2d library troubles, again. (Texturing issues)

Started by
3 comments, last by PnP Bios 19 years, 5 months ago
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]
HxRender | Cornerstone SDL TutorialsCurrently picking on: Hedos, Programmer One
Advertisement
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.
yeah, thats what it was...
but now my textures look like a plaid patter. ;(
HxRender | Cornerstone SDL TutorialsCurrently picking on: Hedos, Programmer One
try this in your hxWritePix function rather than the line you already have:

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


Has it helped?
do unto others... and then run like hell.
yeah, i got this solved. The repeating texture issue was caused by using glTexCoord2i instead of 2f.
HxRender | Cornerstone SDL TutorialsCurrently picking on: Hedos, Programmer One

This topic is closed to new replies.

Advertisement