vallentin / glText

Cross-platform single header text rendering library for OpenGL
zlib License
167 stars 16 forks source link

Only Text Showing #19

Open etr-dev opened 2 years ago

etr-dev commented 2 years ago

So a month ago I had a project where I rendered circles and lines then rendered text, all in a loop and it worked. Now when build the program it works for a few frames and then everything turns black except for the text. I am using the exact same code and libraries is there anything you can think of that would be causing this?

etr-dev commented 2 years ago

this is basically the code I am using image

dmoa commented 2 years ago

Getting the same issue

vallentin commented 2 years ago

I somehow missed this issue, until the latest notification. Sorry about that.

this is basically the code I am using

In this case, are you saying "basically", because it's a simplification, or are you actually using glBegin()? Because glBegin(), glVertex2f(), and glEnd() are part of the fixed function pipeline. Whereas glText requires using the programmable pipeline (at least OpenGL 3.3). So when you start trying to mix-and-match the fixed function pipeline and programmable pipeline, then stuff can get messy and behave weirdly.

it works for a few frames and then everything turns black except for the text

This is actually what confuses me the most. But if the two pipelines are being mixed, then that might explain it.

dmoa commented 2 years ago

By mixing do you mean start one before another one finishes?

I threw in the example code after my main draw functions but before gl's swap window function. I'm making sure to use my main gl_program (shader) before drawing my other code before, and also making sure to gl begin and end.

I understand why erobin's code may not have been working, because when drawing the shapes the next time the gl default program is not used. However, in my code, I am actually resetting it back.

Hope that makes sense?

dmoa commented 2 years ago

Update:

Sorry. Somehow, for 6 months, I had a working graphics pipeline and I had never linked my gl program. I made sure to glLinkProgram my other glProgram that I was using for other stuff, and so now glUseProgram is functioning correctly, and so now all works.

I noticed that gltEndDraw() is an empty function. Maybe it's worth adding glUseProgram(0)?

Let me know what you think.