Sign in to follow this  
tre

OpenGL To transition to OpenGL 3.2

Recommended Posts

Hi, my question is basically: How do I move to 3.2 core profile from before using and mostly understanding the Nehe tutorials? The projects I've previously written have been based on the Nehe tutorials and now that I feel kind of comfortable with that code I thought that moving to more modern code would be a good thing. However I'm getting stumped all around when I try to find tutorials, guides or whatever that explains how to set up a 3.2 context (the highest version supported by my graphics card). Are there any great tutorials out there on this? Or, rather, how should I start? I'm lost again :) Thanks, Marcus Axelsson (goes back to reading the specification with a worried expression)

Share this post


Link to post
Share on other sites
I have been learning OpenGL 3.2 core profile for about a month. There are some tutorials which are very useful. For example,

http://www.opengl.org/wiki/Category:Tutorials
http://sites.google.com/site/opengltutorialsbyaks/introduction-to-opengl-3-2---tutorial-01
http://nopper.tv/opengl_3_2.html
http://www.g-truc.net/post-0204.html

By reading these materials, it is easy to set up my first demo with phong lighting and texture mapping.

However, the most troublesome problem for me is the immature support by related development libraries. Especially, the GUI libraries like freeglut, SDL and QT, are still far away from stable support for core profile. I have post some threads in this forum to show the bugs of freeglut and no solution could be received. I hope all the problems could be solved as soon as possible.

Share this post


Link to post
Share on other sites
I've checked out two of those links (the sample program links) before and they're OK. I hope to understand them better after having read through the specification. The other two links seem allright. I'll have a close look at those.

The libraries you mention will probably have support soon enough. Or maybe they're working on 4.0 compatible code instead? It'd be great with some 3 compatible stuff though, since I'm not really in a position to buy a new graphics card right now :)

Thanks for the links.

Anyone else got something? All references and guides, tutorials and code samples are welcome.

Thanks,
Marcus Axelsson

Share this post


Link to post
Share on other sites
Quote:
Original post by ZHAO Peng
Especially, the GUI libraries like freeglut, SDL and QT, are still far away from stable support for core profile.
It is even worse, not even the most basic libraries like GLEW and GLee do, which is ironical since they explicitely claim to support all the new versions and extensions. Nevertheless, both libraries use the 1.x mechanism for querying extensions. Which, in principle is fine, since the 3.x way totally sucks (especially if you want support both 1.x/2.x and 3.x codepaths), whereas the 1.x way works perfectly well.

However, the 1.x extension query mechanism is deprecated for 3.0 and removed from 3.1, and it is indeed unimplemented (or rather, disabled -- returns null) on recent drivers. I've even had that happen on a compatibility profile (where it's supposed to work!) on a nVidia development driver not long ago, though that was probably a driver bug.
Sadly, the Khronos group seems to have put a lot of effort into making migrating to OpenGL 3.x while retaining a legacy path as troublesome as possible (GLSL versions being another such thing), you have to wonder why. Probably the plan behind that is something like "move on, no way back".

In reply to the OP:
You must use either wglCreateContextAttribsARB or the glx counterpart, depending on whether you're under Windows or Unix.
These functions take a zero-terminated list of name-value integer pairs. Upon first sight, this may be confusing, but once you get it, it is actually quite nice, flexible, and easy. Don't forget the zero at the end!
Also, do note that you must create a fake context first to get the function pointer to that function. You cannot just call the function like that.
The links posted by ZHAO Peng show how to do this.

Also, you must use glGetStringi instead of glGetString to query for extensions. This involves many more driver calls than "the old way" did, and it makes caching the info a lot more tedious too, but alas... that's how it is. If you structure your program properly so all caps are queried at startup and stored in a few global variables, it doesn't make a real difference at runtime, though it might take half a second longer to start up.
Actually, to be correct, you must get a function pointer for glGetStringi, too, since it is not a OpenGL 1.3 function (only implemented after 3.0). Strange enough, it does work either way on my system, so it seems that glGetStringi actually has an entry in the GL import library. I don't think that this is technically correct.

Share this post


Link to post
Share on other sites
Sorry! After lots of tries, I should admit that the core profile support of freeglut is not so bad. The problems I met are caused by GLEW. "glewExperimental" should be set to "GL_TRUE" for the drivers NVIDIA-Linux-x86_64-190.53 and NVIDIA-Linux-x86_64-195.36.07.04.

God! I have wasted several days for this "trap".

Share this post


Link to post
Share on other sites
Quote:
Original post by ZHAO Peng
Sorry! After lots of tries, I should admit that the core profile support of freeglut is not so bad. The problems I met are caused by GLEW. "glewExperimental" should be set to "GL_TRUE" for the drivers NVIDIA-Linux-x86_64-190.53 and NVIDIA-Linux-x86_64-195.36.07.04.
God! I have wasted several days for this "trap".

I've not tried it yet but someone's written a OpenGL 3/4 core profile extractor (see here). It looks a bit like a GLEW for core profiles.

Looks like it might be useful if your IDE does function name completion and you don't want it to keep suggesting deprecated functions.

Share this post


Link to post
Share on other sites
Quote:
Original post by dave j
Quote:
Original post by ZHAO Peng
Sorry! After lots of tries, I should admit that the core profile support of freeglut is not so bad. The problems I met are caused by GLEW. "glewExperimental" should be set to "GL_TRUE" for the drivers NVIDIA-Linux-x86_64-190.53 and NVIDIA-Linux-x86_64-195.36.07.04.
God! I have wasted several days for this "trap".

I've not tried it yet but someone's written a OpenGL 3/4 core profile extractor (see here). It looks a bit like a GLEW for core profiles.

Looks like it might be useful if your IDE does function name completion and you don't want it to keep suggesting deprecated functions.


Yes, GL3W looks a new and easy use library which is similar to GLEW. It's good news for programmers to have one more choice. Thanks!

Share this post


Link to post
Share on other sites
Hm. gl3w seemed really useful. But I can't run the script at all. I get an "invalid syntax" error when I try to run it (python.exe "gl3w.py"). So... too bad :/

With GLUT and this gl3w I think it'd be a breeze to get the ogl 3.2 context up and running. Which would be great :)

Thanks for keeping the thread alive, guys.

Share this post


Link to post
Share on other sites
Quote:
Original post by tre
Hm. gl3w seemed really useful. But I can't run the script at all. I get an "invalid syntax" error when I try to run it (python.exe "gl3w.py"). So... too bad :/

With GLUT and this gl3w I think it'd be a breeze to get the ogl 3.2 context up and running. Which would be great :)

Thanks for keeping the thread alive, guys.

Which version of Python are you using? The script is for 2.6.

Share this post


Link to post
Share on other sites
I have to be honest, I'm about to give up on all of this.
I'm still counting myself as a beginner and I've been focused on getting OpenGL functioning correctly for me. I've got a small program up and running in the old context. I've got shaders creating "nightlights" on a globe which the user can rotate around.
Now I'm supposed to go from this to the new context and nothing will work. There are no decent tutorials out there at all. I've searched, believe me.
There are sample programs but they are very, very, very lacking in comment or explaining text.

I do not want to have it all laid out in front of me, but man, this is ridiculous!
I can get an OGL 3.2 context going. I did actually. But when I got the context going I found out that I can't do... well... anything. Since everything I've been learning for the past one and a half years is now deprecated code.

Previously I've used the NeHe tutorials to get me going and understanding OGL and Windows programming and that went so well that I finally could stand on my own wobbly legs. Now that the context has changed, and not only from 3.x but to 4.0 (which I can't program for), there is nothing I can read and understand. I've never used GLUT before but used NeHe's code for creating a window and the OGL context. But now I've found myself using GLUT instead, which I'm not really comfortable with. It feels strange. Is it really this easy to use (create a couple of display/reshape/input functions, glutSwapBuffers and then compile)? Or am I missing something? Because it feels like I'm skipping most of the programming I've been doing the last year.

And more questions. What the H is GLUS? The Python script gave me a OGL3.2 context but now what? How do I proceed? What has substituted GL_MATRIXMODE and GL_PROJECTION? And why? Setting up shaders with GLUT? My god, I can't even figure out why the keyboard won't react to the "r" button on my keyboard (or turns my cube turqoise) with the keyboardfunc in GLUT.

You see, it's quite a bit to catch up on. What I'm seriously considering is if it's really worth the trouble.

Input, please. I'm not really ready to quit my game programming aspirations just yet, but it's such a daunting task right now. Everything is new, and I have nothing to go by. I'm sort of fumbling in the dark here.

