PDA

View Full Version : glubuild2dmipmaps segfaults



TheSpider
02-14-2005, 02:13 AM
Hello, i have been porting a small graphics app which i drew in windows to linux and have come across problems when loading textures, the following code causes a segfault when it gets to the mipmaps call (im using a 4 channel image)

I have used GDB to step through the code but cant see anything wrong with the parameters, what have i done wrong here?

The width and height parameters are correct and the memory is allocated and read correctly.


void CTexData::LoadFile()
{

SDDBData TextureImage;
// Load The Bitmap
TextureImage=LoadImage(strFileName.c_str());

cerr << "Loaded image\n";
//Create Texture
glGenTextures(1, &amp;uiTexture);

// Create Nearest mipmapped Texture
glBindTexture(GL_TEXTURE_2D, uiTexture);

glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTE R,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTE R,GL_LINEAR_MIPMAP_LINEAR);

glPushAttrib(GL_CURRENT_BIT);

if(!TextureImage.cpData)
{
cerr << strFileName.c_str() << "\n";
}



//These functions are segfaulting!! Pointer is not null!
if(TextureImage.cChannels ==3) //RGB
{
gluBuild2DMipmaps(GL_TEXTURE_2D, 3, TextureImage.uiWidth,
TextureImage.uiHeight, GL_RGB,
GL_UNSIGNED_BYTE, TextureImage.cpData);
}

if(TextureImage.cChannels ==4) //RGBA
{
gluBuild2DMipmaps(GL_TEXTURE_2D, 4, TextureImage.uiWidth,
TextureImage.uiHeight, GL_RGBA,
GL_UNSIGNED_BYTE, TextureImage.cpData);
}

glPopAttrib();

// Free The Texture Image Memory
delete[] TextureImage.cpData;
cerr << "openGL image Funcs called\n";

}the backtrace from GDB is this:

#0 0x40370121 in __strtod_internal () from /lib/tls/libc.so.6
#1 0x402357c6 in __gluTessErrorString ()
from /usr/X11R6/lib/libGLU.so.1if it is important i am using the ATI drivers not Mesa or NVidia

TheSpider
02-15-2005, 09:35 PM
Never mind, solved it. For those who may have a similar problem make sure that you have finished intialising your openGL stuff first

i moved my load textures routine from before the following code to the end and that solved the problem


//Activate window
glXMakeCurrent(dpy, glwin, cx);

XMapWindow(dpy, glwin);
XIfEvent(dpy, &amp;event, WaitForMapNotify, (char *)glwin);

InitGL();
Resize(WINDOW_WIDTH, WINDOW_HEIGHT);

02-17-2005, 10:54 AM
You can usually call your texture loading function "after" you make the DC cuurent with the RC...which is aftrer you create your pixelformatdescriptor.. Even before your Init function.

But, maybe Lynux a little different.