diff --git a/main.c b/main.c index 46703a3..c37ac2d 100644 --- a/main.c +++ b/main.c @@ -15,6 +15,9 @@ static double FrameTime = 1.0 / INITIAL_FPS; static double PerformancePeriod; +const int WIDTH = 640; +const int HEIGHT = 480; + static double GetTime( void ) { return PerformancePeriod * SDL_GetPerformanceCounter(); @@ -30,15 +33,13 @@ static void SetTitle ( SDL_Window *window ) int main( int argc, char* argv[] ) { _glWindows_t glW; - const int WIDTH = 640; - const int HEIGHT = 480; int delayThreshold = 2; int r, g, b, alpha_s, depth_s, stencil_s, dbuffer, glVersionMa, glVersionMi, glAccel, glProfile = 0; double sleepTime = 0; double timeCounter = 0; bool loopShouldStop = false; - SDL_SetHint(SDL_HINT_RENDER_VSYNC, 0); + /* SDL_SetHint(SDL_HINT_RENDER_VSYNC, 0); */ if (!SDL_Init(SDL_INIT_VIDEO)) { SDL_LogCritical(SDL_LOG_CATEGORY_ASSERT, "SDL_Init failed: %s", SDL_GetError()); exit(EXIT_FAILURE); @@ -76,9 +77,7 @@ int main( int argc, char* argv[] ) SetTitle(glW.window); - SDL_HideCursor(); - - glewExperimental = GL_TRUE; + glewExperimental = GL_FALSE; GLenum err = glewInit(); if (err != GLEW_OK) { SDL_LogCritical(SDL_LOG_CATEGORY_ASSERT, "glewInit: %s", glewGetErrorString(err)); @@ -103,8 +102,9 @@ int main( int argc, char* argv[] ) SDL_LogVerbose(SDL_LOG_CATEGORY_RENDER, "Red size: %d, Green size: %d, Blue size: %d, Alpha size: %d, Depth size: %d, Stencil size: %d, DoubleBuffer: %d", r, g, b, alpha_s, depth_s, stencil_s, dbuffer); - SDL_GL_SetSwapInterval(0); + SDL_GL_SetSwapInterval(1); startShaderProg(); + _matrix(WIDTH, HEIGHT); while (!loopShouldStop) { SDL_Event e; @@ -135,7 +135,7 @@ int main( int argc, char* argv[] ) _GLBuffer(); if (!SDL_GL_SwapWindow(glW.window)) { - SDL_LogCritical(SDL_LOG_CATEGORY_ASSERT, "SDL_GL_SwapWwindow: %s", SDL_GetError()); + SDL_LogCritical(SDL_LOG_CATEGORY_ASSERT, "SDL_GL_SwapWindow: %s", SDL_GetError()); exit(EXIT_FAILURE); } diff --git a/opengl.c b/opengl.c index 0285c39..1b2e2dd 100644 --- a/opengl.c +++ b/opengl.c @@ -33,6 +33,27 @@ void resizeWindow ( int width, int height ) glViewport(0, 0, (GLsizei)width, (GLsizei)height); } +void _matrix ( 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); +} + GLuint createShader ( const char *shaderFile, GLenum shaderType ) { const char *strShaderType; diff --git a/opengl.h b/opengl.h index 4409338..a100ac6 100644 --- a/opengl.h +++ b/opengl.h @@ -17,6 +17,7 @@ typedef struct { GLuint createShader ( const char *shaderFile, GLenum shaderType ); void createProgram ( GLuint *shaders, int len ); void resizeWindow ( int width, int height ); +void _matrix ( int width, int height ); void createBuffer ( void ); void startShaderProg ( void ); void _GLBuffer( void );