Sorry if this comes off as a crazed rant. I'm sure OGL is still as powerful (or more powerful) than ever before. It just took a turn for the worse for me. Too many changes, too soon.
The specifications aren't really helping me much. Just feels like Khronos is saying "we're so great since OGL can do this and this now and by the way 90 percent of what you've learnt is now pure crap". And then a list over deprecated functions. So I'm not really too hot for the specification just yet (however, note that I've not read all of it yet).

I'm frustrated and this became too long. Sorry for that.

What I'm really hoping for is some guidance, really.

All the best,
Marcus Axelsson

Share this post


Link to post
Share on other sites
Quote:
Original post by HuntsMan
If it's too hard, try learning OpenGL 2.0 first, then shaders, and then, you'll be ready to use OpenGL 3.2 without problems.


Thanks for your reply.
I thought I had a grip on 2.0 though, but maybe not. I've allready written some shaders. Maybe it's not enough.
Thanks again. I'll go back to 2.0 and hack on through that one.

Share this post


Link to post
Share on other sites
Quote:
Original post by tre
I have to be honest, I'm about to give up on all of this.
I'm still counting myself as a beginner and I've been focused on getting OpenGL functioning correctly for me. I've got a small program up and running in the old context. I've got shaders creating "nightlights" on a globe which the user can rotate around.
Now I'm supposed to go from this to the new context and nothing will work. There are no decent tutorials out there at all. I've searched, believe me.
There are sample programs but they are very, very, very lacking in comment or explaining text.


Yes, I agree with you about the tutorials and samples. However, it is not very hard to read the sample codes and find the explain on the wiki (like VBO, VAO, UBO...).

Quote:
Original post by tre
I do not want to have it all laid out in front of me, but man, this is ridiculous!
I can get an OGL 3.2 context going. I did actually. But when I got the context going I found out that I can't do... well... anything. Since everything I've been learning for the past one and a half years is now deprecated code.
Previously I've used the NeHe tutorials to get me going and understanding OGL and Windows programming and that went so well that I finally could stand on my own wobbly legs. Now that the context has changed, and not only from 3.x but to 4.0 (which I can't program for), there is nothing I can read and understand. I've never used GLUT before but used NeHe's code for creating a window and the OGL context. But now I've found myself using GLUT instead, which I'm not really comfortable with. It feels strange. Is it really this easy to use (create a couple of display/reshape/input functions, glutSwapBuffers and then compile)? Or am I missing something? Because it feels like I'm skipping most of the programming I've been doing the last year.

And more questions. What the H is GLUS? The Python script gave me a OGL3.2 context but now what? How do I proceed? What has substituted GL_MATRIXMODE and GL_PROJECTION? And why? Setting up shaders with GLUT? My god, I can't even figure out why the keyboard won't react to the "r" button on my keyboard (or turns my cube turqoise) with the keyboardfunc in GLUT.


I have learned the OpenGL core profile for several weeks. I use freeglut (codes from SVN), GLEW 1.5.4, GLM 0.9Beta2 on OpenSUSE 11.2 with Nvidia GTX260. After some hard work, everything is OK. It is necessary to call "glutInitContextVersion(3,3); glutInitContextProfile(GLUT_CORE_PROFILE);" and " glewExperimental= GL_TRUE;
GLenum err = glewInit();". This can make sure that freeglut and GLEW could work properly.

GL_MATRIXMODE and GL_PROJECTION have been removed from core profile. Firstly, uniform variables for model view matrix and projection matrix should be declared in vertex shader.Then we can compute the matrices using GLM which is really simple in the host application and set the values using glUniformMatrix4fv. You can find these codes in most samples.
The keyboard function should work well in freeglut. I am not sure what is your problem.


Quote:
Original post by tre
You see, it's quite a bit to catch up on. What I'm seriously considering is if it's really worth the trouble.

Input, please. I'm not really ready to quit my game programming aspirations just yet, but it's such a daunting task right now. Everything is new, and I have nothing to go by. I'm sort of fumbling in the dark here.

