I don’t typically use exclamation points in the titles of a post, but I’m pretty thrilled about this one. I have added a GUI to my engine and support in that GUI for buttons!
It took me a LONG time to figure out how to do this in OpenGL 3.3. I found many tutorials online about how to do it in old school OpenGL, and I guess that’s becoming a more accepted modern way, but I didn’t want to do that. I’m really working on learning the mindset behind OpenGL 3+, and so I spent two days, but I got it working.
The basic idea is that the two buttons you see are each textures. I used GL_TEXTURE_RECTANGLE inside the glBindTexture() function so that I would be drawing in absolute window coordinates, rather than the typical GL_TEXTURE_2D that would give me a range of -1 to 1 in the x and y coordinates. That is probably not necessary, but made understanding the issue better. I also grabbed a shader from Chapter 7 of the SuperBible that translates the x and y values into 2D coordinates. That may not sound too coherent, but I haven’t spent much time with shaders yet, so I’m a little hazy on them still.
Currently, if I click on the OpenGL logo it exits the program. The Settings button (which is a .tga file, not a font – no fonts implemented yet) does nothing. My next plan is to have the buttons respond when the mouse moves over it, and have a state for clicking and releasing buttons. I have other versions of that Settings .tga so I can swap textures out when an action takes place.
Perhaps when I get this down a little better I will put a tutorial on OpenGL 3+ GUI programming. I’m sure people are looking for something like that. There are libraries online that will create pretty sophisticated GUIs, but I’m thrilled to have finished the basics of my own.