good baseline working
This commit is contained in:
parent
69a0733ebe
commit
f63289903b
2 changed files with 108 additions and 5 deletions
111
main.c
111
main.c
|
|
@ -2,6 +2,88 @@
|
|||
#include <GL/gl.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() {
|
||||
printf("Good Morning 🍵\n");
|
||||
SDL_Init(SDL_INIT_VIDEO);
|
||||
|
|
@ -24,13 +106,34 @@ int main() {
|
|||
|
||||
SDL_Event e;
|
||||
int running = 1;
|
||||
while (SDL_PollEvent(&e)) {
|
||||
printf("INSgkldjsj\n");
|
||||
if (e.type == SDL_EVENT_QUIT) running = false;
|
||||
float angle = 0.0;
|
||||
while (running) {
|
||||
while (SDL_PollEvent(&e)) {
|
||||
if (e.type == SDL_EVENT_QUIT) running = false;
|
||||
}
|
||||
checkGlError();
|
||||
|
||||
// Rendorrrr
|
||||
glViewport(0, 0, 800, 600);
|
||||
glClearColor(0.1f, 0.1f, 0.1f, 1.0f); // Dark gray background
|
||||
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