ENIGMA Forums

General fluff => Off-Topic => Topic started by: lonewolff on September 29, 2014, 09:57:53 PM

Title: Good places to learn OpenGL
Post by: lonewolff on September 29, 2014, 09:57:53 PM
Hi Guys,

OpenGL remains a mystery to me. Information seems to be sparse for good places to begin.

The things that confuse that crap out of me


Like I said, complete noob when it comes to OpenGL.

Where the hell do you start?
Title: Re: Good places to learn OpenGL
Post by: TheExDeus on September 30, 2014, 04:59:00 AM
Quote
There is no SDK - how the hell do you use it then
SDK comes with Mingw and Windows itself. To have real access to functions you need to use a library like Glew (there are other alternatives too).
Quote
The SDK's out there seem to be wrappers - SDL, GLUT, etc.. So, where do you start? What is the best place to start?
You take one of those wrappers and code. There are many tutorials on the internet, but they are often out of date, as versions below <GL3 were very different from newer ones (ENIGMA supports both). You can looking for some up to date tutorials here: http://www.lighthouse3d.com/ as well as youtube videos: https://www.youtube.com/watch?v=6-9XFm7XAT8#t=2591 https://www.youtube.com/watch?v=IXxc9yNBpuo. There are lot of youtube videos about opengl.

