PDA

View Full Version : Multitexturing Problems?



Lurking
07-09-2002, 09:33 PM
Hello, i have been working on my texture class. i got it to display a single texture on a mesh. Now i want to enable multitexturing for my class. The problem is that i cant use the ARB functions that i am working with. I am quite new to this so if you could help me out that would be great. Here is some of my code:
====Header==================================
#include <stdio.h>
#include <stdlib.h>
#include "il/il.h"
#include "il/ilu.h"
#include "il/ilut.h"
#include <gl\gl.h>
#include <gl\glu.h>
#include "glext.h"

class CTexture{
ILuint uiImageName;
char *imageName;
int iMaxUnits;
int iImage;
bool bLoaded;
bool bMulti;

//start: only in init of class (sets up IL and sends IL to GL)
void InitAllIL(void);
void Load(void);
void BindIL(void);
void TexObject(void);
void BindGL(void);
void BuildMipmap(void);
//end: only in init of class (sets up IL and sends IL to GL)
void CheckMulti(void);
void ActivateMulti(void);
public:
PFNGLMULTITEXCOORD2FARBPROC glMultiTexCoord2fARB;
PFNGLACTIVETEXTUREARBPROC glActiveTextureARB;
PFNGLCLIENTACTIVETEXTUREARBPROC glClientActiveTextureARB;

void InitMulti(void);
void Filter(int iType);
void BindTexture(void); //use to bind right before texturemapping
void EnableFilter(int iType); //use defined to supply options
bool IsLoaded(void); //checks to see if the texture has been loaded?

CTexture(char *filename);
CTexture(char *filename, bool bMultiT); //questionable
~CTexture(){ ilDeleteImages(1,&uiImageName); }
};

====Source==================================

CTexture::CTexture(char *filename,bool bMultiT){
imageName = filename;
InitAllIL();
TexObject();
BindIL();
Load();
BindGL();
if(bMultiT == true){
CheckMulti();
if(bMulti == true){
InitMulti();
ActivateMulti();
}
}
}

///MultiTexturing (Note: i refer to multitexturing as multi)
//CheckMulti - sees if you have the option of using multitexturing
void CTexture::CheckMulti(void){
char *ext = (char*)glGetString(GL_EXTENSIONS);
char *arb = "GL_ARB_multitexture";
char *endString;
int space;

endString = ext + strlen(ext);
while(ext < endString){
space = strcspn(ext," ");
if((strlen(arb) == space) && (strncmp(arb,ext,space) == 0)){
bMulti = true;
//return true;
}
ext += (space + 1);
}
bMulti = false;
//return false;
}
//InitMult - sets up sys for multitexture
void CTexture::InitMulti(void){
glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, &iMaxUnits);
glMultiTexCoord2fARB = (PFNGLMULTITEXCOORD2FARBPROC) wglGetProcAddress ("glMultiTexCoord2fARB");
glClientActiveTextureARB = (PFNGLCLIENTACTIVETEXTUREARBPROC)wglGetProcAddress ("glClientActiveTextureARB");
glActiveTextureARB = (PFNGLACTIVETEXTUREARBPROC) wglGetProcAddress ("glActiveTextureARB");

}
//ActiveMulti - activates and binds to texture_0 or texture_1
void CTexture::ActivateMulti(void){
if((iArbNum % 2) == 0)
glActiveTextureARB(GL_TEXTURE0_ARB);
else
glActiveTextureARB(GL_TEXTURE1_ARB);
glEnable(GL_TEXTURE_2D);
BindGL();
iArbNum++;
}

====End=====================================
I know its alot of code for a post but if you could give it a look over and see whats wrong. when i try to texturemap the mesh w/ glMultiTexCoord2*() it says its a undeclared identifier. heres the error message:
error C2065: 'glMultiTexCoord2fARB' : undeclared identifier


P.S.
has anyone looked at the opengl 2.0 shader language compiler, and if so how is it?

- Lurking

Miguel_dup1
07-10-2002, 07:10 AM
Well, I see something...
You need to enable texturing for every call to glActiveTexture();

So

glAvtiveTexture( GL..0_ARB );
glEnable( GL_TEXTURE_2D );

glAvtiveTexture( GL..1_ARB );
glEnable( GL_TEXTURE_2D );

Something else is that you should check if the wglProcessAddress return the right thing...

So when you make the instance of your
glActiveTextureARB or whatever, initialize it to NULL and then after you run wglGetProcAddress("MY NAME"), you check for glActiveTextureARB.

so you could have

if( !glActiveTextureARB ) {return "DID NOT LOAD";}

If it did load properly, then you have some design issues where you are not initializing the functions before they are used or something else.

Another little piece of code to check for multitexturing is:

if( strstr( (char*)glGetString(GL_EXTENSIONS), "ARB_multitexture" ) == NULL )
{return false;}

Rather than the ugly loop. http://www.opengl.org/discussion_boards/ubb/smile.gif


http://www.opengl.org/discussion_boards/ubb/smile.gif

Email me if you have more problems and I can send you a simple working piece of code.

Later GL_GATORS .