Cartier
Cartier

Reputation: 426

SDL_Window Being Resized Unwantedly

I am working on a small program for school. It includes a 3D crime scene (I use OpenGL to display it), some instructions, and a main menu. However, I am faced with quite an unwanted problem.

The problem I have encountered is as follows: when I run the program, it has the desired window size (Screen width * 0.85); however, when the program enters the main loop, it shrinks.

What is strange, is that the aspect ratio seemingly does not change, merely the window size.

Here is my main loop:

 while (!quit) {
        if (mainMenu) {
            SDL_UpdateWindowSurface(mainWindow);
            SDL::keyTesting();

            menuImage->drawImage(mainSurface);

            instructionButton->drawButton(mainSurface);
            crimeButton->drawButton(mainSurface);

            SDL_Delay(10);
        } 
        else if (instructions) {
            SDL_UpdateWindowSurface(mainWindow);
            SDL::keyTesting();

            instructionsImage->drawImage(mainSurface);

            backButton->drawButton(mainSurface);

            SDL_Delay(10);
        }
        else if(modelView) {
            for (int i = 0; i < 100; i++)
                SDL::keyTesting();

            GLfloat currentFrame = glfwGetTime();
            deltaTime = currentFrame - lastFrame;
            lastFrame = currentFrame;

            glClearColor(0.2f, 0.2f, 0.2f, 1.0f);
            glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

            glUseProgram(modelProgram);

            glUniform3f(viewPosLoc, camera.Position.x, camera.Position.y, camera.Position.z);

            glm::mat4 projection = glm::perspective(camera.Zoom, (float)windowWidth/(float)windowHeight, 0.1f, 250.0f);
            glm::mat4 view = camera.GetViewMatrix();
            glUniformMatrix4fv(projLoc, 1, GL_FALSE, glm::value_ptr(projection));
            glUniformMatrix4fv(viewLoc, 1, GL_FALSE, glm::value_ptr(view));

            glm::mat4 modelMat;
            modelMat = glm::translate(modelMat, glm::vec3(0.0f, -1.75f, 0.0f));
            modelMat = glm::scale(modelMat, glm::vec3(1.5f, 1.5f, 1.5f));
            glUniformMatrix4fv(modelLoc, 1, GL_FALSE, glm::value_ptr(modelMat));

            model->Draw(modelProgram);

            SDL_GL_SwapWindow(mainWindow);
        }
    }

Upvotes: 0

Views: 70

Answers (1)

djgL
djgL

Reputation: 34

try to use SDL_WINDOW_SHOWN flag.

Upvotes: 2

Related Questions