PDA

View Full Version : Crashes after 3rd glGenTextures



blood.angel
07-06-2003, 06:03 PM
Edit: Damn I meant its glTexImage2D in the subject.

I use 3 textures, all 512x512 RGB. Heres the code





GLvoid Opengl_Init(GLvoid)
{
glClearColor(1.0, 1.0, 1.0, 0.0);
glShadeModel(GL_FLAT);
glLineWidth(2.5);

glGenTextures(1, &StartupTex_Name);
glBindTexture(GL_TEXTURE_2D, StartupTex_Name);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 512, 512, 0, GL_RGB, GL_UNSIGNED_BYTE, startscreen);

glGenTextures(2, &MainmenuTex_Name);
glBindTexture(GL_TEXTURE_2D, MainmenuTex_Name);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 512, 512, 0, GL_RGB, GL_UNSIGNED_BYTE, mainmenu);

glGenTextures(3, &HelpTex_Name);
glBindTexture(GL_TEXTURE_2D, HelpTex_Name);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 512, 512, 0, GL_RGB, GL_UNSIGNED_BYTE, helpscreen);

}

Now it crashes on the last glTexImage2D (helpscreen) though I cant see how! The pointer helpscreen does contain the bitmap, I tested it by outputting them.
So can anyone help me?

[This message has been edited by blood.angel (edited 07-06-2003).]

miko
07-06-2003, 06:19 PM
do you have declarations like this:

GLuint startscreen;
GLuint mainmenu[2];
GLuint helpscreen[3];

because you are generating 1 texture name and storing it at address &startscreen, 2 names at &mainmenu and 3 names at &helpscreen... i think this is your mistake. if not, are startscreen, mainmenu and helpscreen arrays of GLuint? are you using drivers compatible with your os? are you sure you haven't corrupted something before? and so on....

[This message has been edited by miko (edited 07-06-2003).]

blood.angel
07-06-2003, 06:38 PM
I had it working when helpscreen, startscreen and mainmenu were arrays (eg GLubyte helpscreen[512][512][3]) but I thought that was not elegant and wanted to change them to GLubyte* calloc(512*512*3, sizeof(GLubyte)) allocated arrays instead.

Now its stumped me why it doesnt work. Ive forced the three to output what they store to .raw files before the above listed function and all three are perfect.

[This message has been edited by blood.angel (edited 07-06-2003).]

[This message has been edited by blood.angel (edited 07-06-2003).]

blood.angel
07-06-2003, 06:51 PM
Nevermind, I went back to test them again. Somehow the pics ares getting passed back from the reading function.

Stil, pretty weird why the error shows up here though.

blood.angel
07-06-2003, 07:03 PM
Ignore my last post.
IT DOES PASS the textures properly.
So Im back at still having the problem.

Can you pass (Glubyte *) arrays to glTexImage2D in the first place?

blood.angel
07-06-2003, 07:59 PM
Originally posted by miko:
do you have declarations like this:

GLuint startscreen;
GLuint mainmenu[2];
GLuint helpscreen[3];

because you are generating 1 texture name and storing it at address &startscreen, 2 names at &mainmenu and 3 names at &helpscreen... i think this is your mistake. if not, are startscreen, mainmenu and helpscreen arrays of GLuint? are you using drivers compatible with your os? are you sure you haven't corrupted something before? and so on....

[This message has been edited by miko (edited 07-06-2003).]

Thanks that was it!
From reading the red book I thought it meant you could state the number for its label. Its a bit vague explaining it IMO.

And its weird that it worked when the bitmaps were stored in 3D arrays.
Thanks again.

miko
07-06-2003, 09:25 PM
yup... next time i will not post at 3am http://www.opengl.org/discussion_boards/ubb/smile.gif i wanted this

// startup screen will be covered by single texture
GLuint StartupTex_Name;
// i will need 2 textures for mainmenu
GLuint MainmenuTex_Name[2];
// help will be veeeery big it will require 3 textures
GLuint HelpTex_Name[3];

but i assume this is not the think you wanted to do. i assume you wanted a single texture for startup, menu and help. you should solve it like this:

GLuint temp[3], StartupTex_Name,
MainmenuTex_Name,
HelpTex_Name;
unsigned char startscreen[512*512*3];
unsigned char mainmenu[512*512*3];
unsigned char helpscreen[512*512*3];

/*
fill startscreen, mainmenu and helpscreen with some data
*/

glGenTextures(3, &temp);
StartupTex_Name = temp[0];
MainmenuTex_Name = temp[1];
HelpTex_Name = temp[2];

glBindTexture(GL_TEXTURE_2D,StartupTex_Name);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 512, 512, 0, GL_RGB, GL_UNSIGNED_BYTE, startscreen);

glBindTexture(GL_TEXTURE_2D, MainmenuTex_Name);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 512, 512, 0, GL_RGB, GL_UNSIGNED_BYTE, mainmenu);

glBindTexture(GL_TEXTURE_2D, HelpTex_Name);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 512, 512, 0, GL_RGB, GL_UNSIGNED_BYTE, helpscreen);

or

glGenTextures(1, &StartupTex_Name);
glBindTexture(GL_TEXTURE_2D, StartupTex_Name);

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 512, 512, 0, GL_RGB, GL_UNSIGNED_BYTE, startscreen);

glGenTextures(1, &MainmenuTex_Name);
glBindTexture(GL_TEXTURE_2D, MainmenuTex_Name);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 512, 512, 0, GL_RGB, GL_UNSIGNED_BYTE, mainmenu);
glGenTextures(1, &HelpTex_Name);
glBindTexture(GL_TEXTURE_2D, HelpTex_Name);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 512, 512, 0, GL_RGB, GL_UNSIGNED_BYTE, helpscreen);

this is all what i tried to say but.... i screwed it up and i hope it's clear now http://www.opengl.org/discussion_boards/ubb/smile.gif

[This message has been edited by miko (edited 07-06-2003).]