Results 1 to 4 of 4

Thread: just get a black screen

  1. #1
    Junior Member Newbie
    Join Date
    May 2011
    Posts
    2

    just get a black screen

    Hi,
    I try now for hours to understand why my screen is still black. I use qt to draw a simple quad. At first I tried a polygon in 2d. That worked. Here is the code

    void GLtest::initializeGL()
    {
    glEnable(GL_DEPTH_TEST);
    glEnable(GL_CULL_FACE);
    glShadeModel(GL_SMOOTH);
    glEnable(GL_LIGHTING);
    glEnable(GL_LIGHT0);
    glEnable(GL_MULTISAMPLE);
    static GLfloat lightPosition[4] = { 0.5, 5.0, 7.0, 1.0 };
    glLightfv(GL_LIGHT0, GL_POSITION, lightPosition);
    }
    //! [6]

    //! [7]
    void GLtest:aintGL()
    {
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    GLenum errorcode;
    errorcode = glGetError();

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glColor3f(1,0,0);
    errorcode = glGetError();
    glBegin(GL_QUADS);
    glVertex3f(400,400,-;
    glVertex3f(400,-400,;
    glVertex3f(-400,-400,-;
    glVertex3f(-400,400,;
    glEnd();
    errorcode = glGetError();

    }
    //! [7]

    //! [8]
    void GLtest::resizeGL(int width, int height)
    {
    int side = qMin(width, height);
    glViewport((width - side) / 2, (height - side) / 2, side, side);

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    #ifdef QT_OPENGL_ES_1
    glOrthof(-0.5, +0.5, -0.5, +0.5, 4.0, 150.0);
    #else
    glOrtho(-0.5, +0.5, -0.5, +0.5, 4.0, 150.0);
    #endif
    glMatrixMode(GL_MODELVIEW);

    }

    It is a Problem I get often playing with opengl.Is there a short shecklist, what to do if the screen keeps beeing black? What is the minimal code to get this quad drawn in my window?

    Thanks for help

  2. #2
    Senior Member Regular Contributor
    Join Date
    Aug 2009
    Location
    Poland
    Posts
    111

    Re: just get a black screen

    I don't use Qt, but You should probably call some function to swap buffers in your paintGL, or at least glFlush if you are using single buffered context

  3. #3
    Junior Member Newbie
    Join Date
    May 2011
    Posts
    2

    Re: just get a black screen

    Thanks for fast answer. However I think, this is done by qt.
    I tried some other code and got it working with this:

    void GLtest::initializeGL()
    {
    glClearColor (0.0, 0.0, 0.0, 0.0);
    glEnable(GL_DEPTH_TEST);
    glShadeModel (GL_SMOOTH);
    }
    //! [6]

    //! [7]
    void GLtest:aintGL()
    {
    glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glLoadIdentity ();

    // We will draw things a little deeper into the screen
    glTranslatef(0,0,-20);

    glColor3f(1,0,0);
    /* glBegin(GL_TRIANGLES);

    glVertex3f(0,2,0);
    glVertex3f(3,0,0);
    glVertex3f(-3,0,0);

    glEnd();*/
    glBegin(GL_QUADS);
    glVertex3f(0,0,0);
    glVertex3f(1,0,0);
    glVertex3f(1,1,0);
    glVertex3f(0,1,0);
    glEnd();


    }
    //! [7]

    //! [8]
    void GLtest::resizeGL(int width, int height)
    {
    glViewport (0, 0, (GLsizei) width, (GLsizei) height);
    glMatrixMode (GL_PROJECTION);
    glLoadIdentity ();
    gluPerspective(60.0, (GLfloat) width/(GLfloat) height, 1.0, 21.0);
    glMatrixMode (GL_MODELVIEW);

    }

    So I will compare to find my mistake.

  4. #4
    Senior Member Regular Contributor
    Join Date
    Dec 2007
    Posts
    258

    Re: just get a black screen

    you are drawing outside the view frustum, so nothing will be visible

    try glOrtho with near and far at -100 and 100
    you'll see something then

Similar Threads

  1. Black screen
    By Tim88348 in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 09-20-2011, 10:15 AM
  2. The black screen
    By RonHiler in forum OpenGL: Basic Coding
    Replies: 14
    Last Post: 01-09-2011, 05:26 PM
  3. Black screen using Print Screen
    By specifikys in forum OpenGL: Windows
    Replies: 1
    Last Post: 11-01-2010, 01:32 PM
  4. Replies: 0
    Last Post: 07-29-2009, 12:54 PM
  5. Replies: 0
    Last Post: 09-30-2003, 08:58 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean