Jump to content
  • Advertisement
Sign in to follow this  
DontPanic

OpenGL glGetTexLevelParameterfv returns width as zero, I'm lost

This topic is 3666 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm a little baffled with this one, probably me being a newbie though. My code runs on some machines and not on others with the same OS. tested on vista and xp, runs on both, fails on both, depending on the machine. I'm using openGL and SDL but this seems relevent to the GL side of life so I posted it here. Also I have returned to this after months off doing other things. That probably doesnt help. Here is the problem code:
//init the tileset texture and some variables
	if(tileSet = loadTexture(filename, true, true))
	{
		float imageWidth, imageHeight;
		glGetTexLevelParameterfv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &imageWidth);
		glGetTexLevelParameterfv(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &imageHeight);
		xres = (int)imageWidth / TILE_SIZE_X;
		yres = (int)imageHeight / TILE_SIZE_Y;

		t_minx = 0.0f;
		t_miny = 0.0f;
		t_maxx = imageWidth;
		t_maxy = imageHeight;
	} 
	else
	{
		throw std::runtime_error("Map tileset image was not loaded");
	}

I set up vc++08 on to a problem xp machine and tried to debug. Basically the glGetTexLevelParameterfv lines are returning 0 in imageWidth and imageHeight. So xres and yres are zero and it crashes because this happens later:
x_coord = (tile % xres);

Producing this error "Unhandled exception at 0x0041f077 in Never Again.exe: 0xC0000094: Integer division by zero." So it seems to me that the image isnt loading if it has no height or width, however I went through it with debug and it seems to all load, colour key etc. Here is the code for the image loading in case that is the problem. Note that tilemap class inherits these functions and I'm using libSOIL:
void render::getTexture(const char* name, bool clampTexture, bool useColourKey, int red, int green, int blue) 
{
	
	int width, height, channels;
	unsigned char *imgdata = SOIL_load_image
	(
		name,
		&width, &height, &channels,
		SOIL_LOAD_RGBA
	);
	channels = 4;

	if (imgdata == NULL)
	{
		throw std::runtime_error("image was not loaded");
	}

	//colour key image
	if(useColourKey == true)
	{
		for(int i=0; i < width*height*channels; i+=4)
		{
		  if(imgdata==red && imgdata[i+1]==green && imgdata[i+2]==blue)
			imgdata[i+3] = 0;
		}
	}

	//feed the texture into opengl
	glTexImage2D( GL_TEXTURE_2D,
		     0,
		     GL_RGBA8,
		     width,
		     height,
		     0,
		     GL_RGBA,
		     GL_UNSIGNED_BYTE,
		     imgdata );
	
	// Whether the texture will repeat or it is clamped to its destination
	if (clampTexture == true)
	{
		glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
		glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
	} else {
		glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
        glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
	}

	//nearest to prevent blurring on tilesets and other compiled images textures
	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
}

GLuint render::loadTexture(const char* name, bool clampTexture, bool useColourKey, int red, int green, int blue)
{
	GLuint texID = 0;
	glGenTextures(1,&texID);
    glBindTexture(GL_TEXTURE_2D,texID);
	getTexture(name, clampTexture, useColourKey, red, green, blue);
	return texID;
}

Is it a problem of scope? If so why do only some machines not like it? I've noticed all the machines that dont like it have intel celeron processors but something tells me it's not that causing the problem and it probably is my lame code. I've been hacking this together as a novice so I guess it wont be pretty. Any help would be nice :) [Edited by - DontPanic on June 11, 2008 5:03:26 PM]

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!