CreateDC()导致glutInit()失败? [英] CreateDC() causes glutInit() to fail?

查看:116
本文介绍了CreateDC()导致glutInit()失败?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了一个代码,该代码创建一个窗口并在其中绘制形状:

I wrote a code that creates a window and draws a shape into it:

#include<glew.h>
#include<iostream>
#include<GL\freeglut.h>

#include<Windows.h>
#include<stdlib.h>
#include<math.h>

#pragma once

void Render_All()
{
    glClear(GL_COLOR_BUFFER_BIT);
    glBegin(GL_POLYGON);
    glColor3f(1, 0, 0); glVertex2f(0.5, 0.5);
    glColor3f(1, 0, 0); glVertex2f(0.5, -0.5);
    glColor3f(1, 0, 0); glVertex2f(-0.5, -0.5);
    glColor3f(1, 0, 0); glVertex2f(-0.5, 0.5);
    glEnd();
    glFlush();
}

int main(int argc, char** argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
    glutInitWindowSize(300, 300);
    glutCreateWindow("Square");
    //glutFullScreen();
    glutDisplayFunc(Render_All);

    GLenum Error = glewInit();

    if(GLEW_OK != Error)
    {
        fprintf(stderr, "GLEW Error");
        return EXIT_FAILURE;
    }

    glutMainLoop();
    return 0;
}

代码可以正常编译.输出按预期方式输出.唯一的问题是,我在控制台窗口中收到此消息:

The code compiles fine. The output comes out as expected. The only problem is, I get this message in the console window:

fghInitialize: CreateDC failed, Screen size info may be incorrect. This is quite likely caused by a bad '-display' parameter.

在Internet上嗅探,我发现这是从 freeglut_init.c 文件中调用的.除此之外,我找不到任何解决方法.我该如何解决?

Sniffing around the internet, I found out this is called from the freeglut_init.c file. Apart from that, I couldn't find any way of solving it. How do I solve this?

P.S.:这是在Visual Studio 10中完成的.我在相同条件下在另一台PC(笔记本电脑)中执行了相同的程序,但未出现此消息.因此,这很可能是硬件问题.尽管如此,它仍然没有解释如何解决它.

P.S. : This was done in Visual Studio 10. I did the same program in another PC (laptop) under the same conditions, and this message did not occur. So, it is likely a hardware problem. Still, it does not explain how to solve it, though.

推荐答案

这是由于将-display参数传递给程序,或者更有可能定义了DISPLAY环境变量而引起的.在Windows下,FreeGLUT将使用DISPLAY变量调用

This is caused either because you are passing a -display argument to your program or more likely you have a DISPLAY environment variable defined. Under windows, FreeGLUT will use the DISPLAY variable for the call to CreateDC(), which expects NULL, "DISPLAY" or a valid display device name.

这篇关于CreateDC()导致glutInit()失败?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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