I’m new to OpenGL and I managed to load a simple .tga image and apply it as a texture to a plain.
However I’m still just a little confused, because the way I do it is by calling the function glfwLoadTexture2D every loop to apply it, but I’m thinking that that’s not very efficient to load the texture every loop.
So I tried to put the drawing and texturing commands in a display list and simply using glCallList every loop instead, but this gives me a runtime error.
What’s the best method of applying textures with GLFW?
glGenTextures(1, &texture1);// Create The Texture name
glBindTexture(GL_TEXTURE_2D, texture1);
// glfwload texture
// gltexparameters etc
// repeat for more textures
then simply bind the correct texture before drawing, and you are set.
display list should work, if not you are doing something wrong. put some glGetError() everywhere, use a debugger, read the documentation : http://www.opengl.org/sdk/docs/man/
and if you still have problems, post some code.
I think your mistake is not understanding that you don’t have to have to load a texture every time. The image is then “bound” to the appropriate texture object. You can select a texture object to be current with BindTexture operation. Basically, you load the textures on a preprocess step and use the data for rendering.
actually that wasn’t the problem…
But I know what was.
I’m making a loader, and it reads the texture filenames from a file and I’m using vectors to hold the strings, so the first texture is read in by using vectorName.push_back(char);
so then I pass the string into my texture loading function with &texture[0].
To test it I printed it to the screen and the first texture looks corretct:
“crate.tga”
the next one is all messed up:
“OGL.tga(and a bunch of junk after it)”
I’ve been trying vectorName.clear(); vectorName.resize(0); and some others but nothing is working please help.
Why don’t you use the c++ string class? Most likely the problem is that your self implemented strings aren’t null-terminated (’\0’) so the function does not know where the string ends.