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 7 of 7

Thread: Can't draw a pixel , suspecting an OpenGL state variable

  1. #1
    Junior Member Newbie
    Join Date
    Nov 2013
    Posts
    4

    Can't draw a pixel , suspecting an OpenGL state variable

    Hey there everyone , I'm new here , not new to OpenGL tho ,

    So basically , I've been scratching my head over a problem for the last 3 weeks , basically , everything works good , it's all done right , but ... it doesn't draw anything , I basically copied code from my last working app on this one , but it doesn't work

    Not a vertex is drawn , and I'm sure it's not with my code , I suspect GL_GEOMETRY_VERTICES_OUT_EXT , which is set to 0 for my app , I tried another OpenGL app , and it's not set to 0 in most cases , what do you guys think ? Anything related to that variable ?

  2. #2
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Location
    Druidia
    Posts
    3,124
    basically , everything works good , it's all done right , but ... it doesn't draw anything
    What?! It doesn't draw anything but it works good? That doesn't make any sense.

    If it's a short test program, post it here (surrounding it with [code]...[/code] or [highlight=cpp]...[/highlight] tags. If it's not, post the base template for your redraw function().

    Surely at some point you had it drawing "something". Do some basic kick-the-tires tests. Clear the screen to different colors. Draw a red quad with the fixed function pipeline in immediate mode -- something quick and easy.

  3. #3
    Junior Member Newbie
    Join Date
    Nov 2013
    Posts
    4
    Odd ... I tried drawing with the fixed pipeline once , and then , I re-tried drawing with the old code , and it worked , with the same code !
    I swear it didn't work one second ago ...

    Edit : Nvm , I was using the fixed pipeline and it worked just well ... seems like a problem with my code ; I'll post it here

    Code :
    private void draw() {
     
            /* Draw Function                                           //
            // Put everything that is draw every possible tick here !            */
     
                glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
     
                /*------------------------------------------------*/
     
                glBindBuffer(GL_ARRAY_BUFFER, buffer);
                enableVertexAttribs();
     
                // last parameter is obviously the number of vertexes to draw
                glDrawArrays(GL_TRIANGLES, 0, 3);
     
                disableVertexAttribs();
                glBindBuffer(GL_ARRAY_BUFFER, 0);
     
     
                /*------------------------------------------------*/
     
                Display.update();
     
            }

    Code :
    // Vertex Attrib List                                           //
            // Storing all the vertex attributes in a big editable list     //
     
            static LinkedList<Integer> vertexAttribArray = new LinkedList<Integer>();
            static int attribNum; // the non 0-based (Makes for looping correct) number of attributes
            static int stride; // the distance between each elements of the attributes listin bytes
     
            public static void addVertexAttrib(int VectorType) {
                // Basically ; 4 , 3 , 2 , 1
                vertexAttribArray.add(VectorType);
                //Adds the size of the attrib to the stride
                stride += VectorType * 4;
     
                attribNum += 1;
            }
     
            public static void enableVertexAttribs() {
                int offset = 0; // the offset from the beginning in bytes
                for (int i = 0; i < attribNum; i++) {
                    //Size of the current attribute (is it a Vector2f OR 3f OR 4f ?)
                    int size = vertexAttribArray.get(i);
     
                    /* For testing
                    System.out.println(new StringBuilder().append("index : ").append(i).append(" | size : ").append(size).append(" | stride : ").append(stride - size * 4).append(" | offset : ").append(offset));*/
     
                    glEnableVertexAttribArray(i);                   //the distance - the current vertex attribute size ;
                    glVertexAttribPointer(i, size, GL_FLOAT, false, stride - size * 4, offset);
                    offset += size * 4;
     
                }
            }
     
            public static void disableVertexAttribs() {
                for (int i = 0; i < attribNum; i++) {
                    glDisableVertexAttribArray(i);
                }
            }

    Code :
    #version 330
     
       out vec4 outputColor;
     
     
       void main()
       {
          outputColor = vec4(1,1,1,1);
       }

    Code :
    #version 330
     
       layout(location = 0) in vec3 Position;
     
       void main()
       {
          gl_Position = (Position, 1);
       }

    And after installing codexl , here are the calls I'm having (with a breakpoint at glprogram)

    glCreateShader(GL_VERTEX_SHADER)
    glShaderSource(1,1,0x...,0x...)
    glCompileShader(1)
    glGetShaderiv(1,GL_COMPIL
    glCreateShader(GL_FRAGMENT_SHADER)
    glShaderSource(2,1,0x...,0x...)
    glCompileShader(2)
    glGetShaderiv(2,GL_COMPILE_STATUS,0x...)
    glCreateProgram()
    glAttachShader(3,1)
    glAttachShader(3,2)
    glLinkProgram(3)
    glGetProgramiv(3,GL_LINK_STATUS,0x...)
    glValidateProgram()
    glGetProgramiv(3,GL_VALIDATE_STATUS,0x...)
    -> glUseProgram(3)
    glGenBuffers(1,0x...)
    glBindBuffer(GL_ARRAY_BUFFER,1)
    glBufferData(GL_ARRAY_BUFFER,36,0x...,GL_STATIC_DR AW)
    glBindBuffer(GL_ARRAY_BUFFER,0)
    -> glUseProgram(0)
    -> glUseProgram(3)
    -> glUseProgram(0)
    -> glUseProgram(3)
    -> glUseProgram(0)

    But I don't see any glDrawArrays ...

    The vertex buffer is created properly but it seems that the draw code isn't working
    Last edited by Whiteclaws; 11-22-2013 at 04:29 PM.

  4. #4
    Junior Member Newbie
    Join Date
    Nov 2013
    Posts
    4
    COULD ANYONE EXPLAIN THIS NON-SENSE TO ME ?!

    Code :
    //Not Working
    #version 330
     
     layout(location = 0) in vec3 Position;
     
     void main()
     {
        gl_Position = vec4(Position, 1);
     }
     
    //Working
    #version 330
     
    layout(location = 0) in vec3 position;
     
    void main()
    {
        gl_Position = vec4(position,1);
    }

  5. #5
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Location
    Druidia
    Posts
    3,124
    Quote Originally Posted by Whiteclaws View Post
    ...
    -> glUseProgram(3)
    -> glUseProgram(0)
    -> glUseProgram(3)
    -> glUseProgram(0)

    But I don't see any glDrawArrays ...

    The vertex buffer is created properly but it seems that the draw code isn't working
    Did you at least verify that draw() is being called? Put a print in there or something.

  6. #6
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Location
    Druidia
    Posts
    3,124
    Quote Originally Posted by Whiteclaws View Post
    COULD ANYONE EXPLAIN THIS NON-SENSE TO ME ?!
    You didn't actually state what the problem is. Not working doesn't cut it. Are you getting a compile error or a GL error? Are you checking for them? You've got changes in whitespace and in the capitalization of position. Those shouldn't make any difference, unless you were binding to vertex attribute by name, which you're not.

  7. #7
    Junior Member Newbie
    Join Date
    Nov 2013
    Posts
    4
    @Dark Photon , this actually was the problem , No errors on compile , no errors in linking & validating , but it didn't work , just didn't work

Posting Permissions

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