don't stretch viewport when resizing

This commit is contained in:
headshot2017
2023-01-24 00:44:04 -04:00
parent 405de6a367
commit c1031ad6c6
3 changed files with 10 additions and 13 deletions
+7 -7
View File
@@ -5,8 +5,8 @@
static SDL_Window *s_sdlWindow; static SDL_Window *s_sdlWindow;
static SDL_GLContext s_sdlGlContext; static SDL_GLContext s_sdlGlContext;
static SDL_GameController *s_controller; static SDL_GameController *s_controller;
static int s_windowWidth; int WINDOW_WIDTH;
static int s_windowHeight; int WINDOW_HEIGHT;
void context_init( const char *title, int width, int height, int major, int minor ) void context_init( const char *title, int width, int height, int major, int minor )
{ {
@@ -18,8 +18,8 @@ void context_init( const char *title, int width, int height, int major, int mino
SDL_GL_SetAttribute( SDL_GL_CONTEXT_MINOR_VERSION, minor ); SDL_GL_SetAttribute( SDL_GL_CONTEXT_MINOR_VERSION, minor );
SDL_GL_SetAttribute( SDL_GL_CONTEXT_PROFILE_MASK, profile ); SDL_GL_SetAttribute( SDL_GL_CONTEXT_PROFILE_MASK, profile );
s_windowWidth = width; WINDOW_WIDTH = width;
s_windowHeight = height; WINDOW_HEIGHT = height;
s_sdlWindow = SDL_CreateWindow( s_sdlWindow = SDL_CreateWindow(
title, title,
@@ -87,9 +87,9 @@ bool context_flip_frame_poll_events( void )
case SDL_WINDOWEVENT: case SDL_WINDOWEVENT:
if( event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED ) if( event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED )
{ {
s_windowWidth = event.window.data1; WINDOW_WIDTH = event.window.data1;
s_windowHeight = event.window.data2; WINDOW_HEIGHT = event.window.data2;
glViewport( 0, 0, s_windowWidth, s_windowHeight ); glViewport( 0, 0, WINDOW_WIDTH, WINDOW_HEIGHT );
} }
break; break;
} }
-1
View File
@@ -6,7 +6,6 @@
#include "../renderer.h" #include "../renderer.h"
#include "../context.h" #include "../context.h"
#include "../level.h" #include "../level.h"
#include <GL/glu.h>
static void load_collision_mesh( CollisionMesh *mesh ) static void load_collision_mesh( CollisionMesh *mesh )
{ {
+3 -5
View File
@@ -21,9 +21,6 @@ extern "C" {
#include "audio.h" #include "audio.h"
int WINDOW_WIDTH = 1280;
int WINDOW_HEIGHT = 800;
uint8_t *utils_read_file_alloc( const char *path, size_t *fileLength ) uint8_t *utils_read_file_alloc( const char *path, size_t *fileLength )
{ {
FILE *f = fopen( path, "rb" ); FILE *f = fopen( path, "rb" );
@@ -88,6 +85,7 @@ int main( void )
struct Renderer *renderer; struct Renderer *renderer;
int major, minor, selection = 0; int major, minor, selection = 0;
int w = 1280, h = 800;
printf("Select OpenGL version\n1. OpenGL 3.3 Core\n2. OpenGL 2.0\n> "); printf("Select OpenGL version\n1. OpenGL 3.3 Core\n2. OpenGL 2.0\n> ");
scanf("%d", &selection); scanf("%d", &selection);
if (selection == 2) if (selection == 2)
@@ -108,12 +106,12 @@ int main( void )
if (selection == 2) if (selection == 2)
{ {
printf("Launching in 800x600\n"); printf("Launching in 800x600\n");
WINDOW_WIDTH = 800; WINDOW_HEIGHT = 600; w = 800; h = 600;
} }
else else
printf("Launching in 1280x600\n"); printf("Launching in 1280x600\n");
context_init( "libsm64", WINDOW_WIDTH, WINDOW_HEIGHT, major, minor ); context_init( "libsm64", w, h, major, minor );
renderer->init( &renderState, texture ); renderer->init( &renderState, texture );
struct SM64MarioInputs marioInputs; struct SM64MarioInputs marioInputs;