Great OpenGL 3.1 tutorial

I found this OpenGL 3.1 tutorial on Wikiscripts, this is the first part, but author promised that soon there will be a sequel.

Nice. Thanks for sharing.

Cool!!! I was looking for some tutorial that gives insight to working with MFC. MSDN’s resource is good too but many times go overhead.

This link atleast takes pains to explain things from scratch.

First, I have to criticize gvizbi for the title. It is not a great tutorial, but just the beginning of something that could help. :o)

And second, because wikiscripts do not have a way to discuss about topics, please be free to express your opinions and post requests on this forum.

There are a lot of tutorials how to bind OpenGL code to MFC application, but if you think it is an interesting topic, it will be covered in my next tutorial.

None of the usual browser tools that you’d just expect to work (search, highlight, bookmark, scrapbook, etc.) work because this site decided to make the whole page a silly flash app.

Similarly, google apparently doesn’t find the content of this page because it is just a flash app.

So thanks for the tutorial, but please consider a different forum that makes article text standard, searchable, indexable web text. The OpenGL.org wiki (http://www.opengl.org/wiki) is one idea.

Thank you for the suggestion!

I’ll put it on OpenGL.org, but I have to change it a little bit. It is still not “mature” enough. This is just my little donation to the community. :o)

This tutorial is more a solution of problems in Leonardi’s code (thanks, Leonardi for the first public OpenGL 3 code) and my reflections on building the first application, than a stand alone full featured OpenGL 3.1 tutorial. There is a problem in teaching OpenGL 3.x, because there are a lot of things to do to get the first outcome. Probably, it is a good idea to break the code into many separate tutorials, and build some kind of “framework” allowing students to “play” only with little snippets of code.

I do not want to overwhelm this site with my code samples and tutorials. :o)
But I promise to make a pure html site dedicated to OpenGL programming.

Thanks for the friendly hug!

The opengl wiki site needs such code sample and tutorials.
Please put it there :slight_smile:

Just created a tutorials page on the wiki, linked to the main page:

and tossed in a little OpenGL 3.0 context creation tutorial/snippet for GLX adapted from previous forum posts.

I’m not very satisfied what I’ve done, but I hope it will serve the purpose for a while (until I find time to update it, and post other tutorials). The link is:

http://www.opengl.org/wiki/Tutorial:OpenGL_3.1_The_First_Triangle(C++/Win)

Thank you, guys!

Looks good, thanks!

Great to see people starting to make tutorials. I see some issues with your code that I wanted to point out. You set VBOs and vertex attributes in the draw loop even though you use VAOs. This kind of defeats the purpose of using VAOs as I see it. Or do I misunderstand the purpose of the tutorial? (Just scanned it briefly)
In any case, I think it would be good to make sure that tutorials on the official wiki uses functionality in a way that is effective and concise, following the purposes of the standard.

Please change to: set VBOs and and vertex attributes once (since it is static) and just bind the VAOs in the draw loop.

Thank you for the suggestion. I know the purpose of VBO, but there is a small problem. The code can be organized this way:


void CGLRenderer::BuildData()
{
     // ...
     glGenBuffers(2, m_vboID);

     glBindBuffer(GL_ARRAY_BUFFER, m_vboID[0] );	         
     glBufferData(GL_ARRAY_BUFFER, 9*sizeof(GLfloat), vert, GL_STATIC_DRAW);
     glEnableVertexAttribArray(0);
     glVertexAttribPointer((GLuint)0, 3, GL_FLOAT, GL_FALSE, 0, 0); 

     glBindBuffer(GL_ARRAY_BUFFER, m_vboID[1]);
     glBufferData(GL_ARRAY_BUFFER, 9*sizeof(GLfloat), col, GL_STATIC_DRAW);
     glEnableVertexAttribArray(1);
     glVertexAttribPointer((GLuint)1, 3, GL_FLOAT, GL_FALSE, 0, 0);

     glBindVertexArray(0);
     // ...
}

void CGLRenderer::DrawScene()
{
     // ...
     glClear(GL_COLOR_BUFFER_BIT);
     glBindVertexArray(m_vaoID);
     glDrawArrays(GL_TRIANGLES, 0, 3);	 
     // ...
}


It works perfectly fine, but if you try to Enable or Disable any of VertexAttribArrays, the program will crush. That’s one of the problem I mentioned in the first version of the tutorial.

One or two function calls more per VBO gives me more feedom to disable AttribArrays at will. I still don’t know why program crushes. If any one have an idea, it will be interesting to share it with us. :o)

You have to
glBindVertexArray before glEnableVertexArray (or any operations on the current vertex array) otherwise opengl gl will not use the correct one or the one enabled before.

I know that! And I did it, of course, but that was not the problem. I have posted the whole code, so that anyone can try. It is Visual Studio 2008 SP1 project.

I have changed the tutorial on OpenGl.org/Wiki. Now it shows how to deal with two (and more) VAOs. In fact, the problem was in the way of thinking (i.e. programming practice). We do not have to enable/disable vertex attribute arrays, as we did before with a single client state object, but to create many separate VAOs with adequate states and just to bind them. Although it can be useful sometimes to disable/enable some auxiliary arrays, current version of NVidia drivers do not allow that. After disabling some arrays, if we want to enable them again, we have to bind VBOs again and define offsets (with glVertexAttribPointer).

But now I have another problem. The first tutorial was called The First Triangle. To demonstrate two VAOs, I added another triangle. So, the title is inadequate. The only way to solve this problem is to delete tutorial and create new link. Should I do this, or let it stay as it is?

I have received several questions and complainings that the code does not work on Radeon cards. I don’t have any Radeon in my computers, so I, personally, did not try it. Until we found why Radeon is so unfriendly to my tutorial, I’ll post all comments daily on: http://www.wikiscripts.net/?action=user&id=23

Thanks to Stephane Denis, the problem with fragment shader is solved! The following line must be added to fragment shader before variables declaration:

 precision highp float;

Precision qualifiers are added to PenGL 3.0 spec for code portability with OpenGL ES, not for functionality. They have the same syntax as in OpenGL ES, but they have no semantic meaning, which includes no effect on the precision used to store or operate on variables.

According to latest GLSL specification (ver.1.40.07):
“The fragment language has the following predeclared globally scoped default precision statements:
precision mediump int;
precision highp float;”

So, we shouldn’t need to define precision, especially when it means nothing to GLSL compiler. NVIDIA follows this spec. But, in order to compile fragment shader with Catalyst drivers, the precision declaration is obligatory.

I’m having a problem compiling the tutorial. I’m using VC++ 2008 express. When I try to compile it tells me

‘CDC’ : undeclared identifier
‘pDC’ : undeclared identifier

among other things. I tried searching around, but couldn’t really find anything relating to either one of these. Any help would be appreciated. Thanks

I’m sorry, I see now that CDC is part of MFC. I’m downloading it now, and hopefully won’t have anymore problems :wink:

Just created a tutorials page on the wiki, linked to the main page:

and tossed in a little OpenGL 3.0 context creation tutorial/snippet for GLX adapted from previous forum posts.
[/QUOTE]

Nice.

This could be the start of something dangerous :wink: