user3161752
user3161752

Reputation: 45

OpenGL white blank screen and not responding

I am using SDL2.00 with OpenGL to create a program. The program isn't supposed to do anything at the moment it's just a test bed. However I ran into a problem. When I create a window using SDL_CreateWindow, the window goes into a busy state and stops responding. The program flow isn't really affected by this however the window itself just won't work. All it does is show a white blank window and accept no input, can't resize can't move and can't quit. I will attach the code but I doubt it is code related since I already made a few programs using SDL and they seem to work just fine.

Using VS2013 SDL2.00 OpenGL

=========main========

#include "stdafx.h"


void init()
{
    glClearColor(0.0, 0.0, 0.0, 1.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45, 640.0 / 480.0, 1.0, 500.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

}

void display()
{
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_TRIANGLES);
glVertex3f(0.0, 2.0, -5.0);
glVertex3f(-2.0, -2.0, -5.0);
glVertex3f(2.0, -2.0, -5.0);
glEnd();

}


int main(int argc, char* argv[]){


SDL_Init(SDL_INIT_VIDEO); 
SDL_Window * window;
window = SDL_CreateWindow("OpenGLTest", 300, 300, 640, 480, SDL_WINDOW_SHOWN |       SDL_WINDOW_OPENGL);
init();


while (true){
    display();
    SDL_GL_SwapWindow(window);
}




return 0;

}

=========stdafx======

#pragma once

#include <iostream>
#include <SDL.h>
#include <Windows.h>
#include <gl/GL.h>
#include <gl/GLU.h>

#define PI 3.14159265

using namespace std;

Upvotes: 1

Views: 3168

Answers (1)

vallentin
vallentin

Reputation: 26157

You forgot to process all the events, so the SDL window is just waiting and waiting and waiting, thereby "not responding" - Simply adding that should fix the problem!

while (true) {
    SDL_PumpEvents();

    display();
    SDL_GL_SwapWindow(window);
}

You could also pull all the events manually with a loop calling SDL_PollEvent(SDL_Event *event)

SDL_Event event;

while (SDL_PollEvent(&event)) {
    // Process the event...
}

Wiki

Upvotes: 3

Related Questions