OpenGL窗口没有打开 [英] OpenGL window isn't opening

查看:147
本文介绍了OpenGL窗口没有打开的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有来自OpenGLBook(openglbook.com)的代码,它编译但不加载。我完全不知道为什么它不加载。代码如下:

I have code from the OpenGLBook (openglbook.com) which compiles, but does not load. I have absolutely no idea why it's not loading. The code is as follows:

main.cpp

#include "main.h"

/// Methods
/// -----------------------------

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

    glutMainLoop();

    exit(EXIT_SUCCESS);
}

main.h
$ b

main.h

#ifndef main_h
#define main_h

#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <GL/glew.h>
#include <GL/freeglut.h>

#define WINDOW_TITLE_PREFIX "CHAPTER 1"

void Initialize(int, char*[]);
void InitWindow(int, char*[]);
void ResizeFunction(int, int);
void RenderFunction(void);

#endif

functions.cpp / p>

functions.cpp

#include "main.h"

int CurrentWidth = 800,
    CurrentHeight = 600,
    WindowHandle = 0;

void Initialize(int argc, char* argv[])
{
    InitWindow(argc, argv);

    fprintf(
        stdout,
        "INFO: OpenGL Version: %s\n",
        glGetString(GL_VERSION)
        );

    glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
}

void InitWindow(int argc, char* argv[])
{
    glutInit(&argc, argv);

    glutInitContextVersion(4, 2);
    glutInitContextFlags(GLUT_FORWARD_COMPATIBLE);
    glutInitContextProfile(GLUT_CORE_PROFILE);</pre>

    glutSetOption(
        GLUT_ACTION_ON_WINDOW_CLOSE,
        GLUT_ACTION_GLUTMAINLOOP_RETURNS
        );

    glutInitWindowSize(CurrentWidth, CurrentHeight);

    glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);

    WindowHandle = glutCreateWindow(WINDOW_TITLE_PREFIX);

    if(WindowHandle < 1) {
        fprintf(
            stderr,
            "ERROR: Could not create a new rendering window.\n"
            );
        exit(EXIT_FAILURE);
    }

    glutReshapeFunc(ResizeFunction);
    glutDisplayFunc(RenderFunction);

}

void ResizeFunction(int Width, int Height)
{
    CurrentWidth = Width;
    CurrentHeight = Height;
    glViewport(0, 0, CurrentWidth, CurrentHeight);
}

void RenderFunction(void)
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glutSwapBuffers();
    glutPostRedisplay();
}



当我编译并尝试使用Visual Studio 2010运行我的.exe时,发生。
OpenGL窗口甚至不打开。

When I compile and try to run my .exe with Visual Studio 2010, nothing happens at all. The OpenGL window doesn't even open. Visual Studio acts as if it is running something for about 2 seconds, then returns to its normal state.

推荐答案

glutInitContextVersion(4, 2);

您当前的图形驱动程序实际上是否支持OpenGL 4.2?如果没有,那么你的窗口创建将失败。 4.2还是比较新的;请尝试4.1。

Does your current graphics driver actually support OpenGL 4.2? If not, then your window creation will fail. 4.2 is still rather new; try 4.1 instead.

这篇关于OpenGL窗口没有打开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