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

help with fragment program

Started by penetrator Apr 19, 2004 at 8:51 AM 0 replies 400+ views
Original Post
penetrator
penetrator
Hi, i''ve been asking for help also at opengl forum, but didn''t have a clear answer to the following problem. I want to blend two textures together through a fragment program. The shader code is this: TEMP tex0; TEMP tex1; TEX tex0, fragment.texcoord[0], texture[0], 2D; TEX tex1, fragment.texcoord[0], texture[1], 2D; MUL oColor, tex0, tex1; and this is the code in the opengl pipe: glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); glEnable( GL_VERTEX_PROGRAM_ARB ); glBindProgramARB( GL_VERTEX_PROGRAM_ARB, g_vertexProgramID ); glEnable( GL_FRAGMENT_PROGRAM_ARB ); glBindProgramARB( GL_FRAGMENT_PROGRAM_ARB, g_pixelProgramID ); glBindTexture(GL_TEXTURE_2D, my_texture1); glutSolidTeapot(.5); glDisable( GL_FRAGMENT_PROGRAM_ARB ); glDisable( GL_VERTEX_PROGRAM_ARB ); SwapBuffers( g_hDC ); I loaded the two textures to blend in the initgl() function, but i don''t understand where you tell the fragment program which textures correspond to texture[0] and texture[1]. I''m a newbie i know, but simply reading the arb_fragment_program is impossible to write a program from scratch. It would be much better if, together with the arb paper, they would include a couple of well commentented tutorials. At least this is my opinion.
aaron_ds
aaron_ds

glBegin(GL_TRIANGLES);
POINT3f i,j,k;
i=cur_uv->points[0];
j=cur_uv->points[1];
k=cur_uv->points[2];
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
glNormal3f(-(cur_poly->normal.x), cur_poly->normal.y, cur_poly->normal.z);
glMultiTexCoord2f(GL_TEXTURE0_ARB, i.x, i.y);
glMultiTexCoord2f(GL_TEXTURE1_ARB, i.x, i.y);
glColor4f(cur_poly->colors[0].x,cur_poly->colors[0].y,cur_poly->colors[0].z, 1.0f);
glVertex3f(-(cur_poly->points[0].x) , cur_poly->points[0].y ,cur_poly->points[0].z);
glMultiTexCoord2f(GL_TEXTURE0_ARB, j.x, j.y);
glMultiTexCoord2f(GL_TEXTURE1_ARB, j.x, j.y);
glColor4f(cur_poly->colors[1].x,cur_poly->colors[1].y,cur_poly->colors[1].z, 1.0f);
glVertex3f(-(cur_poly->points[1].x) , cur_poly->points[1].y ,cur_poly->points[1].z);
glMultiTexCoord2f(GL_TEXTURE0_ARB, k.x, k.y);
glMultiTexCoord2f(GL_TEXTURE1_ARB, k.x, k.y);
glColor4f(cur_poly->colors[2].x,cur_poly->colors[2].y,cur_poly->colors[2].z, 1.0f);
glVertex3f(-(cur_poly->points[2].x) , cur_poly->points[2].y ,cur_poly->points[2].z);
}
glEnd();

The above is an edited code snippet that I use.

Your fragment program ''looks'' correct. Try using
TEX tex1, fragment.texcoord[1], texture[1], 2D;
instead, in case you want to use different different texture coords for each texture.
If MUL oColor, tex0, tex1;
isnt giving you the results you want, change MUL to ADD and see if it works better.

Topic Locked

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

Sign in to reply to this topic.