Sorry if this comes off as a crazed rant. I'm sure OGL is still as powerful (or more powerful) than ever before. It just took a turn for the worse for me. Too many changes, too soon.
The specifications aren't really helping me much. Just feels like Khronos is saying "we're so great since OGL can do this and this now and by the way 90 percent of what you've learnt is now pure crap". And then a list over deprecated functions. So I'm not really too hot for the specification just yet (however, note that I've not read all of it yet).


Although it is painful to forget the old functions and experiences, we have to go ahead to the future. Modern OpenGL pipeline is more flexible and powerful. I think it is worth working hard at it.


Share this post


Link to post
Share on other sites
First off I'd like to ask forgiveness for the above post that I made. I got very, very frustrated and when I do I usually rant. However my point is still in there and very much alive: Why would anyone, no matter how much better it is with this new way of doing things, in their right mind change it all and then not give simple code with enough comments so that anyone who's been using OGL < 3.x could understand it? It is a very strange way of doing things, this. Changing it this much and then not provide enough information so that people are left spending hours, days, months to get it working.


Quote:
Original post by ZHAO Peng
Yes, I agree with you about the tutorials and samples. However, it is not very hard to read the sample codes and find the explain on the wiki (like VBO, VAO, UBO...).

I guess I got very frustrated. The sample code I've downloaded (nopper and the rest) run stuff I can't find information on. Say Nopper, those code samples run something called GLUS and I can't find documentation on it anywhere. Very strange.

Quote:
Original post by ZHAO Peng
I have learned the OpenGL core profile for several weeks. I use freeglut (codes from SVN), GLEW 1.5.4, GLM 0.9Beta2 on OpenSUSE 11.2 with Nvidia GTX260. After some hard work, everything is OK. It is necessary to call "glutInitContextVersion(3,3); glutInitContextProfile(GLUT_CORE_PROFILE);" and " glewExperimental= GL_TRUE;
GLenum err = glewInit();". This can make sure that freeglut and GLEW could work properly.

GL_MATRIXMODE and GL_PROJECTION have been removed from core profile. Firstly, uniform variables for model view matrix and projection matrix should be declared in vertex shader.Then we can compute the matrices using GLM which is really simple in the host application and set the values using glUniformMatrix4fv. You can find these codes in most samples.
The keyboard function should work well in freeglut. I am not sure what is your problem.

I'm trying to get this working with GLUT / FreeGLUT, GLEW in Vista x64 on a 8800GTX.
Where can I find documentation on FreeGLUT, then? How should I know that I need to run the InitContext and ContextProfile? And what does glewExperimental do? When I try to find information on that on google I just end up confused. Why is it necessary for OpenGL 3.x?
So when I've created an OGL 3.2 context I should create a shader pair, just the normal "here's the vertex" and "this is the fragment color" shaders? Or is it more advanced? What do I need to do at this point?
I've downloaded GLM now and I've been reading about it a bit. So setting the "position values" in main.cpp and sending them to a shader with a uniform would be allright?
Never mind the keyboard function, that's just got to be a part of my rant yesterday :)

Quote:
Original post by ZHAO Peng
Although it is painful to forget the old functions and experiences, we have to go ahead to the future. Modern OpenGL pipeline is more flexible and powerful. I think it is worth working hard at it.

I know. I want to move forward but can't seem to get a grip around how to walk. It's frustrating for me, but I'm going to move forward (or die trying it seems like). The new pipeline does look more flexible and powerful, but as an aspiring developer I don't want to see the GL shrouded in fog and difficulties. It should be open and clear. It doesn't have to be easy, but the more difficult something is, the better commented and documented it has to be. It would've made everything much easier.
I will keep trying to get this to work and try to be a part of the future.

Thanks for taking the time and answering my very long rant that I'm a bit embarrassed about today :)

Share this post


Link to post
Share on other sites
Quote:
Original post by tre
First off I'd like to ask forgiveness for the above post that I made. I got very, very frustrated and when I do I usually rant. However my point is still in there and very much alive: Why would anyone, no matter how much better it is with this new way of doing things, in their right mind change it all and then not give simple code with enough comments so that anyone who's been using OGL < 3.x could understand it? It is a very strange way of doing things, this. Changing it this much and then not provide enough information so that people are left spending hours, days, months to get it working.

Actually, I also felt painful to meet so many new concepts and techniques like VBO, VAO,UBO...
After reading some materials, I have got initial understanding about them. The red book has been updated to the version 7 which covers OpenGL 3.0&3.1. If you could get one, it should be very useful. The books and other materials for OpenGL 3.2 or later should be published in the future. However, programmers could not wait so long. Sometimes learning these new techniques is like an adventure which could make me excited.

Quote:

Say Nopper, those code samples run something called GLUS and I can't find documentation on it anywhere. Very strange.

GLUS is just a very preliminary library written by Nopper for his OpenGL 3.2 samples. It is lack of many indispensable functions. It is not fair to ask him to build a great libary for us in a short time.:) Maybe it will become more mature. However, libraries like freeglut and qt should be used currently.

