PDA

View Full Version : Opengl 3.0 example?



Jacek Nowak
01-31-2009, 06:37 AM
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?

martinsm
01-31-2009, 09:09 AM
You use glVertexAttribPointer (http://www.opengl.org/sdk/docs/man/xhtml/glVertexAttribPointer.xml) 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.

Jacek Nowak
01-31-2009, 10:30 AM
I have never used generic vertex attributes before.
What do you mean by "bind names of attributes to specific indices"?

martinsm
01-31-2009, 10:36 AM
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);

Mars_999
01-31-2009, 12:47 PM
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?

martinsm
01-31-2009, 02:20 PM
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).

Groovounet
02-02-2009, 08:55 AM
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 ...

Jacek Nowak
02-03-2009, 01:31 PM
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 :p What else could be invalidating glDrawElements?

arekkusu
02-03-2009, 02:47 PM
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."

Jacek Nowak
02-06-2009, 01:52 PM
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 :)

tswong
02-06-2009, 07:42 PM
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.

Cippa
02-07-2009, 06:51 AM
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?

tswong
02-07-2009, 08:40 PM
you got to do the matrix calculation by urself, i think.
anyway i did that in this way.

Jacek Nowak
02-08-2009, 02:45 PM
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."

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

martinsm
02-08-2009, 03:36 PM
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.