Sign in to follow this  
PnP Bios

2d library troubles, again. (Texturing issues)

Recommended Posts

source for my build surface function:
hxSurface *hxBuild(int w, int h)
{
	int tID;
	hxSurface *workSurface;

	workSurface = new hxSurface;
	
	workSurface->w = w;
	workSurface->h = h;
	
	workSurface->pixeldata = (unsigned char*)malloc((sizeof(unsigned char)*4)*(w*h));

	tID = hxiFindOpenSlot();

	workSurface->texID = tID;
	hxiTakenList[tID] = true;
	
	return workSurface;
}




and here are the rest of the functions
void hxBeginPixWrite(hxSurface *target)
{
	hxiWs = target;

	return;
}

void hxWritePix(unsigned int x, unsigned int y, hxColorSet color)
{
	unsigned char *pd;
	unsigned int offset;

	pd = hxiWs->pixeldata;
	offset = (y*hxiWs->w)+(x*4);

	pd[offset+0] = color.r;
	pd[offset+1] = color.g;
	pd[offset+2] = color.b;
	pd[offset+3] = color.a;

	return;
}

void hxEndPixWrite(void)
{
	glBindTexture(GL_TEXTURE_2D, hxiTexList[hxiWs->texID]);
	glTexImage2D(GL_TEXTURE_2D, 0, 4, hxiWs->w, hxiWs->h, 0, GL_RGBA, GL_UNSIGNED_BYTE, hxiWs->pixeldata);	
	
	hxiWs = NULL; //we are done with this...
}

void hxBlitSurface(hxSurface *source, hxBlitRect sRect, hxBlitRect dRect, hxColorSet blendColor)
{
	glBindTexture(GL_TEXTURE_2D, hxiTexList[source->texID]);

	glColor4ub(blendColor.r, blendColor.g, blendColor.b, blendColor.a);

	glBegin(GL_QUADS);

		glTexCoord2i(sRect.x, sRect.y); glVertex2i(dRect.x, dRect.y);
		glTexCoord2i(sRect.x + sRect.w, sRect.y); glVertex2i(dRect.x + dRect.w, dRect.y);
		glTexCoord2i(sRect.x + sRect.w, sRect.y + sRect.h); glVertex2i(dRect.x + dRect.w, dRect.y + dRect.h);
		glTexCoord2i(sRect.x, sRect.y + sRect.h); glVertex2i(dRect.x, dRect.y + dRect.h);

	glEnd();		

	return;
}




hxiWs is a global copy of the current surface. My problem is that essentially, all I am getting is the rectangle. I don't think I am getting any memory leakage. I think the problem might lie in my WritePixel Function. I don't know if I am setting the offset up correctly or not. [Edited by - PnP Bios on November 24, 2004 11:57:07 PM]

Share this post


Link to post
Share on other sites
Just a thought - try putting


glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);



..or something similar (GL_LINEAR if you want it to look nicer) between the

glBindTexture(GL_TEXTURE_2D, hxiTexList[hxiWs->texID]);

and

glTexImage2D(GL_TEXTURE_2D, 0, 4, hxiWs->w, hxiWs->h, 0, GL_RGBA, GL_UNSIGNED_BYTE, hxiWs->pixeldata);

calls.

I tried replicating your situation, and throwing those lines in there worked for me.

Regards,

Hew T.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this