Sign in to follow this  
lightbug

OpenGL Adding some GUI to OpenGL

Recommended Posts

Hi, I have a c++ 3d application based in opengl, sdl and bullets (physics), now i want to add a simple GUI (for example a buttom), the problem is that I don't know how to aproach this situation:

 

1 - Should I download a free gui library (c++) or made one with SDL?

 

2 - Should I add the GUI to my openGL window, or Add the openGL window to my GUI project?

 

 

Another thing, i have been seeing profesional software (for example : unreal engine 4 , unity , cubase , 3ds max , etc ... ) and all of those uses the same buttoms, the same menus, like the one windows have. My question--> what GUI use these software? 

 

In any case, I would appreciate a good book about this specific topic

 

 

Thanks and sorry for the english happy.png

Edited by lightbug

Share this post


Link to post
Share on other sites


where did you find this library? I was going to start with wxwidget, but now i got to see more of ImGUI

 

I had a 3D viewer and needed some simple controls to adjust values.  Not sure how I stumbled upon it.

Share this post


Link to post
Share on other sites

I was searching about this new concept (for me) of "immediate GUI". Some people says it's not good, some people says that this is "the" solution against the classic method (called "Retained GUI")

 

 

See this link : http://gamedev.stackexchange.com/questions/24103/immediate-gui-yae-or-nay

 

I really don't understand anything about GUI, so I will keep investigating

Share this post


Link to post
Share on other sites

My 2cents:

 

Immediate mode UIs are great to quickly get simple UIs up and running, specially if you are a lone programmer.

 

They are usually not so great when the UI complexity increases, and if you have designers in the team.

Share this post


Link to post
Share on other sites

This is the original video, which started the idea of IMGUI: http://mollyrocket.com/861

 

The Nay-sayers in that thread on stackexchange only seem hung up on some supposedly bad bundling of logic and rendering from their view of only knowing entangled RMGUI, cause one person answering called his example functions RenderButton and so on. They are not considering how these are implemented internally (probably only the clicking and positioning logic and then calling into some helper function to put drawitems into a renderqueue).

Both do basically the same drawing, but the RMGUI tries to only update changed parts.Then if some of your game objects changes you have to find the right GUI objects which you have to update, calculate update rectangles (and inevitably forget some) to invalidate some parts and hope that the listeners are set up to propagate all changes to the subobjects. RMGUI is an entangled mess of observer-objects which never know when/if their listener methods get called. If you are lucky all necessary draw methods get called timely and necessary parts of the screen updated, though nowadays all that complicated logic is useless, you redraw the whole game window for the game world and a few extra rectangles for the GUI wont kill a modern GPU. If you would just invalidate everything to ease your work an avalanche of update events would ripple back and forth through all GUI objects.

 

With IMGUI you most likely just do a little setup each frame, no update checking needed, just call the functions for the GUI elements you need and check for results returned from them. The generated drawitems can then be rendered however you like when you think its a good time (for example after rendering the game world). At least thats how I did it when I wrote a little IMGUI library for myself some time ago.

Share this post


Link to post
Share on other sites

I used to be a naysayer but now i am pro it after many discussions and looking at ocornuts implementation. I've converted my level editor to use my own IMGUI and there is nothing i've been unable to do with it. The original discussion never specified what happens behind the scenes but you can actually do a hell of a lot of "clever stuff". This mostly involves checking against the last frames state.

Share this post


Link to post
Share on other sites

I guess I'll put in a few more cents.

 

There is a lot of crappy RMGUIs out there, so I understand peoples frustration and need for something new.

But RMGUIs doesn't have to be that crappy, and IMGUIs, while solving some problems, overlook others.

 

There is no reason an RMGUI would have to have complicated observers or invalidation logic.

In the RMGUI I'm currently writing, if you change something, vertex buffers will be invalidated and rebuilt before the next draw.

If not, well, then we reuse the vertex buffers from last frame. (normal case for 99% of the frames)

