OpenGL白色空白屏幕,没有响应 [英] OpenGL white blank screen and not responding
问题描述
我使用SDL2.00与OpenGL来创建程序。该程序目前不应该做任何事情,它只是一个测试床。然而我遇到了一个问题。当我使用SDL_CreateWindow创建一个窗口时,窗口进入忙碌状态并停止响应。程序流没有真正受到这个影响,但是窗口本身不会工作。它所做的就是显示一个白色的空白窗口,并接受没有输入,不能调整大小不能移动,不能退出。我将附加代码,但我怀疑它是代码相关,因为我已经使用SDL的几个程序,他们似乎工作很好。
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.
使用VS2013 SDL2.00 OpenGL
Using VS2013 SDL2.00 OpenGL
========= main ========
=========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 == ====
=========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;
推荐答案
您忘记处理所有事件,因此SDL窗口只是在等待和等待和等待,从而不响应 - 只需添加应该可以解决问题!
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);
}
您也可以使用循环调用 SDL_PollEvent(SDL_Event * event)
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 $ c> - http://wiki.libsdl.org/SDL_PumpEvents
-
SDL_PollEvent()
- http://wiki.libsdl .org / SDL_PollEvent SDL_PumpEvents()
- http://wiki.libsdl.org/SDL_PumpEventsSDL_PollEvent()
- http://wiki.libsdl.org/SDL_PollEvent
Wiki
这篇关于OpenGL白色空白屏幕,没有响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!