Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Page 1 of 2 12 LastLast
Results 1 to 10 of 15

Thread: Opengl 3.0 example?

  1. #1
    Junior Member Newbie
    Join Date
    Jan 2009
    Location
    Poland
    Posts
    26

    Opengl 3.0 example?

    Hello. Did anyone manage to create anything more than an opengl 3.0 context? I have no problem creating the forward-compatible context, but I don't know how to render anything without gl*Pointer calls.

    Could anyone provide me with some example code e.g. rendering a triangle?

  2. #2
    Junior Member Regular Contributor
    Join Date
    Mar 2007
    Location
    Latvia
    Posts
    225

    Re: Opengl 3.0 example?

    You use glVertexAttribPointer instead of gl*Pointer calls. To get index either bind names of attributes to specific index'es before linking shader, or get them by glGetAttribLocation after linking. It is same as rendering in OGL 2.1 context without gl*Pointer calls.

  3. #3
    Junior Member Newbie
    Join Date
    Jan 2009
    Location
    Poland
    Posts
    26

    Re: Opengl 3.0 example?

    I have never used generic vertex attributes before.
    What do you mean by "bind names of attributes to specific indices"?

  4. #4
    Junior Member Regular Contributor
    Join Date
    Mar 2007
    Location
    Latvia
    Posts
    225

    Re: Opengl 3.0 example?

    When you have attribute in GLSL:
    Code :
    attribute vec3 vertex_position;

    Before linking program, you use glBindAttribLocation function to associate specific location for attribute:
    Code :
    glBindAttribLocation(shader_program, 2, "vertex_position");
    Now "vertex_position" will have location 2.

    Later, when you need to render, you use this location 2:
    Code :
    glEnableVertexAttribArray(2);
     
    glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, stride, pointer);

  5. #5
    Advanced Member Frequent Contributor Mars_999's Avatar
    Join Date
    Mar 2001
    Location
    Sioux Falls, SD, USA
    Posts
    519

    Re: Opengl 3.0 example?

    Wow did they do away with there stupid vertex attribute rule that you need to have glVertex placed in position 0 IIRC with GL3? and now you can place it where ever you want?

  6. #6
    Junior Member Regular Contributor
    Join Date
    Mar 2007
    Location
    Latvia
    Posts
    225

    Re: Opengl 3.0 example?

    Forward compatible context has no predefined gl_Vertex attribute. You must define all attributes by yourself. And obviously you can bind any generic attribute to any index you want.

    But anyway - even in my GL 2.1 code I do not use any of predefined gl_xxx vertex attributes. I always bind all attributes (position, normal, texcoords, ...) myself, so I will need not to change much in code when I move to GL 3.0 forward compatbile context. Had no problems binding vertex_position to any index I want. Works fine on Mobility X1600, HD2400, 8400M GS, under Windows (GL 2.1 context).

  7. #7
    Super Moderator Frequent Contributor Groovounet's Avatar
    Join Date
    Jul 2004
    Posts
    934

    Re: Opengl 3.0 example?

    The only issue with the 0 vertex attribute is when you are using the immediate mode (with glVertexAttrib*(), no "*Pointer" functions) because the vertex is 'assembled' for rendering at the 0 attribute location call.

    I wish we have some kind of "glBindUniformLocation" to be able to set every variable locations ...

  8. #8
    Junior Member Newbie
    Join Date
    Jan 2009
    Location
    Poland
    Posts
    26

    Re: Opengl 3.0 example?

    oh well, I do not understand. My glDrawElements call returns error GL_INVALID_OPERATION.

    Now, opengl documentation says:

    GL_INVALID_OPERATION is generated if glDrawElements is
    executed between the execution of glBegin and the
    corresponding glEnd.

    I don't use glBegin/glEnd in the code at all, I do not understand What else could be invalidating glDrawElements?

  9. #9
    Advanced Member Frequent Contributor arekkusu's Avatar
    Join Date
    Nov 2003
    Posts
    761

    Re: Opengl 3.0 example?

    If you've made a 3.0 forward-compatible context, you must use VBOs and VAOs. The spec says (in the Deprecation Model chapter):

    "Calling VertexAttribPointer when no buffer object or no
    vertex array object is bound will generate an INVALID OPERATION error,
    as will calling any array drawing command when no vertex array object is
    bound."

  10. #10
    Junior Member Newbie
    Join Date
    Jan 2009
    Location
    Poland
    Posts
    26

    Re: Opengl 3.0 example?

    I really appreciate all the help given to me in this topic, <s>however it still doesn't want to work for me despite having newest drivers installed.</s>

    <s>There is one last thing I suspect - I cannot use PFNGLGENVERTEXARRAYSPROC, I have to use PFNGLGENVERTEXARRAYSAPPLEPROC. Is it a bad thing or are they equivalent?</s>

    THANKS! I finally figured it out. As it turns out, after some desperate fixes, I didn't uncomment the glUseProgram call. As a result, I hadn't had the shader bound while rendering.

    http://img87.imageshack.us/img87/9768/triangledi3.png

    Enjoy

Posting Permissions

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