Its not hard to know if a change will mean the vertex buffer it belongs to need update.

I don't care at all about regions. That was relevant in software rendering. Not so much in HW.

 

You do decouple creation from update/reaction, but you do it for a reason. It might not even be the same person defining it.

But even if it is, I like to have my widgets initial position and layout defined in an xml. Nice and neat and does not pollute my code with layout, and I can even edit it in runtime and reload it for quick ui tweaks. (or complete ui changes as long as the same actions exists)

 

Since I use lambdas, there is no problem with extreme decoupling, all my callbacks are defined right then and there, without unnecessary code.

Code should be concerned with actions, and never care about exact sizes or positions.

 

I don't want to rewrite logic for when and how to draw my buttons for every game I do.

It makes sense for game engines where you have complex needs for culling and handling of transparency and effects.

Not that much for UIs. 

To have higher class objects like views and popups make code brief and easy to read and modify the relevant parts of.

 

In my RMGUI, my UI is just another layer/pass in our graphics engine, I call "update" on it when it should be updated, and I call "draw" on it when it should be drawn. (so in a way IM, but on a higher level)

But I wouldn't want to call the equivalent of "draw" for each and every ui item each frame.

Not because I think it would be slow, but because I have no need to see and change that code, it can be completely generic for every UI.

 

Then of course, RMGUIs can be made overly complex... like most out there.

But it doesn't have to be like that, and I'm not sure IMGUIs really solve the problem, just moves the responsibilty

 

I don't want to discourage anyone from using an IMGUI though, I'm sure it can be perfect for a lot of projects.

Edited by Olof Hedman

Share this post


Link to post
Share on other sites

4. I don't see a reason why you couldn't load your xml file, then do IMGUI function calls based on that data.

 

5. Many RMGUI libs don't allow this.

 

6. Not sure what logic you fear of having to rewrite. You can easily have a library of precomposed functions for more complicated collections of widgets, which you can reuse in your next game.

 

7. You forgot that in your RMGUI you probably at some point feed the mouse events and other events into it (unless you let it take over the whole OS-event-loop). There it internally does lots of logic at that point. Thats where you could also call a function for the IMGUI to do its logic, and I don't see a problem with this, as it would be the same. Then later in your graphics engine you might do the same draw call.

Edited by wintertime

Share this post


Link to post
Share on other sites

I love the simplicity of IMGUIs. The extensibility of the Unity editor is a testament to that.

Need a custom editor window? Just write a few lines and you are done.

 

I couldn't imagine however implementing a complex game UI in that fashion with artist-crafted graphics, particle effects and other stuff.

Share this post


Link to post
Share on other sites

I guess I'll put in a few more cents.

 

There is a lot of crappy RMGUIs out there, so I understand peoples frustration and need for something new.

But RMGUIs doesn't have to be that crappy, and IMGUIs, while solving some problems, overlook others.

 

There is no reason an RMGUI would have to have complicated observers or invalidation logic.

In the RMGUI I'm currently writing, if you change something, vertex buffers will be invalidated and rebuilt before the next draw.

If not, well, then we reuse the vertex buffers from last frame. (normal case for 99% of the frames)

Its not hard to know if a change will mean the vertex buffer it belongs to need update.

I don't care at all about regions. That was relevant in software rendering. Not so much in HW.

 

You do decouple creation from update/reaction, but you do it for a reason. It might not even be the same person defining it.

But even if it is, I like to have my widgets initial position and layout defined in an xml. Nice and neat and does not pollute my code with layout, and I can even edit it in runtime and reload it for quick ui tweaks. (or complete ui changes as long as the same actions exists)

 

Since I use lambdas, there is no problem with extreme decoupling, all my callbacks are defined right then and there, without unnecessary code.

Code should be concerned with actions, and never care about exact sizes or positions.

 

I don't want to rewrite logic for when and how to draw my buttons for every game I do.

