Archived

This topic is now archived and is closed to further replies.

ShDragon

Crashing when creating textures.

Recommended Posts

ShDragon    122
and I''m stumped as to why. Here''s an abbreviated version of my main() func:
int main( int argc, char* argv[] )
{
  // SDL setup stuff here...


  // Set up OpenGL

  float ratio = (float) width / (float) height;
  glShadeModel( GL_SMOOTH );
  glCullFace( GL_BACK );
  glFrontFace( GL_CCW );
  glEnable( GL_CULL_FACE );
  glEnable( GL_TEXTURE_2D );
  glClearColor( 0, 0, 0, 0 );
  glViewport( 0, 0, width, height );
  glMatrixMode( GL_PROJECTION );
  glLoadIdentity( );
  gluPerspective( 60.0, ratio, 1.0, 1024.0 );

  // initialize the game board

  GameBoard.init( 1 );	

  // message loop here..

}
And here''s GameBoard::init()
void ShuffleBoard::init( int diff )
{
  // set difficully

  if( diff < 0 ) diff = 0;
  if( diff > 4 ) diff = 4;
  difficulty = diff;
	
  // Generate all texture objects

  glGenTextures(10, textureNames);

  int width, height;

  glBindTexture(GL_TEXTURE_2D, textureNames[0]);
  blockTex[0] = LoadBitmapFile("box1.bmp", &width, &height);
  if( blockTex[0] == NULL )
    printf("Something happened in LoadBitmapFile!\n");
  else
  {
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); // linear magnification

    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); // linear minification

    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, blockTex[0]);
  }
  return;
}
I''ve left out and abbreviated some of the stuff that I think is unimportant. I can post full versions if this turns out to be not enough though. The code is crashing on glTexImage2D(). I''ve confirmed that LoadBitmapFile() is doing its job correctly, width and height are both set to 128 (the correct numbers for the bitmap) by loadBitmapFile() and blockTex[0] is a pointer to an unsigned char array of size 128*128 that contains all the bitmap data. So everything -looks- good to me. Any ideas of what I a) forgot to do, or b) am doing wrong?

Share this post


Link to post
Share on other sites
quote:
Original post by exa_einstein
possible problem with LoadBitmapFile, can you post some code?

idea2 : memory must have size (128*128)*3 !!!! you are loading RGB!



It is a bmp so he is loading BGR and not RGB but yes it should be 128*128*3.

"C lets you shoot yourself in the foot rather easily. C++ allows you to reuse the bullet!"

Share this post


Link to post
Share on other sites
ShDragon    122
Well.... duh.. It -would- help if I allocated enough memory. I was allocating width*height, not width*height*3.

Its amazing how well programs work when you allocate enough memory.

Thanks for helping point out the obvious. Would have taken me a long time to find that.

Share this post


Link to post
Share on other sites
exa_einstein    122
quote:
Original post by ShlomiSteinberg
quote:
Original post by exa_einstein
possible problem with LoadBitmapFile, can you post some code?

idea2 : memory must have size (128*128)*3 !!!! you are loading RGB!



It is a bmp so he is loading BGR and not RGB but yes it should be 128*128*3.

"C lets you shoot yourself in the foot rather easily. C++ allows you to reuse the bullet!"


WHY BGR? i load some_image.bmp normally (=without swapping) and have no problems. Possible that i am from that fuckin'' Czech Rep... everything''s reversed here....

Share this post


Link to post
Share on other sites
marijnh    182
Nah ShlomiSteinberg is confused by the (confusing) way palettes are stored in bmp''s. Palettes do contain BGR (plus a reserved byte) colors, while normal 24-bit data is stored in RGB order.

Marijn

Share this post


Link to post
Share on other sites
quote:
Original post by marijnh
Nah ShlomiSteinberg is confused by the (confusing) way palettes are stored in bmp''s. Palettes do contain BGR (plus a reserved byte) colors, while normal 24-bit data is stored in RGB order.

Marijn




What normal 24-bit data?! You can store anything in anyway you want. Normal 24-bit bmps, that I create using Photoshop 7.0, are BGR. I don''t use swapping either but I use GL_BGR_EXT instead of GL_RGB.

"C lets you shoot yourself in the foot rather easily. C++ allows you to reuse the bullet!"

Share this post


Link to post
Share on other sites
exa_einstein    122
oh my god what are you using? GL_BGR_EXT is only an extension, i have a card which doesn't know anything about GL_XXX_EXT. it is s3trio3D

once more: WHAT ARE YOU USING?! i know only GIMP and PaintShopPro4.12. Nothing more in texture world. that badobebhodozhob cannot survive...

[edited by - exa_einstein on August 12, 2003 7:10:13 AM]

Share this post


Link to post
Share on other sites
quote:
Original post by exa_einstein
oh my god what are you using? GL_BGR_EXT is only an extension, i have a card which doesn't know anything about GL_XXX_EXT. it is s3trio3D

once more: WHAT ARE YOU USING?! i know only GIMP and PaintShopPro4.12. Nothing more in texture world. that badobebhodozhob cannot survive...

[edited by - exa_einstein on August 12, 2003 7:10:13 AM]



My OpenGL application is designed only for hardware that support pixel shaders and vertex shaders so s3trio3D (what the hell is that?!) isn't supported . And yes I use the GL_EXT_bgra extension, I also use about 15 other extensions so?
And yes Photoshop, the best thing (I think so) for textures. look here


Edit: Stupid link!!!

"C lets you shoot yourself in the foot rather easily. C++ allows you to reuse the bullet!"

[edited by - shlomisteinberg on August 12, 2003 7:30:50 AM]

Share this post


Link to post
Share on other sites
exa_einstein    122
oh my god he doesn''t know what is my S3 Trio3D with GREAT 2048KB of ULTRA FAST VIDEO MEMORY (80MB/S) and COOL support for all new drivers and APIs: dos4gw, OGL, Glide,...

Share this post


Link to post
Share on other sites
quote:
Original post by exa_einstein
oh my god he doesn''t know what is my S3 Trio3D with GREAT 2048KB of ULTRA FAST VIDEO MEMORY (80MB/S) and COOL support for all new drivers and APIs: dos4gw, OGL, Glide,...



OMG LOL!!!

PS: I think it is time for a new video card

"C lets you shoot yourself in the foot rather easily. C++ allows you to reuse the bullet!"

Share this post


Link to post
Share on other sites
exa_einstein    122
if I have ZILOGz80 i cannot have anything better than my S3...god be peaceful...

...stop these smiles
I will send saddam to destroy them all...
<:-=|

[edited by - exa_einstein on August 13, 2003 1:22:09 AM]

Share this post


Link to post
Share on other sites