Skip to main content
GameDev.net gamedev.net
🔒 Locked

Question regarding the tutorial..

Started by anonymouse3823 Dec 28, 2003 at 2:18 AM 4 replies 1.2k views
Original Post
anonymouse3823
anonymouse3823
Hlo! Actually I have 2 questions: one regarding the tutorials and one is regarding the "Red Book" First: Umm.. It''s about the tutorial number 7 wherein I load 1 picture on a cube and it rotates with keyboard controls and I can also change the filter of the texture. I''m just wandering, can I load different pictures on each side of the cube and still change the filter of the texture with keyboard controls. I can''t seem to do it because i tried to load 6 different pictures but the thing that it does is that it loads only the last picture on all sides of the cube. Second: Umm.. regarding the book. I tried to compile the programs there from Chapter 1 but this is the error that I always get: Compiling... Body.cpp c:\program files\microsoft visual studio\vc98\include\gl\gl.h(1152) : error C2144: syntax error : missing '';'' before type ''void'' c:\program files\microsoft visual studio\vc98\include\gl\gl.h(1152) : error C2501: ''WINGDIAPI'' : missing storage-class or type specifiers c:\program files\microsoft visual studio\vc98\include\gl\gl.h(1152) : fatal error C1004: unexpected end of file found Error executing cl.exe. Body.obj - 3 error(s), 0 warning(s) What does this mean? But I can still compile programs that I got from the tutorials. Thank you in advance!!
RipTorn
RipTorn
for your second question it probably needs to have #include <windows.h> added before the #include <GL/gl.h>

for the first, the older Nehe base code is dodgy for loading multiple textures.

You might have noticed the whole unsigned int (GLuint I think) textures[someSize]; array, or whatever he calls them.

The thing is, when you load/generate a texture, openGL assigns it a number. 0 is no texture, 1 is the first you load, etc. It returns an unsigned int. Hence the GLuints... Thats also why glBindTexture() takes in an unsigned int. I can bet that your LoadTexture function isn't setting up these variables correctly.

The best way to have it setup is have LoadTexture() return an unsigned int.. so you can do something like:

unsigned int myBigRedTexture = LoadTexture("BigRedTexture.psd");

then just:

glBindTexture(myBigRedTexture);

and glDeleteTextures, etc.

Someone posted a LoadTexture function that did this a while ago.. I forget who it was, you might want to search or someone might be kind and help you out.

okely.

[edit]

also remember you can't change texture in between glBegin and glEnd.
Also, If my memory is correct I think Nehe reloaded each texture for each filtering type, you don't have to do this.. just bind the texture and call the appropriate glTexParameteri functions.

[edited by - RipTorn on December 28, 2003 5:12:36 AM]
anonymouse3823
anonymouse3823
Thanks riptorn! But I have a new problem here. I placed the "#include" before the other header files but this is now the new error that comes out:

Compiling...
Body.cpp
c:\MY DOCUMENTS\VISUAL C++\TheRedBook\Chp01\Body.cpp(4) : fatal error C1083: Cannot open include file: ''GL/glx.h'': No such file or directory
Error executing cl.exe.

Body.obj - 1 error(s), 0 warning(s)

but when I try to remove that header file. Something in my computer hangs. I think it''s "CI" that''s not responding when I try to compile it again. What do you think is causing this? Thanks again!!
anonymouse3823
anonymouse3823
Umm.. Why is it that upon changing the header files from glx.h to glaux.h, my compiler always hangs. Is there a chance that my system cannot handle it? By the way, my system is just P166MMX w/ 128mb ram and 40HDD.

RipTorn: new question about the tutorial.. I''ve manage to do the multiple textures on a cube and the filters can still be changed upon keyboard input in a long way.. so I decided to try to put the repeating steps w/in a function. When there is only one picture to load there''s no problem but if there are more than one picture my program crashes with this error:

