Hello,this question might be asked a million times already,so I would be happy even if someone provides a link to a post or document where i can read about a solution.
So my issue is:
With my basic knowledge I managed to do render text and with glfw to make it dynamic(basically when the user types OpenGL renders that letter).I exported from Blender a obj file that has all the letters and symbols I need. Then with an OBJ parser I went trough all of the lines and parsed all the vertex and index data as well as the object names(letter names).In the end the OBJ parser returns a dictionary with assigned VAO, indices,vertex count,bounding box for every letter.
then in my text class,in the draw method I loop trough a string and assign the relevant VAO for the specific letter and do some offsets so the next letter is rendered after the previous.
All good but I noticed that every instance drops the frame rate really hard.I use the ms per frame method from opengl-tutorial.com FPS tutorial.And at instance 100 it’s like 10ms per frame. I want to use the text for UI of course,but if 100 characters lower the performance so greatly it’s kind of not worth it.
here is the code of the draw method:
# for l in string: if l == r" " : x_pos += self.size_x_offset pass elif ' ' == l: y_pos -= self.size_y_offset x_pos = 25 increment = 0 pass elif ' ' == l: x_pos += self.size_x_offset*4 pass else: glUseProgram(self.shader2) glUniform3f(self.color_loc, *self.color_text) glUniformMatrix4fv(self.model_loc,1,GL_FALSE,self.modified_model) glUniformMatrix4fv(self.view_loc,1,GL_FALSE,self.view2) glUniformMatrix4fv(self.projection_loc,1,GL_FALSE,self.projection) glBindVertexArray(self.letters[l]) glDrawElements(GL_TRIANGLES, self.letters[l], GL_UNSIGNED_INT, self.letters[l]) glBindVertexArray(0) glUseProgram(0) x_pos += self.letters[l]*self.size increment += self.size*.05 #
No doubt I’m doing something wrong…but what is it?
I hope some of you guys can point me to my error and what I can do to fix it.
I doubt that OpenGL is unable to handle many instances.And it’s not my hardware…because Blender handles a lot of instances with no issue on my computer.