It makes sense for game engines where you have complex needs for culling and handling of transparency and effects.

Not that much for UIs. 

To have higher class objects like views and popups make code brief and easy to read and modify the relevant parts of.

 

In my RMGUI, my UI is just another layer/pass in our graphics engine, I call "update" on it when it should be updated, and I call "draw" on it when it should be drawn. (so in a way IM, but on a higher level)

But I wouldn't want to call the equivalent of "draw" for each and every ui item each frame.

Not because I think it would be slow, but because I have no need to see and change that code, it can be completely generic for every UI.

 

Then of course, RMGUIs can be made overly complex... like most out there.

But it doesn't have to be like that, and I'm not sure IMGUIs really solve the problem, just moves the responsibilty

 

I don't want to discourage anyone from using an IMGUI though, I'm sure it can be perfect for a lot of projects.

 

I'll treat each paragraph as a bullet point, all are addressed:

 

1) Every RMGUI i've worked on (in games or otherwise) get overly complicated. It's inevitable. The most important thing in game development is iteration time, IMGUI tend to be quicker for this.

 

2) You can rebuild vertex buffers on invalidation sure, you should do that whether RM or IM. The topic is really about "what it takes to get my game gui done", both options have similar optimisations. I'm not sure what you mean by regions.

 

3) There isn't much practical need to decouple display and logic. The games ive worked on have had heavy XML driven RMGUI front ends and the artists and designers barely go near it. A well thought out IMGUI interface can produce code that is as easy to read as XML. If artists want to change the size of something they'll just look for the name and numbers wherever theyre declared.

 

4) Not sure about this but in my experience having callbacks registered to events etc gets very messy and it hard to track what is listening to what.

 

5) Surely when you call draw on your RMGUI it is fast enough that it doesn't hiccup the framerate much right? If so then just do it every frame. My IMGUI (fairly optimised) runs at around 1ms on reasonable hardware for my level editor. This is content that is much more complicated than any typical game GUI with health bars and so on. Also you don't change that code, it's completely generic for all UIs made with any given IMGUI.

 

6) They do move the problem to a certain degree but the fundamental benefits are that its easy to write new client UI content and you don't have application state stored in your UI widgets because they don't exist.

 

It's perfect for realtime applications.

Share this post


Link to post
Share on other sites

4. I don't see a reason why you couldn't load your xml file, then do IMGUI function calls based on that data.

 

5. Many RMGUI libs don't allow this.

 

6. Not sure what logic you fear of having to rewrite. You can easily have a library of precomposed functions for more complicated collections of widgets, which you can reuse in your next game.

 

7. You forgot that in your RMGUI you probably at some point feed the mouse events and other events into it (unless you let it take over the whole OS-event-loop). There it internally does lots of logic at that point. Thats where you could also call a function for the IMGUI to do its logic, and I don't see a problem with this, as it would be the same. Then later in your graphics engine you might do the same draw call.

 

4. This _generally_ doesn't work because your logic is embedded. If you try too hard to declare logic in the XML you end up writing a bunch of rules that are interpretted and processed as actual logic when running your UI and so you may as well just do it in your GUI code. If your UI is command driven than you can do things like declared your menu buttons and specify a command that should be run when its clicked.

 

6. Yep this is basically the whole point.

Share this post


Link to post
Share on other sites
wow this post is growing stronger! thanks for all the answers. smile.png
 
I want to add an OS based GUI.
 
This is a new concept for me, every application runs a native User interface, that's why i said:
 

 

 

Another thing, i have been seeing profesional software (for example : unreal engine 4 , unity , cubase , 3ds max , etc ... ) and all of those uses the same buttoms, the same menus, like the one windows have. My question--> what GUI use these software? 

So, i'll go with wxwidget, which is crossplatform, but is RMGUI. I like the approach of IMGUI now

 

correct me if I'm wrong!

 

-> A win32 application used the win32 API to open a window

-> opengl by itself can't create a window

