Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 4 of 4

Thread: OpenGL SuperBible 5E, Triangle program background "scattered"

  1. #1
    Junior Member Newbie
    Join Date
    Mar 2014
    Posts
    4

    Question OpenGL SuperBible 5E, Triangle program background "scattered" [SOLVED]

    Sorry to have to dig up such an old book, and I hope this can be considered a beginner question. But I'm using the OpenGL SB 5E because my mac only supports OpenGL 3.3.

    I'm currently working on the first sample program, Triangle.cpp. I have included all the necessary files, set up the correct path, and built and ran the program.

    I am having an issue with the display of the program. It is supposed to display a red triangle on a blue background. I am able to see the red triangle, but the blue background displays other scattered images of my screen.

    screenshot: imgur.com / mivJWpS


    In all honesty I have no idea what could be causing this issue. I do however have 4 warnings that appear from the GLTools.h:

    - Lexical or Preprocessor Issue: 'glGenVertexArrays' macro redefined
    - Lexical or Preprocessor Issue: 'glDeleteVertexArrays' macro redefined
    - Lexical or Preprocessor Issue: 'glBindVertexArray' macro redefined
    - Lexical or Preprocessor Issue: 'glGenerateMipmap' macro redefined

    Could these be a possible cause to the issue?

    Macbook Pro 3,1 - 2.2GHz, 4GB Ram
    Last edited by kyle.brechin; 03-05-2014 at 02:18 AM. Reason: Problem solved

  2. #2
    Senior Member OpenGL Pro
    Join Date
    Jan 2012
    Location
    Australia
    Posts
    1,117
    Warnings like this probably aren't causing you problem but you should resolve why you are getting them. How is the blue background being set?

  3. #3
    Junior Member Newbie
    Join Date
    Mar 2014
    Posts
    4
    The blue background is being drawn in SetupRC with 'glClearColor'.

    I've included the code so you know exactly what is going on.

    Code :
     
    #include <GLTools.h>
    #include <GLShaderManager.h>
     
    #ifdef __APPLE__
    #include <GLUT/glut.h>
    #else
    #DEFINE FREEGLUT_STATIC
    #include <GL/glut.h>
    #endif
     
     
    GLBatch triangleBatch;
    GLShaderManager shaderManager;
     
    void ChangeSize(int w, int h)
    {
        glViewport(0, 0, w, h);
    }
     
    void SetupRC() {
        // blue background
        glClearColor(0.0f, 0.0f, 1.0f, 1.0f);
     
        shaderManager.InitializeStockShaders();
     
        // load up triangle
        GLfloat vVerts[] = { -0.5f, 0.0f, 0.0f,
                    0.5f, 0.0f, 0.0f,
                    0.0f, 0.5f, 0.0f };
     
        triangleBatch.Begin(GL_TRIANGLES, 3);
        triangleBatch.CopyVertexData3f(vVerts);
        triangleBatch.End();
    }
     
    void RenderScene(void)
    {
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER | GL_STENCIL_BUFFER_BIT);
     
        GLfloat vRed[] = { 1.0f, 0.0f, 0.0f, 1.0f };
        shaderManager.UseStockShader(GLT_SHADER_IDENTITY, vRed);
        triangleBatch.Draw();
     
        glutSwapBuffers();
    }
     
    int main(int argc, char* argv[])
    {
        gltSetWorkingDirectory(argv[0]);
     
        glutInit(&argc, argv);
        glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH | GLUT_STENCIL);
        glutInitWindowSize(800, 600);
        glutCreateWindow("Triangle");
        glutReshapeFunc(ChangeSize);
        glutDisplayFunc(RenderScene);
     
        GLenum err = glewInit();
        if(GLEW_OK != err)
        {
            fprintf(stderr, "GLEW Error: %s\n", glewGetErrorString(err));
            return 1;
        }
     
        SetupRC();
     
        glutMainLoop();
        return 0;
     
     
    }

  4. #4
    Junior Member Newbie
    Join Date
    Mar 2014
    Posts
    4
    I solved the problem after reading the code about 10 times through.

    The original RenderScene function, note 'glClear'
    Code :
    void RenderScene(void)
    {
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER | GL_STENCIL_BUFFER_BIT);
     
        GLfloat vRed[] = { 1.0f, 0.0f, 0.0f, 1.0f };
        shaderManager.UseStockShader(GLT_SHADER_IDENTITY, vRed);
        triangleBatch.Draw();
     
        glutSwapBuffers();
    }

    The fixed and working just fine RenderScene function


    Code :
    void RenderScene(void)
    {
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
                    //                            ^ That's the error!
     
        GLfloat vRed[] = { 1.0f, 0.0f, 0.0f, 1.0f };
        shaderManager.UseStockShader(GLT_SHADER_IDENTITY, vRed);
        triangleBatch.Draw();
     
        glutSwapBuffers();
    }

    Solved by simply adding _BIT to GL_DEPTH_BUFFER

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •