unsigned int CreateTexture(unsigned char *img, short SizeX, short SizeY, char mipmap, char Alpha)
{
unsigned int tID;
glGenTextures(1,&tID);
glBindTexture(GL_TEXTURE_2D,tID);
if (mipmap)
{
if (Alpha)
gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA, SizeX, SizeY, GL_RGBA, GL_UNSIGNED_BYTE, img);
else
gluBuild2DMipmaps(GL_TEXTURE_2D, 3, SizeX, SizeY, GL_RGB, GL_UNSIGNED_BYTE, img);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR_MIPMAP_NEAREST);
}
else
{
if (Alpha)
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, SizeX, SizeY, 0, GL_RGBA, GL_UNSIGNED_BYTE, img);
else
glTexImage2D(GL_TEXTURE_2D, 0, 3, SizeX, SizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, img);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
}
glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MODULATE);
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
return tID;
}
Any help would be GREATLY appreciated. By the way, just wanted to mention again, this works perfectly fine under windows, and the only difference in code is the window setup code.
(Also, if you need more code, let me know).
[edited by - Ready4Dis on September 25, 2003 11:12:28 AM]
Problems with textures...
Ok, i've got the basis of a game engine started (was trying to convert my old base, but figured a re-write was in order), and it compiles and runs in both Windows and Linux (mandrake 9.1 i'm using, but that shouldnt' matter). It runs flawlessly under windows, but has problems under linux. It seems when I try to load a second texture up, it seg faults on me. I can't seem to figure out why. If I only load up one texture, no problems, but once I load that second texture, it seg faults... it was seg faulting on the glBindTexture call, but after moving a few glTexParameterX things around, it now seg faults on the glTexImage2D call... code as below:
find out where it segfaults.
gdb myprogram
run
--SEGFAULTS--
backtrace
maybe also get the exact line at which it happens. I don''t remember how exactly off the top of my head.
gdb myprogram
run
--SEGFAULTS--
backtrace
maybe also get the exact line at which it happens. I don''t remember how exactly off the top of my head.
Ok, just ran it on my linux box with that:
Program received signal SIGFPE, Arithmetic Expression
Switching to thread 16384 (LWP 9150)
0x4050ed57 in __driUtilCreateScreen ()
from /usr/X11R6/lib/modules/dri/r200_dri.so
Happens right at the glTexImage2D call on the second time.
--- Edit ---
Alright, a bit more playing around... and I found out, that if I reverse the calls, it doesn't seg-fault (reverse the order in which the two textures get loaded), but I didn't have much time to test out to see if it looked correct (something still seems wrong that way).
[edited by - Ready4Dis on September 25, 2003 5:25:06 PM]
Program received signal SIGFPE, Arithmetic Expression
Switching to thread 16384 (LWP 9150)
0x4050ed57 in __driUtilCreateScreen ()
from /usr/X11R6/lib/modules/dri/r200_dri.so
Happens right at the glTexImage2D call on the second time.
--- Edit ---
Alright, a bit more playing around... and I found out, that if I reverse the calls, it doesn't seg-fault (reverse the order in which the two textures get loaded), but I didn't have much time to test out to see if it looked correct (something still seems wrong that way).
[edited by - Ready4Dis on September 25, 2003 5:25:06 PM]
Ok, well it appears when I reverse the order the textures load, it works fine... but if I put them back to normal, it keeps crashing. I just don''t get it... any ideas guys? This is a VERY simple test program for now, I''m affraid once I drop the rest of my game engine in there it''s going to break again.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement