good baseline working
This commit is contained in:
parent
69a0733ebe
commit
f63289903b
2 changed files with 108 additions and 5 deletions
2
Makefile
2
Makefile
|
|
@ -6,4 +6,4 @@ all:
|
||||||
$(CC) $(CFLAGS) $(LDFLAGS) -o glonkers main.c
|
$(CC) $(CFLAGS) $(LDFLAGS) -o glonkers main.c
|
||||||
|
|
||||||
run: all
|
run: all
|
||||||
./glonkers
|
SDL_VIDEODRIVER="wayland,x11" ./glonkers
|
||||||
|
|
|
||||||
107
main.c
107
main.c
|
|
@ -2,6 +2,88 @@
|
||||||
#include <GL/gl.h>
|
#include <GL/gl.h>
|
||||||
#include <SDL3/SDL.h>
|
#include <SDL3/SDL.h>
|
||||||
|
|
||||||
|
float tanf(float in) {
|
||||||
|
return in;
|
||||||
|
}
|
||||||
|
|
||||||
|
void perspective(float fovY, float aspect, float zNear, float zFar, float* matrix) {
|
||||||
|
float f = 1.0f / tanf(fovY * 0.5f * (3.14159265358979323846f / 180.0f));
|
||||||
|
matrix[0] = f / aspect;
|
||||||
|
matrix[1] = 0;
|
||||||
|
matrix[2] = 0;
|
||||||
|
matrix[3] = 0;
|
||||||
|
|
||||||
|
matrix[4] = 0;
|
||||||
|
matrix[5] = f;
|
||||||
|
matrix[6] = 0;
|
||||||
|
matrix[7] = 0;
|
||||||
|
|
||||||
|
matrix[8] = 0;
|
||||||
|
matrix[9] = 0;
|
||||||
|
matrix[10] = (zFar + zNear) / (zNear - zFar);
|
||||||
|
matrix[11] = -1;
|
||||||
|
|
||||||
|
matrix[12] = 0;
|
||||||
|
matrix[13] = 0;
|
||||||
|
matrix[14] = (2 * zFar * zNear) / (zNear - zFar);
|
||||||
|
matrix[15] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void drawCube() {
|
||||||
|
glBegin(GL_QUADS);
|
||||||
|
|
||||||
|
// Front
|
||||||
|
glColor3f(1, 0, 0);
|
||||||
|
glVertex3f(-1, -1, 1);
|
||||||
|
glVertex3f( 1, -1, 1);
|
||||||
|
glVertex3f( 1, 1, 1);
|
||||||
|
glVertex3f(-1, 1, 1);
|
||||||
|
|
||||||
|
// Back
|
||||||
|
glColor3f(0, 1, 0);
|
||||||
|
glVertex3f(-1, -1, -1);
|
||||||
|
glVertex3f(-1, 1, -1);
|
||||||
|
glVertex3f( 1, 1, -1);
|
||||||
|
glVertex3f( 1, -1, -1);
|
||||||
|
|
||||||
|
// Top
|
||||||
|
glColor3f(0, 0, 1);
|
||||||
|
glVertex3f(-1, 1, -1);
|
||||||
|
glVertex3f(-1, 1, 1);
|
||||||
|
glVertex3f( 1, 1, 1);
|
||||||
|
glVertex3f( 1, 1, -1);
|
||||||
|
|
||||||
|
// Bottom
|
||||||
|
glColor3f(1, 1, 0);
|
||||||
|
glVertex3f(-1, -1, -1);
|
||||||
|
glVertex3f( 1, -1, -1);
|
||||||
|
glVertex3f( 1, -1, 1);
|
||||||
|
glVertex3f(-1, -1, 1);
|
||||||
|
|
||||||
|
// Right
|
||||||
|
glColor3f(1, 0, 1);
|
||||||
|
glVertex3f(1, -1, -1);
|
||||||
|
glVertex3f(1, 1, -1);
|
||||||
|
glVertex3f(1, 1, 1);
|
||||||
|
glVertex3f(1, -1, 1);
|
||||||
|
|
||||||
|
// Left
|
||||||
|
glColor3f(0, 1, 1);
|
||||||
|
glVertex3f(-1, -1, -1);
|
||||||
|
glVertex3f(-1, -1, 1);
|
||||||
|
glVertex3f(-1, 1, 1);
|
||||||
|
glVertex3f(-1, 1, -1);
|
||||||
|
|
||||||
|
glEnd();
|
||||||
|
}
|
||||||
|
|
||||||
|
void checkGlError() {
|
||||||
|
const char *err = SDL_GetError();
|
||||||
|
if (*err != 0) {
|
||||||
|
printf("OpenGL error: %s", err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
printf("Good Morning 🍵\n");
|
printf("Good Morning 🍵\n");
|
||||||
SDL_Init(SDL_INIT_VIDEO);
|
SDL_Init(SDL_INIT_VIDEO);
|
||||||
|
|
@ -24,13 +106,34 @@ int main() {
|
||||||
|
|
||||||
SDL_Event e;
|
SDL_Event e;
|
||||||
int running = 1;
|
int running = 1;
|
||||||
|
float angle = 0.0;
|
||||||
|
while (running) {
|
||||||
while (SDL_PollEvent(&e)) {
|
while (SDL_PollEvent(&e)) {
|
||||||
printf("INSgkldjsj\n");
|
|
||||||
if (e.type == SDL_EVENT_QUIT) running = false;
|
if (e.type == SDL_EVENT_QUIT) running = false;
|
||||||
|
}
|
||||||
|
checkGlError();
|
||||||
|
|
||||||
// Rendorrrr
|
// Rendorrrr
|
||||||
glViewport(0, 0, 800, 600);
|
glViewport(0, 0, 800, 600);
|
||||||
glClearColor(0.1f, 0.1f, 0.1f, 1.0f); // Dark gray background
|
glClearColor(0.1f, 0.1f, 0.1f, 1.0f); // Dark gray background
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
//SDL_GL_SwapWindow(window);
|
|
||||||
|
glMatrixMode(GL_PROJECTION);
|
||||||
|
glLoadIdentity();
|
||||||
|
|
||||||
|
float proj[16];
|
||||||
|
perspective(60.0f, 800.0f / 600.0f, 1.0f, 100.0f, proj);
|
||||||
|
glLoadMatrixf(proj);
|
||||||
|
|
||||||
|
glMatrixMode(GL_MODELVIEW);
|
||||||
|
glLoadIdentity();
|
||||||
|
glTranslatef(0.0f, 0.0f, -5.0f);
|
||||||
|
glRotatef(angle, 1.0f, 1.0f, 0.0f);
|
||||||
|
|
||||||
|
drawCube();
|
||||||
|
SDL_GL_SwapWindow(window);
|
||||||
|
angle += 0.5;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
checkGlError();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue