Skip to main content
GameDev.net gamedev.net
🔒 Locked

Detail texturing error

Started by azjerei Nov 9, 2004 at 8:11 AM 1 replies 400+ views
Original Post
azjerei
azjerei
I recently attempted to include detail texturing in my 3d engine using OpenGL, but after having done all the necessary steps, I noticed that it did not quite work. Here is the detail texture I attempted to use: But, when I run the game, it looks like this (I have no idea where that texture in the screenshot is coming from): Here is my code: in function :: init()

glActiveTextureARB = (PFNGLACTIVETEXTUREARBPROC) wglGetProcAddress("glActiveTextureARB");
	glMultiTexCoord2fARB = (PFNGLMULTITEXCOORD2FARBPROC) wglGetProcAddress("glMultiTexCoord2fARB");

if (!glActiveTextureARB || !glMultiTexCoord2fARB) {
	MessageBox(g_hWnd, "Multitexturing is not supported!", "Error", MB_OK);
	PostQuitMessage(0);
}




Necessary functions

void SetTextureCoord(float u, float v)
{
	glMultiTexCoord2fARB(GL_TEXTURE0_ARB, u, v);
	glMultiTexCoord2fARB(GL_TEXTURE1_ARB, u, v);
}

void SetupDetailTexturing(int texture, int detail)
{
	// Set up the original texture.
	glActiveTextureARB(GL_TEXTURE0_ARB);
	glEnable(GL_TEXTURE_2D);
	glBindTexture(GL_TEXTURE_2D, texture);

	// Set up the detail texture.
	glActiveTextureARB(GL_TEXTURE1_ARB);
	glEnable(GL_TEXTURE_2D);
	glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT);
	glTexEnvi(GL_TEXTURE_ENV, GL_RGB_SCALE_EXT, 2);
	glBindTexture(GL_TEXTURE_2D, detail);
	
	// Set up the detail scale matrix.
	glMatrixMode(GL_TEXTURE);
		glLoadIdentity();
		glScalef((float)g_DetailScale, (float)g_DetailScale, 1);
	glMatrixMode(GL_MODELVIEW);
}

void DisableDetailTexturing()
{
	glActiveTextureARB(GL_TEXTURE1_ARB);
    glDisable(GL_TEXTURE_2D);

	glActiveTextureARB(GL_TEXTURE0_ARB);		
    glDisable(GL_TEXTURE_2D);
}




in function :: Render() (pseudocode)

for each object
	SetupDetailTexturing(TXregular, TXdetail);

	for each polygon face
		for each vertex
			SetupTextureCoord(TexVerts.x, TexVerts.y);
		end
	end
end

DisableDetailTexturing();



I know it loads the correct texture for this, but it does not display it. And, the whole thing is running much slower with detail texturing turned on. Any ideas, suggestions or similar?
okonomiyaki
okonomiyaki
Try doing it without scaling the detail texture. See if it looks right. You could also scale it a lot easier by multiplying the detail's texcoords by the desired repeat factor.

I have a feeling there's a problem with this part:

	glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT);	glTexEnvi(GL_TEXTURE_ENV, GL_RGB_SCALE_EXT, 2);


I remember playing around with multitexturing without pixel shaders, and it never seemed to do what I wanted. Maybe I didn't understand it well enough. Have you looked the OpenGL spec document? I think it outlines this operations pretty well.

Good luck.
azjerei
azjerei
Solved it... did not type g_Texture[txDetail] :)

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.