View Full Version : GLFW texturing
12-21-2007, 11:53 AM
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?
12-21-2007, 01:16 PM
1) As written in the (excellent) glfw documentation, this command replaces glTexImage2d. so, as with opengl, bind a texture name to be able to recall it later.
glGenTextures(1, &texture1);// Create The Texture name
// glfwload texture
// gltexparameters etc
// repeat for more textures
then simply bind the correct texture before drawing, and you are set.
2) display list should work, if not you are doing something wrong. put some glGetError() everywhere, use a debugger, read the documentation :
and if you still have problems, post some code.
12-21-2007, 01:30 PM
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.
12-28-2007, 11:07 AM
Ok, I know I'm doing something stupid now, as I had it working a few days ago, but I just cannot see what I'm doing wrong all of a sudden.
GLuint tempInt, tempIntTwo;
and then I do, glBindTexture(GL_TEXTURE_2D, tempInt);
To bind the "crate.tga" texture, and then I draw a quad.
However, I don't see the crate texture instead I see the OGL.tga texture, it appears to overwrite the first one, why is this?
12-28-2007, 11:17 AM
Probably a stupid question... but you did put the glBindTexture(GL_TEXTURE_2D, tempInt) call outside of the glBegin(GL_QUADS)/glEnd() scope, right?
12-28-2007, 03:52 PM
that's not a stupid question because that is exactly what I was doing.
12-28-2007, 05:03 PM
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.
To test it I printed it to the screen and the first texture looks corretct:
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.
12-29-2007, 07:10 AM
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.
Powered by vBulletin® Version 4.2.2 Copyright © 2014 vBulletin Solutions, Inc. All rights reserved.