Problem drawing OpenGL lines in GLFW window


#1

Hello All,

I’ve been able to use GLFW to create a window and accept user keyboard/mouse input. I was even able to load a texture from an image (with SOIL) and display that in the GLFW window. However, I’m having problems drawing simple lines with OpenGL. I’m compiling with mingw64 on Windows 7. I’ve created a pretty simple test program that I believe should show a few lines on screen, but all it shows is just a black background. I only have a relatively simple understanding of OpenGL, so I may be missing some small, but obviously important!, detail. Can anyone look at the code that I’ve pasted to pastebin and help me figure out what I might be doing wrong, or what settings I might be missing. The pastebin link is https://pastebin.com/YTt4DUWE

To give a little more info on the goal of the program, I’m trying to create a program that will display a 2D map in an orthographic projection. I plan on using keyboard and mouse callbacks to allow the user to pan around and zoom in and out of the map. I’ll be drawing the map with simple lines so that zooming in/out will always look good. I’ve cobbled the main program together from various sources online, which has possibly led to my missing some details. Thanks in advance for any help anyone can provide.


#2

I haven’t gone through your code in detail, but a quick scan shows you lack a projection matrix.

For 2D work, you should use an orthographic projection matrix. You need to set this to identity and then use glOrtho.

If you want to use a simpler 2D API than raw OpenGL, take a look at custom rendering with dear imgui or NanoVG. NanoVG is slower than dear imgui but the custom rendering is more powerful.