PDA

View Full Version : Great OpenGL 3.1 tutorial



gvizbi
07-10-2009, 02:09 PM
I found this OpenGL 3.1 tutorial (http://www.wikiscripts.net/?action=post&id=149) on Wikiscripts, this is the first part, but author promised that soon there will be a sequel.

LangFox
07-10-2009, 07:45 PM
Nice. Thanks for sharing.

awhig
07-10-2009, 08:15 PM
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.

Aleksandar
07-11-2009, 03:22 AM
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.

Dark Photon
07-11-2009, 06:29 PM
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 (http://www.opengl.org/wiki/Main_Page)) is one idea.

Aleksandar
07-12-2009, 04:51 AM
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!

ZbuffeR
07-12-2009, 12:50 PM
The opengl wiki site needs such code sample and tutorials.
Please put it there :)

Dark Photon
07-12-2009, 08:11 PM
The opengl wiki site needs such code sample and tutorials.
Please put it there :)

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

* http://www.opengl.org/wiki/Tutorials

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

Aleksandar
07-13-2009, 08:42 AM
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) (http://www.opengl.org/wiki/Tutorial:_OpenGL_3.1_The_First_Triangle_(C%2B%2B/Win))

Thank you, guys!

Dark Photon
07-14-2009, 05:28 AM
Looks good, thanks!

Filip
07-14-2009, 02:07 PM
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.

Aleksandar
07-15-2009, 06:56 AM
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)

chris2718
07-15-2009, 12:36 PM
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.

Aleksandar
07-15-2009, 01:28 PM
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.

Aleksandar
07-25-2009, 01:09 PM
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?

Aleksandar
07-26-2009, 11:26 AM
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

Aleksandar
07-31-2009, 03:27 AM
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.

cplusrun
09-16-2009, 06:31 PM
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

cplusrun
09-16-2009, 07:00 PM
I'm sorry, I see now that CDC is part of MFC. I'm downloading it now, and hopefully won't have anymore problems ;)

dorbie
09-16-2009, 07:15 PM
The opengl wiki site needs such code sample and tutorials.
Please put it there :)

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

* http://www.opengl.org/wiki/Tutorials

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


Nice.

This could be the start of something dangerous ;-)

Aleksandar
09-17-2009, 07:47 AM
This could be the start of something dangerous ;-)
I have realized the same thing! ;)
And decided to put tutorials on different site. If community judge some of them as useful, then they will be transfered to OpenGL.org/wiki. :)