问题
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.
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. : 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.
回答1:
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.
来源:https://stackoverflow.com/questions/26069038/createdc-causes-glutinit-to-fail