Fixup not worked shader

This commit is contained in:
CRy386i 2025-02-21 18:09:12 +02:00
parent f6bb22bb05
commit 5460918bcc
6 changed files with 39 additions and 33 deletions

View file

@ -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

31
main.c
View file

@ -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;

6
math.c Normal file
View file

@ -0,0 +1,6 @@
float toRad ( float deg )
{
/* 180 deg = pi */
/* "deg" deg = x */
return deg * 3.141593f / 180.0f;
}

6
math.h Normal file
View file

@ -0,0 +1,6 @@
#ifndef MATH_H
#define MATH_H
float toRad ( float deg );
#endif // MATH_H

View file

@ -1,4 +1,5 @@
#include <stdlib.h>
#include <math.h>
#include <GL/glew.h>
#include <SDL3/SDL.h>
@ -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;

View file

@ -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 );