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?

You use glVertexAttribPointer instead of glPointer 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 glPointer calls.

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

When you have attribute in GLSL:

attribute vec3 vertex_position;

Before linking program, you use glBindAttribLocation function to associate specific location for attribute:

glBindAttribLocation(shader_program, 2, "vertex_position");

Now “vertex_position” will have location 2.

Later, when you need to render, you use this location 2:


glEnableVertexAttribArray(2);

glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, stride, pointer);

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?

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).

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 …

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 :stuck_out_tongue: What else could be invalidating glDrawElements?

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.”

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 :slight_smile:

this is my first opengl3.0 try

http://souxsicx.spaces.live.com/blog/cns!48AC31AE06ACD76B!239.entry

i didnt put any code there, but if u r interested, let me know.

Well, I can understand this, but OpenGL 3 specs says that shaders versions 1.10 and 1.20 are deprecated (obviously for forward-compatible context), with LoadIdentity, LoadMatrix and related GL routines.

Finally, I’m wondering how simply translate vertex positions without model view matrix routines (and most of the builtin uniform state. May I missed something?

you got to do the matrix calculation by urself, i think.
anyway i did that in this way.

Is there some default vertex array object bound? I don’t have any calls to glBindVertexArray() in my entire code, yet VertexAttribPointre doesn’t give me GL_INVALID_OPERATION :stuck_out_tongue:

Then you have some buffer object (VBO) bound. The spec there deprecated pointers to client memory area - it forces in pointer argument to pass offset in buffer object memory.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.