Hi,
I’ve some code loading a 2D texture as this :
void load_texture () {
GLfloat *params;
GLubyte *raw_bitmap;
//here is the problem
if (!file_name) Form1->file_name= “test.dcm”; //A: like this it works
//return; //B: black screen
else file_name= “test.dcm”; //B: doesn’t work even if I do this (so it’s not a path problem)
raw_bitmap = chargementImage(&Image_Width,&Image_Height); //file_name is globalif (raw_bitmap) {
if (allocated)
glDeleteTextures(1, texture_id);
else
allocated= true;
if (glIsTexture(texture_id[0])==GL_TRUE)
glDeleteTextures(1, texture_id);
glGenTextures (1, texture_id);
glBindTexture (GL_TEXTURE_2D, texture_id[0]);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, Image_Width, Image_Height, 0, GL_RGBA, GL_UNSIGNED_BYTE, raw_bitmap);
free (raw_bitmap);
}
else
allocated= false;
}
//------------------------------------------------------------------------------
void draw_texture (int number) {
float tempX= -0.5f, tempY=-0.5f;
int i;glEnable(GL_TEXTURE_2D);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glPushMatrix ();
glColor3f (1.0, 1.0, 1.0);
glBindTexture (GL_TEXTURE_2D, texture_id[number]);
glTranslatef(panX0+panX, panY0+panY, 0.);
glScalef(fact,fact,1.0);
glBegin (GL_QUADS);
glTexCoord2f(0.0f, 0.0f); glVertex3f(tempX, tempY, 0.);
glTexCoord2f(1.0f, 0.0f); glVertex3f(tempX+1.0F, tempY, 0.);
glTexCoord2f(1.0f, 1.0f); glVertex3f(tempX+1.0F, tempY+1.0F, 0.);
glTexCoord2f(0.0f, 1.0f); glVertex3f(tempX, tempY+1.0F, 0.);
glEnd ();
glColor3f (1.0, 0.0, 0.0);
glDisable(GL_TEXTURE_2D);
if (C1.finished) {
glBegin (GL_LINE_LOOP);
for (i=0; i<C1.nbr; ++i)
glVertex3f(C1.points[i].x,C1.points[i].y,0.);
glEnd ();
} else
for (i=1; i<C1.nbr; ++i) {
glBegin (GL_LINES);
glVertex3f(C1.points[i-1].x,C1.points[i-1].y,0.);
glVertex3f(C1.points[i].x,C1.points[i].y,0.);
glEnd();
}
glColor3f (0.0, 1.0, 0.0);
for (i=0; i<C1.nbr; ++i) {
glBegin (GL_QUADS);
glVertex3f(C1.points[i].x-0.004f,C1.points[i].y-0.004f,0.);
glVertex3f(C1.points[i].x-0.004f,C1.points[i].y+0.004f,0.);
glVertex3f(C1.points[i].x+0.004f,C1.points[i].y+0.004f,0.);
glVertex3f(C1.points[i].x+0.004f,C1.points[i].y-0.004f,0.);
glEnd ();
}
glPopMatrix ( );
}
(C++ Builder 5)
I’d like to load my texture or change it with the BCB File selection component but I can’t get it working!
Altough it works fine when I load the texture giving the name of the file manually on the first pass (cfr //here is the problem).
When I trace the error I see that glGenTexture doesn’t allow a name when I don’t do it manually at the first o_O
I resume the 2 ways and the weird problem :
A. Init the file_name var with the relative path of my image :
- init my prog
- load texture giving the “filename” manually (as none has been selected yet : initialisation)
- texture_id has 1 after glGenTexture (ok!)
- it works (image on the screen)
- when I try to select a file after it, it gives me a white screen (my white quad)
B. try to not do it with the initialisation but when i select an image :
- init my prog (file_name is NULL)
- loading the texture returns NULL as there are no file_name given (this time)
3. texture_id has 0 after glGenTexture (normal)
4. my screen is black (it would be a white quad o_O I don’t understand this)
5. try to select an image
6. texture_id has 0 after glGenTexture (weird problem as nothing change but the time when I set file_name - even if i put it manually at this moment so it’s not a path problem)
7. My screen is white (my quad but no pic on it)
Anyone has an idea? You’re welcome…
Thanks,
acerb
[This message has been edited by acerb (edited 03-19-2003).]