Quote:

Where can I find documentation on FreeGLUT, then? How should I know that I need to run the InitContext and ContextProfile? And what does glewExperimental do? When I try to find information on that on google I just end up confused. Why is it necessary for OpenGL 3.x?

In fact, I don't read the document of freeglut because most of the functions don't change. When move to the OpenGL3.2, I know it introduces the profile mechanism. So I search in the head file and find glutInitContextVersion and glutInitContextProfile. glewExperimental really upset me. When I use core profile, some functions could not be got by GLEW. I wasted several days for this problem. Finally I found glewExperimental=GL_TRUE in Nopper's samples. You can find the detail on the website of GLEW.

Quote:

I've downloaded GLM now and I've been reading about it a bit. So setting the "position values" in main.cpp and sending them to a shader with a uniform would be allright?

Yes, just compute the transform matrixes using GLM and send them to shader. In the vertex shader, vertex coordinates should be multiplied by these matrixes.

Quote:

The new pipeline does look more flexible and powerful, but as an aspiring developer I don't want to see the GL shrouded in fog and difficulties. It should be open and clear. It doesn't have to be easy, but the more difficult something is, the better commented and documented it has to be. It would've made everything much easier.

Maybe Khronos are too busy and other evolved companies don't want to put their effort into it. The only way is to wait for the books and better tutorials. But for me it is too slow.
Come on! Good luck!

Share this post


Link to post
Share on other sites
First off, thanks Zhao for your replies. They give me hope as well as helping me move forward.

I've decided to go with a 50/50 approach to this, that is OpenGL 2.0 but I'll be leaning heavily on GLSL. Using this approach I should be able to get on better terms with both GLSL and VAO, VBO and whatever other abbreviations I need to learn. A good approach? Thoughts?

I'm also thinking of buying some more books. I've got the "OpenGL Game Programming" and "More OpenGL game programming" books. The new books I'm thinking of buying is "Beginning C++ Game Programming" and the "Orange Book 3rd Edition".
The "beginning"-book should prove useful however I decide to move forwards, but how is the 3rd edition of the orange book? Is it close to what I'll be doing in 3.2 and 4.0? I have found some information on it - that it's written with 3.1 in mind. How much does 3.1, 3.2 and 4.0 differ from each other?
Mainly, will I have to buy the fourth edition of the orange book just to get started in the programmable pipeline?

Thanks for taking the time.
Marcus Axelsson

Share this post


Link to post
Share on other sites
Quote:
Original post by tre
First off, thanks Zhao for your replies. They give me hope as well as helping me move forward.

You are welcome. I am also happy to have a companion on the road to modern OpenGL.

Quote:

I've decided to go with a 50/50 approach to this, that is OpenGL 2.0 but I'll be leaning heavily on GLSL. Using this approach I should be able to get on better terms with both GLSL and VAO, VBO and whatever other abbreviations I need to learn. A good approach? Thoughts?


If you don't want to learn core profile purely, compatibility profile of OpenGL 3.2 or later should be good choice. It contains all the features of 2.0 and other more advanced functions.

Quote:

I'm also thinking of buying some more books. I've got the "OpenGL Game Programming" and "More OpenGL game programming" books. The new books I'm thinking of buying is "Beginning C++ Game Programming" and the "Orange Book 3rd Edition".
The "beginning"-book should prove useful however I decide to move forwards, but how is the 3rd edition of the orange book? Is it close to what I'll be doing in 3.2 and 4.0? I have found some information on it - that it's written with 3.1 in mind. How much does 3.1, 3.2 and 4.0 differ from each other?
Mainly, will I have to buy the fourth edition of the orange book just to get started in the programmable pipeline?


I am not familiar with the books of game programming. For the orange book, I think it is not very necessary when I looked through the first edition. It has too many pages. For programmers who are good at c or cplusplus, it is not hard to learn GLSL by reading the specification because the grammar is very similar. Maybe what we need is the application examples. If the third edition has good examples and application informations, it should be useful.

Good luck.

Share this post