-> Only the OS can create a windows

 

So Can I made an entire editor with wxwidget (for example) and read inputs from sdl at the same time? Would there be a problem? (because wxwidget and SDL reads messages from the OS)

 

 

Again thanks!

 

Regards!

Edited by lightbug

Share this post


Link to post
Share on other sites

If you want OS native looked widgets and you want to be portable, you probably want QT or wxwidget.

You can mix SDL with those, thought there might be some hoops to jump through with handling events but nothing bad.

 

I totally understand the appeal to conform to a standard set of widgets. Now - QT is very powerful and featureful but it is an enormous thing (5 GB+ install). In my experience the problem with those big things is that it scares off lots of people in your team and you end up with 10% of the people ever looking at the project with the UI (if you have multiple projects running). It also make many things quite tedious to make IHMO. With a custom library like ImGui, many things are easier to make, and some are more tricky but you benefit from a less steep usage and learning curve, and you can create tools anytime more naturally without planning things out. wxwidget apparently is less unwieldly but I have never used it myself.

 

You may want to consider a few questions:

- is your app going to be short-lived or meant to be active for a very long time?

- is it small or big? simple or complex?

- will your app be used internally, for content-creators and technically minded people, or by your mother in law?

- will it have 10 users, 1000 users, one million user?

- will it have 1 developer, 10 developers, 100 developers? will they be a tight team or people coming and going?

 

Based on this you can better weight the trade-off of going for something more in the standard and "correct" spectrum or something more in the practical and "clunky" spectrum.

For the majority of app, having native OS widgets would ideally be better than non-native OS widgets. However you have to consider how it impact your development. Bad UI code can also become a bottleneck to your development and then you don't add feature xx or yy just become the UI is a pain to deal with. That happens everyday.

 

Recently I had to rewrite an old desktop-ey always-on app from a codebase that uses both Win32 and QT for standalone tools.

I bite the bullet and tried for the first time to use ImGui (which I wrote) instead of adopting QT.

The result is that I get an app that's not standard and a bit odd and has its limitation, but writing ui seems 100 times easier and everyone in the team can touch it.

Screenshot from that app: (not actually a fullscreen shot, that was a gif I made to demonstrate a feature)

 

1864a2c2-70df-11e5-9ce8-2acddc030f71.gif

Edited by ocornut

Share this post


Link to post
Share on other sites

that's a good looking gui

 

I will be the only user of my future tool app cool.png

 

I just want to add some properties panel and a menu, that's all for now, and of course a Opengl scene view (in qt this is called GL widget)

 

I was checking qt and something like this is what a want :
 
 https://www.youtube.com/watch?v=1nzHSkY4K18
 
the qt creator is great , not only for qt, also as an c++ IDE, right now I'm using MSVS 2013 community , and some qt libs, for now it works pretty well, and its so easy to code, although still I don't understand what is happening in the background. With my cpp + Glew I can specify where the main loop is going to be, now in qt i don't have any idea.
 
In the video above use repaingGL for this (i think)
 
How did you make you own imgui? is there any tutorial out there? i don't what nothing complicated, only the basics
 
regards
Edited by lightbug

Share this post


Link to post
Share on other sites

My imgui was linked above https://github.com/ocornut/imgui

There's a few links on that github page in the "References" paragraph, if you have the time to read them you'll understand lots of imgui principles better.

If you want to write your own, those links will help you. For basic things such as clickable button you can make you own in a matter of minutes. For something really fancy it's like any project - it can become an infinite time sink (I spent many months on mine).

 

One advantage of QT is that it comes with a million non-GUI things, it's almost an engine for non-gamey thing. So if you don't have much code already done you can use that and it can be very helpful as long as you are happy with the dependency. Wouldn't hurt giving it a go and pushing QT + QT Creator and see how you feel.

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  

  • Announcements

  • Forum Statistics

    • Total Topics
      628307
    • Total Posts
      2981972
  • 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