Quote
Cross platformness - what version of OpenGL do you use for this?
Windows, Linux and OSX run everything from GL1 to GL4. If you want embedded devices (phones - IOS, Android or ARM PC's like Raspberry Pi) you need to use OpenGLES (ES - Embedded Systems). GLES2 is about the same as GL3.3, so they are quite compatible with one another and it should be easy to convert. If you code in GL4, then it's totally 100% compatible with the newest GLES version.

Quote
Where the hell do you start?
I started with ENIGMA.
Title: Re: Good places to learn OpenGL
Post by: Rusky on September 30, 2014, 11:42:59 AM
To add to that, the reason for the wrappers is that every platform has a different way to get an OpenGL context and to actually put things on the screen- Windows uses wgl and Win32 functions, Linux uses glX and X11 functions, etc.

GLFW is probably the lightest wrapper there is- it lets you just create a window without dealing with platform-specific APIs. Probably a good place to start if you just want to #include a few headers, make a window, and start making GL calls.

You'll also need GLEW whichever window/context library you use, to load GL extensions (which is a euphemism for "almost all the modern API"). But it's pretty simple too- just #include a header and call a function to initialize everything.

A couple of other good tutorials: http://www.opengl-tutorial.org/ https://open.gl/
Title: Re: Good places to learn OpenGL
Post by: The 11th plague of Egypt on September 30, 2014, 02:45:35 PM
Unless you want yo build Yet Another Graphics Engine, then I'd suggest you avoid learning the gory details of OpenGL and pick something less low level.

I've yet to see a person learn OpenGL AND finish an actual game.

Want something that works cross platform and does more than just graphics?
http://libgdx.badlogicgames.com/
http://jmonkeyengine.org/

Just graphics and low level stuff?
http://www.ogre3d.org/
Title: Re: Good places to learn OpenGL
Post by: Goombert on September 30, 2014, 02:46:56 PM
Yes if you want to just start making some small OpenGL applications I suggest you download Code::Blocks which will come with MinGW and isn't very large and you can build some nice little OpenGL apps. However if you want something a little cleaner, Qt Creator has a very nice interface for building OpenGL applications that may be a little easier to learn, and they also include examples.

http://programanddesign.com/cpp/qt-opengl-code-example/

Also, as an alternative to Ogre3D, which is a huge bitch to compile, I would like to suggest Irrlicht which is extremely light weight and can do quite a bit including Geomipmapped terrain and stuff as well as make 2D games, has a GUI framework and everything and makes use of different drivers for Direct3D9/10/11 and OpenGL1/2/3/4 I honestly can't suggest anything else for a budding game developer wanting to use C++
Irrlicht also likes to play nice with GNU Make.
http://irrlicht.sourceforge.net/
Title: Re: Good places to learn OpenGL
Post by: lonewolff on September 30, 2014, 05:03:24 PM
Thanks for the replies, guys! Awesome stuff.

Rob - Funnily enough, I am quite familiar with Ogre3D (and it's compilation problems - lots of them). I actually wrote and Ogre 3D extension for GameMaker (unreleased) - LOL.

Some of the screenies in my other thread were using that very extension (Like this).

(http://www.win32developer.com/general_images/ogre_00.png)

So, there is no real 'consistent' OpenGL API as such then? Is it pretty much a case of pick an API like Ogre, SDL, etc and learn their wrapper functions? Fine by me if that is the case.

If that does happen to be the case then I allready know OpenGL - LOL.  :)
Title: Re: Good places to learn OpenGL
Post by: Darkstar2 on September 30, 2014, 06:35:00 PM
You are very skilled, I can only imagine what your full finished games would look like, you would be the RARE developers using GM/ENIGMA that would be pushing the limits.
Title: Re: Good places to learn OpenGL
Post by: Rusky on September 30, 2014, 07:57:41 PM
No, there is a consistent, standard OpenGL API. It just doesn't include context creation or backbuffer swapping. The only thing you need wrappers for is initializing a window with a GL context and calling some sort of SwapBuffers() once per frame.
Title: Re: Good places to learn OpenGL
Post by: TheExDeus on October 01, 2014, 02:59:42 AM
The API is the Khronos Group's published spec. There are thousands of built-in functions, which are then used to do what you want. As Rusky said, you only need special functions for context creation and some other few things. Like in fixed function pipeline you have this:
Code: (C) [Select]
glBegin(gl_triangleList);
glVertex(10,10);
glVertex(50,10);
glVertex(10,50);
glEnd();
This will draw a triangle. Those functions are defined by OpenGL spec, and implement in all OS's. You don't need Ogre or SDL anything else to use them. ENIGMA for example doesn't use any of the wrappers. We code OpenGL from ground up and only use GLEW for extensions.
Title: Re: Good places to learn OpenGL
Post by: Goombert on October 01, 2014, 03:19:50 AM
Yes Harri is right, and further anybody that can initialize Direct3D on a Win32 window could and should be able to easily write an OpenGL application without difficulty.
Title: Re: Good places to learn OpenGL
Post by: lonewolff on October 01, 2014, 03:33:50 AM
The API is the Khronos Group's published spec. There are thousands of built-in functions, which are then used to do what you want. As Rusky said, you only need special functions for context creation and some other few things. Like in fixed function pipeline you have this:
Code: (C) [Select]
glBegin(gl_triangleList);
glVertex(10,10);
glVertex(50,10);
glVertex(10,50);
glEnd();
This will draw a triangle. Those functions are defined by OpenGL spec, and implement in all OS's. You don't need Ogre or SDL anything else to use them. ENIGMA for example doesn't use any of the wrappers. We code OpenGL from ground up and only use GLEW for extensions.

Thanks guys! :)

And geez, that code snippet looks simple as anything. Is it really that easy to render a triangle in OpenGL? If so, where has OpenGL been all my life? :)
Title: Re: Good places to learn OpenGL
Post by: TheExDeus on October 01, 2014, 04:28:09 AM
That code is what is called "Immediate mode". It's <GL3 and is now deprecated. Considered slow and ugly. But it's simple. Newer GL (like our GL3.3 implementation in ENIGMA) uses Vertex Buffer Object's (VBO) and Vertex Array Objects (VAO), which makes the whole thing a lot more complicated and you need a lot more code to actually draw something. The triangle example would be something like this:
Code: (C) [Select]
float triangle[] = {10.,10., 50.,10., 10.,50.};
GLuint VBO, VAO;
 
glGenBuffers( 1, &VBO);
glGenVertexArrays(1, &VAO);

//Bind the VBO and transfer our triangle data from RAM to VRAM
glBindBuffer( GL_ARRAY_BUFFER, VBO);
glBufferData( GL_ARRAY_BUFFER, sizeof(triangle), triangle, GL_STATIC_DRAW);

