From 5460918bcc1c2e6efb6e71f36aa9571539297297 Mon Sep 17 00:00:00 2001 From: CRy386i Date: Fri, 21 Feb 2025 18:09:12 +0200 Subject: [PATCH] Fixup not worked shader --- Makefile | 4 ++-- main.c | 31 ------------------------------- math.c | 6 ++++++ math.h | 6 ++++++ opengl.c | 24 ++++++++++++++++++++++++ opengl.h | 1 + 6 files changed, 39 insertions(+), 33 deletions(-) create mode 100644 math.c create mode 100644 math.h diff --git a/Makefile b/Makefile index 858ae12..0871561 100644 --- a/Makefile +++ b/Makefile @@ -2,8 +2,8 @@ CC=gcc CFLAGS=-O1 -DDEBUG -g -ggdb -std=c23 LIBS=`pkg-config sdl3 --cflags --libs` -lGL -lGLEW -lm -HEADER = opengl.h readfile.h -OBJ = main.o opengl.o readfile.o +HEADER = readfile.h math.h opengl.h +OBJ = main.o readfile.o math.o opengl.o all: mobiground diff --git a/main.c b/main.c index d1abf51..46703a3 100644 --- a/main.c +++ b/main.c @@ -27,37 +27,6 @@ static void SetTitle ( SDL_Window *window ) SDL_SetWindowTitle(window, title); } -float toRad ( float deg ) -{ - /* 180 deg = pi */ - /* "deg" deg = x */ - return deg * 3.141593f / 180.0f; -} - -void resizeWindow ( int width, int height ) -{ - shaderProgram_t sp; - float n = 1.0f; // near - float f = 3.0f; // far - float fov = toRad(90); // 90 or 65 for console - float aspect = width / (float) height; - float t = n * tanf (fov / 2.0f); - float r = t * aspect; - - float projMatr[] = { - n/r, 0, 0, 0, - 0, n/t, 0, 0, - 0, 0, (f+n)/(n-f), -1, - 0, 0, 2.0f*n*f/(n-f), 0 - }; // it's not rows, it's columns, 'GL_FALSE' - SDL_LogVerbose(SDL_LOG_CATEGORY_RENDER, "n=%.1f f=%.1f fov=%.2f aspect=%.2f t=%.2f r=%.2f\n", n, f, fov, aspect, t, r); - glUseProgram(sp.program); - glUniformMatrix4fv(sp.projMatrLoc, 1, GL_FALSE, projMatr); - glUseProgram(0); - glViewport(0, 0, (GLsizei)width, (GLsizei)height); -} - - int main( int argc, char* argv[] ) { _glWindows_t glW; diff --git a/math.c b/math.c new file mode 100644 index 0000000..bbc7a5c --- /dev/null +++ b/math.c @@ -0,0 +1,6 @@ +float toRad ( float deg ) +{ + /* 180 deg = pi */ + /* "deg" deg = x */ + return deg * 3.141593f / 180.0f; +} diff --git a/math.h b/math.h new file mode 100644 index 0000000..a80cf3d --- /dev/null +++ b/math.h @@ -0,0 +1,6 @@ +#ifndef MATH_H +#define MATH_H + +float toRad ( float deg ); + +#endif // MATH_H diff --git a/opengl.c b/opengl.c index d49deb5..bce0a4a 100644 --- a/opengl.c +++ b/opengl.c @@ -1,4 +1,5 @@ #include +#include #include #include @@ -6,9 +7,32 @@ #include "opengl.h" #include "readfile.h" +#include "math.h" shaderProgram_t sp; +void resizeWindow ( int width, int height ) +{ + float n = 1.0f; // near + float f = 3.0f; // far + float fov = toRad(90); // 90 or 65 for console + float aspect = width / (float) height; + float t = n * tanf (fov / 2.0f); + float r = t * aspect; + + float projMatr[] = { + n/r, 0, 0, 0, + 0, n/t, 0, 0, + 0, 0, (f+n)/(n-f), -1, + 0, 0, 2.0f*n*f/(n-f), 0 + }; // it's not rows, it's columns, 'GL_FALSE' + SDL_LogVerbose(SDL_LOG_CATEGORY_RENDER, "n=%.1f f=%.1f fov=%.2f aspect=%.2f t=%.2f r=%.2f\n", n, f, fov, aspect, t, r); + glUseProgram(sp.program); + glUniformMatrix4fv(sp.projMatrLoc, 1, GL_FALSE, projMatr); + glUseProgram(0); + glViewport(0, 0, (GLsizei)width, (GLsizei)height); +} + GLuint createShader ( const char *shaderFile, GLenum shaderType ) { const char *strShaderType; diff --git a/opengl.h b/opengl.h index b4ead28..8d0285d 100644 --- a/opengl.h +++ b/opengl.h @@ -15,6 +15,7 @@ typedef struct { GLuint createShader ( const char *shaderFile, GLenum shaderType ); void createProgram ( GLuint *shaders, int len ); +void resizeWindow ( int width, int height ); void createBuffer ( void ); void startShaderProg ( void ); void _GLBuffer( void );