C-没有GLWF/GLUT的openGL简单示例



我正在尝试编写一个基本的opengl循环(没有glwf和glut;只有glew(,除了清除窗口外,什么也无能为力。但是,窗口一直是白色的,窗户的颜色未清除为红色。

您能找到错误为什么代码不起作用吗?关于我的代码还有其他建议吗?什么可以做得更好?

/*Window is created using CreateWindowExA()*/ 
/* glewInit() etc  */
    RenderingContext = wglCreateContextAttribsARB(DeviceContext, 0, version_attribs);
    if (!wglMakeCurrent(DeviceContext, RenderingContext))
    {
        OutputDebugStringA("Errorn");
        exit(-1);
    }   
    bool Running = true;
    while (Running){
            glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
            // Simply clear the window with red
            static const GLfloat red[] = { 1.0f, 0.0f, 0.0f, 1.0f };
            glClearBufferfv(GL_COLOR, 0, red);
            // here some other code
    }

将在当前上下文上执行任何GL-Command。

您使用wglMakeCurrent(NULL, NULL);,意思是:"排除此线程的所有GL命令"

而是使用wglMakeCurrent(this_window_device, the_context_I_want_to_use);

编辑:

另外,渲染是对后帧缓冲区的(我认为您正在使用双缓冲区PixelforMat(。要将其显示到窗口中(前帧缓冲区(,您需要调用wglSwapBuffers

编辑2:

我推荐您阅读整个Wiki有关使环境变化的信息。
它显示了窗口和上下文创建的示例。

最新更新