Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 7 of 7

Thread: Multiple Textures loading problem

  1. #1
    Junior Member Newbie
    Join Date
    Sep 2011
    Posts
    5

    Multiple Textures loading problem

    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
    Code :
    void init()
    {
       //...
       glBindTexture(GL_TEXTURE_2D,myTex[0]);
       glTexImage2D(GL_TEXTURE_2D,0,GL_RGB,320,240,0,GL_RGB,GL_UNSIGNED_BYTE,img1->imageData);
       glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
       glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
     
       glBindTexture(GL_TEXTURE_2D,myTex[1]);
       glTexImage2D(GL_TEXTURE_2D,0,GL_RGB,320,240,0,GL_RGB,GL_UNSIGNED_BYTE,img2->imageData);
       glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
       glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
    }

    And after I load shader and use it(glUseProgram), I did something like
    Code :
    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!

  2. #2
    Senior Member OpenGL Guru
    Join Date
    May 2009
    Posts
    4,726

    Re: Multiple Textures loading problem

    can you tell me the process or how to deal with multiple textures?
    No, but I can point to my tutorials on the subject.

  3. #3
    Junior Member Newbie
    Join Date
    Oct 2011
    Posts
    2

    Re: Multiple Textures loading problem

    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!!!

  4. #4
    Advanced Member Frequent Contributor
    Join Date
    Apr 2010
    Location
    Germany
    Posts
    899

    Re: Multiple Textures loading problem

    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.

  5. #5
    Junior Member Newbie
    Join Date
    Oct 2011
    Posts
    2

    Re: Multiple Textures loading problem

    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...

  6. #6
    Senior Member OpenGL Guru
    Join Date
    May 2009
    Posts
    4,726

    Re: Multiple Textures loading problem

    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.

  7. #7
    Junior Member Newbie
    Join Date
    Sep 2011
    Posts
    5

    Re: Multiple Textures loading problem

    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/g...p_mapping.html

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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •