This commit is contained in:
Rakarake 2025-12-08 16:24:10 +01:00
parent f63289903b
commit 56070f31e4
2 changed files with 25 additions and 19 deletions

3
fragment.glsl Normal file
View file

@ -0,0 +1,3 @@
void main() {
gl_FragColor = vec4(1.0,0.0,1.0,1.0);
}

41
main.c
View file

@ -1,5 +1,8 @@
#define GL_GLEXT_PROTOTYPES
#include <stdio.h>
#include <GL/gl.h>
#include <GL/glext.h>
#include <SDL3/SDL.h>
float tanf(float in) {
@ -32,13 +35,6 @@ void perspective(float fovY, float aspect, float zNear, float zFar, float* matri
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);
@ -84,6 +80,15 @@ void checkGlError() {
}
}
const char *vertex_shader_source = "";
GLuint create_shader() {
GLuint vshader = glCreateShader(GL_VERTEX_SHADER);
glShaderSource(vshader, 1, &vertex_shader_source, NULL); // vertex_shader_source is a GLchar* containing glsl shader source code
glCompileShader(vshader);
return vshader;
}
int main() {
printf("Good Morning 🍵\n");
SDL_Init(SDL_INIT_VIDEO);
@ -117,23 +122,21 @@ int main() {
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);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
float proj[16];
perspective(60.0f, 800.0f / 600.0f, 1.0f, 100.0f, proj);
glLoadMatrixf(proj);
//drawCube();
// Front
glBegin(GL_QUADS);
glColor3f(1, 0, 0);
glVertex2f(-1, -1);
glVertex2f(-1, 1);
glVertex2f( 1, 1);
glVertex2f( 1, -1);
glEnd();
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();
}