Link to post
Share on other sites
Quote:
Original post by ZHAO Peng
If you don't want to learn core profile purely, compatibility profile of OpenGL 3.2 or later should be good choice. It contains all the features of 2.0 and other more advanced functions.


Didn't even think of the compability profile. Great idea.

And yeah, I agree. Modern application examples, thoroughly commented and documented would be the single best thing when it comes to learning GLSL. Well, save from school.

I want to lean the core profile, but I think I have too much other stuff to learn before I can dive into it. I'll be taking the long road instead, learning the things that are important for the core profile. I'll probably start up a couple of core profile projects just to see if I'm ready to move on yet or if I need to read even more.

I'll probably see if I can get my hands on the Orange Book since it at least covers GLSL which I could need. The C++ Game programming book seems like a great book for learning game logic and such. I'm on the hunt for more great books. I need more places to jump off from, so to speak.

Thanks again,
Marcus Axelsson

Share this post


Link to post
Share on other sites
Quote:
Original post by Bregma
One other suggestion is to learn OpenGL ES 2.0: it is very similar to OpenGL 3.0 core profile and there are plenty of resources out there for learning from.


I will probably stick with OpenGL 3.2 compability profile for now. But thanks for the tip. I'll keep it in mind.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

  • Forum Statistics

    • Total Topics
      628291
    • Total Posts
      2981862
  • Similar Content

    • By mellinoe
      Hi all,
      First time poster here, although I've been reading posts here for quite a while. This place has been invaluable for learning graphics programming -- thanks for a great resource!
      Right now, I'm working on a graphics abstraction layer for .NET which supports D3D11, Vulkan, and OpenGL at the moment. I have implemented most of my planned features already, and things are working well. Some remaining features that I am planning are Compute Shaders, and some flavor of read-write shader resources. At the moment, my shaders can just get simple read-only access to a uniform (or constant) buffer, a texture, or a sampler. Unfortunately, I'm having a tough time grasping the distinctions between all of the different kinds of read-write resources that are available. In D3D alone, there seem to be 5 or 6 different kinds of resources with similar but different characteristics. On top of that, I get the impression that some of them are more or less "obsoleted" by the newer kinds, and don't have much of a place in modern code. There seem to be a few pivots:
      The data source/destination (buffer or texture) Read-write or read-only Structured or unstructured (?) Ordered vs unordered (?) These are just my observations based on a lot of MSDN and OpenGL doc reading. For my library, I'm not interested in exposing every possibility to the user -- just trying to find a good "middle-ground" that can be represented cleanly across API's which is good enough for common scenarios.
      Can anyone give a sort of "overview" of the different options, and perhaps compare/contrast the concepts between Direct3D, OpenGL, and Vulkan? I'd also be very interested in hearing how other folks have abstracted these concepts in their libraries.
    • By aejt
      I recently started getting into graphics programming (2nd try, first try was many years ago) and I'm working on a 3d rendering engine which I hope to be able to make a 3D game with sooner or later. I have plenty of C++ experience, but not a lot when it comes to graphics, and while it's definitely going much better this time, I'm having trouble figuring out how assets are usually handled by engines.
      I'm not having trouble with handling the GPU resources, but more so with how the resources should be defined and used in the system (materials, models, etc).
      This is my plan now, I've implemented most of it except for the XML parts and factories and those are the ones I'm not sure of at all:
      I have these classes:
      For GPU resources:
      Geometry: holds and manages everything needed to render a geometry: VAO, VBO, EBO. Texture: holds and manages a texture which is loaded into the GPU. Shader: holds and manages a shader which is loaded into the GPU. For assets relying on GPU resources:
      Material: holds a shader resource, multiple texture resources, as well as uniform settings. Mesh: holds a geometry and a material. Model: holds multiple meshes, possibly in a tree structure to more easily support skinning later on? For handling GPU resources:
      ResourceCache<T>: T can be any resource loaded into the GPU. It owns these resources and only hands out handles to them on request (currently string identifiers are used when requesting handles, but all resources are stored in a vector and each handle only contains resource's index in that vector) Resource<T>: The handles given out from ResourceCache. The handles are reference counted and to get the underlying resource you simply deference like with pointers (*handle).  
      And my plan is to define everything into these XML documents to abstract away files:
      Resources.xml for ref-counted GPU resources (geometry, shaders, textures) Resources are assigned names/ids and resource files, and possibly some attributes (what vertex attributes does this geometry have? what vertex attributes does this shader expect? what uniforms does this shader use? and so on) Are reference counted using ResourceCache<T> Assets.xml for assets using the GPU resources (materials, meshes, models) Assets are not reference counted, but they hold handles to ref-counted resources. References the resources defined in Resources.xml by names/ids. The XMLs are loaded into some structure in memory which is then used for loading the resources/assets using factory classes:
      Factory classes for resources:
      For example, a texture factory could contain the texture definitions from the XML containing data about textures in the game, as well as a cache containing all loaded textures. This means it has mappings from each name/id to a file and when asked to load a texture with a name/id, it can look up its path and use a "BinaryLoader" to either load the file and create the resource directly, or asynchronously load the file's data into a queue which then can be read from later to create the resources synchronously in the GL context. These factories only return handles.
      Factory classes for assets:
      Much like for resources, these classes contain the definitions for the assets they can load. For example, with the definition the MaterialFactory will know which shader, textures and possibly uniform a certain material has, and with the help of TextureFactory and ShaderFactory, it can retrieve handles to the resources it needs (Shader + Textures), setup itself from XML data (uniform values), and return a created instance of requested material. These factories return actual instances, not handles (but the instances contain handles).
       
       
      Is this a good or commonly used approach? Is this going to bite me in the ass later on? Are there other more preferable approaches? Is this outside of the scope of a 3d renderer and should be on the engine side? I'd love to receive and kind of advice or suggestions!
      Thanks!
    • By nedondev
      I 'm learning how to create game by using opengl with c/c++ coding, so here is my fist game. In video description also have game contain in Dropbox. May be I will make it better in future.
      Thanks.
    • By Abecederia
      So I've recently started learning some GLSL and now I'm toying with a POM shader. I'm trying to optimize it and notice that it starts having issues at high texture sizes, especially with self-shadowing.
      Now I know POM is expensive either way, but would pulling the heightmap out of the normalmap alpha channel and in it's own 8bit texture make doing all those dozens of texture fetches more cheap? Or is everything in the cache aligned to 32bit anyway? I haven't implemented texture compression yet, I think that would help? But regardless, should there be a performance boost from decoupling the heightmap? I could also keep it in a lower resolution than the normalmap if that would improve performance.
      Any help is much appreciated, please keep in mind I'm somewhat of a newbie. Thanks!
    • By test opty
      Hi,
      I'm trying to learn OpenGL through a website and have proceeded until this page of it. The output is a simple triangle. The problem is the complexity.
      I have read that page several times and tried to analyse the code but I haven't understood the code properly and completely yet. This is the code:
       
      #include <glad/glad.h> #include <GLFW/glfw3.h> #include <C:\Users\Abbasi\Desktop\std_lib_facilities_4.h> using namespace std; //****************************************************************************** void framebuffer_size_callback(GLFWwindow* window, int width, int height); void processInput(GLFWwindow *window); // settings const unsigned int SCR_WIDTH = 800; const unsigned int SCR_HEIGHT = 600; const char *vertexShaderSource = "#version 330 core\n" "layout (location = 0) in vec3 aPos;\n" "void main()\n" "{\n" " gl_Position = vec4(aPos.x, aPos.y, aPos.z, 1.0);\n" "}\0"; const char *fragmentShaderSource = "#version 330 core\n" "out vec4 FragColor;\n" "void main()\n" "{\n" " FragColor = vec4(1.0f, 0.5f, 0.2f, 1.0f);\n" "}\n\0"; //******************************* int main() { // glfw: initialize and configure // ------------------------------ glfwInit(); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); // glfw window creation GLFWwindow* window = glfwCreateWindow(SCR_WIDTH, SCR_HEIGHT, "My First Triangle", nullptr, nullptr); if (window == nullptr) { cout << "Failed to create GLFW window" << endl; glfwTerminate(); return -1; } glfwMakeContextCurrent(window); glfwSetFramebufferSizeCallback(window, framebuffer_size_callback); // glad: load all OpenGL function pointers if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) { cout << "Failed to initialize GLAD" << endl; return -1; } // build and compile our shader program // vertex shader int vertexShader = glCreateShader(GL_VERTEX_SHADER); glShaderSource(vertexShader, 1, &vertexShaderSource, nullptr); glCompileShader(vertexShader); // check for shader compile errors int success; char infoLog[512]; glGetShaderiv(vertexShader, GL_COMPILE_STATUS, &success); if (!success) { glGetShaderInfoLog(vertexShader, 512, nullptr, infoLog); cout << "ERROR::SHADER::VERTEX::COMPILATION_FAILED\n" << infoLog << endl; } // fragment shader int fragmentShader = glCreateShader(GL_FRAGMENT_SHADER); glShaderSource(fragmentShader, 1, &fragmentShaderSource, nullptr); glCompileShader(fragmentShader); // check for shader compile errors glGetShaderiv(fragmentShader, GL_COMPILE_STATUS, &success); if (!success) { glGetShaderInfoLog(fragmentShader, 512, nullptr, infoLog); cout << "ERROR::SHADER::FRAGMENT::COMPILATION_FAILED\n" << infoLog << endl; } // link shaders int shaderProgram = glCreateProgram(); glAttachShader(shaderProgram, vertexShader); glAttachShader(shaderProgram, fragmentShader); glLinkProgram(shaderProgram); // check for linking errors glGetProgramiv(shaderProgram, GL_LINK_STATUS, &success); if (!success) { glGetProgramInfoLog(shaderProgram, 512, nullptr, infoLog); cout << "ERROR::SHADER::PROGRAM::LINKING_FAILED\n" << infoLog << endl; } glDeleteShader(vertexShader); glDeleteShader(fragmentShader); // set up vertex data (and buffer(s)) and configure vertex attributes float vertices[] = { -0.5f, -0.5f, 0.0f, // left 0.5f, -0.5f, 0.0f, // right 0.0f, 0.5f, 0.0f // top }; unsigned int VBO, VAO; glGenVertexArrays(1, &VAO); glGenBuffers(1, &VBO); // bind the Vertex Array Object first, then bind and set vertex buffer(s), //and then configure vertex attributes(s). glBindVertexArray(VAO); glBindBuffer(GL_ARRAY_BUFFER, VBO); glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW); glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)0); glEnableVertexAttribArray(0); // note that this is allowed, the call to glVertexAttribPointer registered VBO // as the vertex attribute's bound vertex buffer object so afterwards we can safely unbind glBindBuffer(GL_ARRAY_BUFFER, 0); // You can unbind the VAO afterwards so other VAO calls won't accidentally // modify this VAO, but this rarely happens. Modifying other // VAOs requires a call to glBindVertexArray anyways so we generally don't unbind // VAOs (nor VBOs) when it's not directly necessary. glBindVertexArray(0); // uncomment this call to draw in wireframe polygons. //glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); // render loop while (!glfwWindowShouldClose(window)) { // input // ----- processInput(window); // render // ------ glClearColor(0.2f, 0.3f, 0.3f, 1.0f); glClear(GL_COLOR_BUFFER_BIT); // draw our first triangle glUseProgram(shaderProgram); glBindVertexArray(VAO); // seeing as we only have a single VAO there's no need to // bind it every time, but we'll do so to keep things a bit more organized glDrawArrays(GL_TRIANGLES, 0, 3); // glBindVertexArray(0); // no need to unbind it every time // glfw: swap buffers and poll IO events (keys pressed/released, mouse moved etc.) glfwSwapBuffers(window); glfwPollEvents(); } // optional: de-allocate all resources once they've outlived their purpose: glDeleteVertexArrays(1, &VAO); glDeleteBuffers(1, &VBO); // glfw: terminate, clearing all previously allocated GLFW resources. glfwTerminate(); return 0; } //************************************************** // process all input: query GLFW whether relevant keys are pressed/released // this frame and react accordingly void processInput(GLFWwindow *window) { if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS) glfwSetWindowShouldClose(window, true); } //******************************************************************** // glfw: whenever the window size changed (by OS or user resize) this callback function executes void framebuffer_size_callback(GLFWwindow* window, int width, int height) { // make sure the viewport matches the new window dimensions; note that width and // height will be significantly larger than specified on retina displays. glViewport(0, 0, width, height); } As you see, about 200 lines of complicated code only for a simple triangle. 
      I don't know what parts are necessary for that output. And also, what the correct order of instructions for such an output or programs is, generally. That start point is too complex for a beginner of OpenGL like me and I don't know how to make the issue solved. What are your ideas please? What is the way to figure both the code and the whole program out correctly please?
      I wish I'd read a reference that would teach me OpenGL through a step-by-step method. 
  • Popular Now