PDA

View Full Version : Multiple Textures loading problem



chun0216
10-30-2011, 04:30 PM
Hello,
I have a problem of loading multiple textures and then use it in Shader(GLSL) and I am not sure what's wrong.
On my program, init function, I have something like


void init()
{
//...
glBindTexture(GL_TEXTURE_2D,myTex[0]);
glTexImage2D(GL_TEXTURE_2D,0,GL_RGB,320,240,0,GL_R GB,GL_UNSIGNED_BYTE,img1->imageData);
glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTE R,GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTE R,GL_LINEAR);

glBindTexture(GL_TEXTURE_2D,myTex[1]);
glTexImage2D(GL_TEXTURE_2D,0,GL_RGB,320,240,0,GL_R GB,GL_UNSIGNED_BYTE,img2->imageData);
glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTE R,GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTE R,GL_LINEAR);
}

And after I load shader and use it(glUseProgram), I did something like


void drawSquare()
{
//...
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D,myTex[0]);
GLint tex1Loc = glGetUniformLocation(program,"tex0");
glUniform1i(tex1Loc,0);

glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D,myTex[1]);
GLint tex2Loc = glGetUniformLocation(program,"tex1");
glUniform1i(tex2Loc,1);
}


And this did not work. It seems like one texture is empty (black) and another one is 2nd file. I know glTexImage2D lines are correct.
In fact, I am not sure how to deal with multiple textures and pass those to GLSL so can someone please help me? Like I don't know what ActiveTexture, GenTexture and others do exactly. I read API website but it still confuses me so can you tell me the process or how to deal with multiple textures?

Thank you so much for the help!

Alfonse Reinheart
10-30-2011, 05:14 PM
can you tell me the process or how to deal with multiple textures?

No, but I can point to my tutorials on the subject (http://www.arcsynthesis.org/gltut/Texturing/Tutorial%2014.html).

LEOdabao
10-31-2011, 02:00 AM
i also have some problems on my superbible!!!! at first,i use the RedBook to help me learn Opengl,but later,i found the examples on SuperBible are more interesting,and........the problem is :"LINK : warning LNK4098: defaultlib "LIBC" conflicts with use of other libs; use /NODEFAULTLIB:library
sphereworld.obj : error LNK2001: unresolved external symbol "void __cdecl gltDrawTorus(float,float,int,int)" (?gltDrawTorus@@YAXMMHH@Z)
sphereworld.obj : error LNK2001: unresolved external symbol "void __cdecl m3dRotationMatrix44(float * const,float,float,float,float)" (?m3dRotationMatrix44@@YAXQAMMMMM@Z)
freeglut_static.lib(freeglut_joystick.obj) : error LNK2001: unresolved external symbol __ftol2
freeglut_static.lib(freeglut_menu.obj) : error LNK2001: unresolved external symbol __ftol2
freeglut_static.lib(freeglut_font.obj) : error LNK2001: unresolved external symbol __ftol2
Debug/sphereworld.exe : fatal error LNK1120: 3 unresolved externals"
i'm crazy!!!

thokra
10-31-2011, 04:51 AM
LEOdabao: This has nothing to do with OpenGL whatsoever - and not even with the OPs question!

You need to tell the Visual C++ Linker to include the necessary libraries. IIRC, glt is the tools lib that comes with the SuperBible (i guess the m3d calls are also part of it). What freeglut has as dependencies I can't tell.

Please figure out how to properly use a C++ compiler.

LEOdabao
10-31-2011, 06:28 AM
but....actually,before i write some codes based on the ".h"(provided by superbible),everything is ok,and....i don't want to spend so many time figuring out how to properly use a C++compiler...

Alfonse Reinheart
10-31-2011, 10:24 AM
i don't want to spend so many time figuring out how to properly use a C++compiler...

Graphics programming is, by definition, programming. If you don't want to learn how to use the tools you need to know in order to program, then you don't want to learn graphics programming either.

3D graphics programming is not a task for a beginner-level programmer. You need to get some programming under your belt before you can tackle graphics. At the very least, if you're going to write OpenGL programs in C++, you should know how to work a C++ compiler and build environment.

chun0216
10-31-2011, 04:38 PM
FYI, I just figured out and fixed it...
In case anyone hits the same/similar problem, this is where I got a help from.
http://www.swiftless.com/tutorials/glsl/8_bump_mapping.html

Keep in mind that you do everything after you LOAD the shaders ;)