//This is just required so the video card knows how to interpret the data
glBindVertexArray(VAO);
glEnableVertexAttribArray(shader_att_vertex);
glVertexAttribPointer(shader_att_vertex, 2, GL_FLOAT, GL_FALSE, 2, 0);

//Actually draw the triangle
glDrawElements(GL_TRIANGLES, 6, GL_FLOAT, 0);

//Cleanup
glBindBuffer( GL_ARRAY_BUFFER, 0);
glBindVertexArray(0);
glDeleteBuffers(1, &VBO);
glDeleteVertexArrays(1, &VAO);
This is all required to draw a single triangle in GL3.3 Core Context. Additionally you have to write a pixel and vertex shader (to draw a simple triangle, they would be about 5 lines each) and add additional code to use it (like I didn't write where shader_att_vertex is from). So the newer one is a lot more complicated and usually harder to learn, but it's a lot faster. Especially if written correctly. And it allows a lot more possibilities.
Title: Re: Good places to learn OpenGL
Post by: Goombert on October 01, 2014, 04:31:46 AM
Actually Harri, I don't think you have to use VBO's. I would like you to find out, since you have the means of doing so I don't actually know how you find out which functions are which core, if vertex arrays like we use in GL1 for models can be used in newer GL cores. Do you know if they can or not? I think they can because they can also interface with vertex attribute arrays and shaders. They are immensely easier to use than VBO's.

Edit: From what I gather vertex array's are usable in GLES.
https://www.khronos.org/registry/gles/extensions/OES/OES_vertex_array_object.txt
Title: Re: Good places to learn OpenGL
Post by: lonewolff on October 01, 2014, 05:29:47 AM
Ah ok, seems not too dissimilar to DirectX 11.  (Y)
Title: Re: Good places to learn OpenGL
Post by: TheExDeus on October 01, 2014, 05:57:16 AM
Quote
Actually Harri, I don't think you have to use VBO's. I would like you to find out, since you have the means of doing so I don't actually know how you find out which functions are which core, if vertex arrays like we use in GL1 for models can be used in newer GL cores. Do you know if they can or not? I think they can because they can also interface with vertex attribute arrays and shaders. They are immensely easier to use than VBO's.
They are not available in GL3. Only VBO's are supported. There is no glEnableClientState or glVertexPointer functions in GL3.3. There are several ways to see what is deprecated and what isn't. One is during runtime by setting the core context. It's done in my GL3.3Fix branch, where it actually trows an error if something deprecated is called. Second way is to search for the function in the docs, both official https://www.opengl.org/sdk/docs/man3/ or this http://docs.gl/gl3/glEnableClientState . The second site is awesome because you can choose the version of GL in the left panel, and then see what functions are unavailable (grayed out).

Quote
Edit: From what I gather vertex array's are usable in GLES.
https://www.khronos.org/registry/gles/extensions/OES/OES_vertex_array_object.txt
Vertex array objects (VAO) is not the same as a vertex array (GL_VERTEX_ARRAY). VAO don't hold vertex data, it holds the description about that data. It's actually required in GL3.3 Core. That is why it didn't render anything previously on my GL3.3 branch, because we didn't create a VAO for the mesh.
Title: Re: Good places to learn OpenGL
Post by: Goombert on October 01, 2014, 08:09:08 AM
That actually kind of upsets me, because this is one of the powerful features Direct3D 9, 10, and 11 all have, they can force software vertex processing as well as emulate shader models not supported by the current graphics card which makes them a lot more compatible with older graphics hardware. In Direct3D it's just a flag, in OpenGL you have to write your code twice if you want it to be able to support software and hardware, and even then it won't be core compliant.

So that is a huge disappointment for me with OpenGL, has been for a while actually.

Title: Re: Good places to learn OpenGL
Post by: TheExDeus on October 01, 2014, 01:33:04 PM
There just no need for it in GL. VBO's are supported since 2003. We don't need to support Amiga in our GL3.3 rendering engine. If you want ancient hardware (and I mean ancient, not old, old hardware even supports GL3). There is 0 need for software vertex processing. It's the most useless feature ever, as you wouldn't be able to render more than 50k vertices (that is probably a stretch too).