OpenGL white blank screen and not responding

一曲冷凌霜 提交于 2019-12-25 09:34:54

问题


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;

回答1:


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

  • SDL_PumpEvents() - http://wiki.libsdl.org/SDL_PumpEvents
  • SDL_PollEvent() - http://wiki.libsdl.org/SDL_PollEvent


来源:https://stackoverflow.com/questions/20929623/opengl-white-blank-screen-and-not-responding

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!