2

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.

genpfault
  • 51,148
  • 11
  • 85
  • 139
  • I'd consider not using a single-buffered pixel format. It's not going to work unless you're in fullscreen mode anyway on anything newer than Windows Vista. – Andon M. Coleman Sep 26 '14 at 23:00
  • Yes, use double buffered. (`GLUT_DOUBLE` instead of `GLUT_SINGLE` in `glutInitDisplayMode`) – St0fF Sep 26 '14 at 23:09
  • 1
    I did use double buffering. I changed `GLUT_SINGLE` to `GLUT_DOUBLE` and used `glutSwapBuffers()` in the `Render_All()` method. I am still getting the message. Any other reason why it could be? Please help. – Bhargav Jannabhatla Sep 27 '14 at 09:37

1 Answers1

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.

genpfault
  • 51,148
  • 11
  • 85
  • 139
Jason Brown
  • 174
  • 9
  • I got the same error but from a python environment. How am I supposed to change the display variable? – SuperCiocia Dec 17 '20 at 20:24
  • 1
    Python can alter environment variables. See this question. https://stackoverflow.com/questions/5971312/how-to-set-environment-variables-in-python – Jason Brown Dec 21 '20 at 14:05