TEXTURE4 caused an invalid page fault in
module TEXTURE4.EXE at 017f:00401197.
Registers:
EAX=cccccccc CS=017f EIP=00401197 EFLGS=00010246
EBX=00560000 SS=0187 ESP=0066fad4 EBP=0066fb20
ECX=00000001 DS=0187 ESI=0066fad4 FS=749f
EDX=0066fb84 ES=0187 EDI=0066fb20 GS=0000
Bytes at CS:EIP:
8b 48 08 51 68 01 14 00 00 68 07 19 00 00 6a 00
Stack dump:
0066fba0 0066fbfc 00560000 cccccccc cccccccc cccccccc cccccccc cccccccc cccccccc cccccccc cccccccc cccccccc cccccccc cccccccc cccccccc cccccccc


Here''s my code:

void PictureFilter(int *Status, AUX_RGBImageRec *TextureImage[], int j)
{
*Status=TRUE;
glGenTextures(3, &texture[j][0]);


glBindTexture(GL_TEXTURE_2D, texture[j][0]);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[j]->sizeX, TextureImage[j]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[j]->data);


glBindTexture(GL_TEXTURE_2D, texture[j][1]);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[j]->sizeX, TextureImage[j]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[j]->data);


glBindTexture(GL_TEXTURE_2D, texture[j][2]);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST);
gluBuild2DMipmaps(GL_TEXTURE_2D, 3, TextureImage[j]->sizeX, TextureImage[j]->sizeY, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[j]->data);

if (TextureImage[j])
{
if (TextureImage[j]->data)
{
free(TextureImage[j]->data);
}
free (TextureImage[j]);
}
}

int LoadGLTextures()
{
int Status=FALSE;
int j=0;
AUX_RGBImageRec *TextureImage[6];
memset(TextureImage,0,sizeof(void *)*1);

if (TextureImage[0]=LoadBMP("mima1.bmp"))
{
j=0;
PictureFilter(&Status, &TextureImage[j], j);
}

if (TextureImage[1]=LoadBMP("mima2.bmp"))
{
j=1;
PictureFilter(&Status, &TextureImage[j], j);
}

if (TextureImage[2]=LoadBMP("mima3.bmp"))
{
j=2;
PictureFilter(&Status, &TextureImage[j], j);
}

if (TextureImage[3]=LoadBMP("mima4.bmp"))
{
j=3;
PictureFilter(&Status, &TextureImage[j], j);
}

if (TextureImage[4]=LoadBMP("Shinchan.bmp"))
{
j=4;
PictureFilter(&Status, &TextureImage[j], j);
}

if (TextureImage[5]=LoadBMP("Squirrel.bmp"))
{
j=5;
PictureFilter(&Status, &TextureImage[j], j);
}
return Status;
}

I tried to debug my program and it seems the problem comes from this line:
glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[j]->sizeX, TextureImage[j]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[j]->data);

What seems to be the problem? Thank you again in advance!!
Enigma
Enigma
The problem lies with these two lines:
...
PictureFilter(&Status, &TextureImage[j], j);
...
glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[j]->sizeX, TextureImage[j]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[j]->data);
...

You pass the address of the TextureImage you want to the function, effectively passing an array where the first element is the required image, and then you go and use the old index into the new array. either just pass the full array of textures each time you call PictureFilter:
PictureFilter(&Status, TextureImage, j); 

or make PictureFilter take a single TextureImage:
void PictureFilter(int *Status, AUX_RGBImageRec &TextureImage, int j){
*Status=TRUE;
glGenTextures(3, &texture[j][0]);

glBindTexture(GL_TEXTURE_2D, texture[j][0]);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage.sizeX, TextureImage.sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage.data);

glBindTexture(GL_TEXTURE_2D, texture[j][1]);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage.sizeX, TextureImage.sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage.data);

glBindTexture(GL_TEXTURE_2D, texture[j][2]);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST);
gluBuild2DMipmaps(GL_TEXTURE_2D, 3, TextureImage.sizeX, TextureImage.sizeY, GL_RGB, GL_UNSIGNED_BYTE, TextureImage.data);

if (TextureImage.data){
free(TextureImage.data);
}
free(&TextureImage);
}
...
PictureFilter(&Status, TextureImage[j], j);


Enigma

EDIT: correcting memory cleanup

[edited by - Enigma on December 31, 2003 4:59:49 PM]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.