gltexgen error

Started by
2 comments, last by MARS_999 15 years, 7 months ago
hi all iam trying to do a simple gl texgen of a picture on a teapot but the program takes only one texel value, as it would do, if i dint do gltexgen here is my code ---------------------------------- in test.cpp program GLuint setupSOILTexture(char *texName, GLuint texture_unit) { static int abc =0; glActiveTexture(texture_unit); GLuint x = SOIL_load_OGL_texture ( texName, SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_MIPMAPS | SOIL_FLAG_NTSC_SAFE_RGB |SOIL_FLAG_INVERT_Y | SOIL_FLAG_TEXTURE_REPEATS ); if( 0 == x ) { printf( "SOIL loading error: '%s'\n", SOIL_last_result() ); } glBindTexture( GL_TEXTURE_2D, x); glEnable(GL_TEXTURE_GEN_S); glEnable(GL_TEXTURE_GEN_T); float s_plane[] = { 1.0, 0.0, 0.0, 0.0}; float t_plane[] = { 0.0, 1.0, 0.0,0.0}; // we use the z plane here, but map it to y, since we are extruding on Z, not Y glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR); glTexGenfv(GL_S, GL_OBJECT_PLANE, s_plane); glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR); glTexGenfv(GL_T, GL_OBJECT_PLANE, t_plane); if(glIsEnabled(GL_TEXTURE_GEN_S) && glIsEnabled(GL_TEXTURE_GEN_T)){printf("gen s,t enabled");} else{printf("gen s,t not enabled");} return x; } ------------------ void render(){ glUseProgram(p); loc1 = glGetUniformLocation(p, "LightPosition"); glUniform3f(loc1, 1.5, 1.5, 0.0); loc2 = glGetUniformLocation(p, "texture1"); //skull glUniform1i(loc2, 0); glPushMatrix(); glScalef(3.31,3.31,3.31); glRotatef(mouseWindowX*360,0,1,0); glRotatef(mouseWindowY*60,0,0,1); glutSolidTeaPot(2); } ------------------ int main(int argc, char **argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA); glutInitWindowPosition(0,0); glutInitWindowSize(1300,1300); glutCreateWindow("GLSL demo"); glutDisplayFunc(renderScene); glutIdleFunc(renderScene); glutReshapeFunc(changeSize); glEnable(GL_DEPTH_TEST); glClearColor(0.0, 0.0, 0.0, 1.0); glewInit(); if (GLEW_ARB_vertex_shader && GLEW_ARB_fragment_shader) printf("Ready for GLSL\n"); else { printf("No GLSL support\n"); exit(1); } if(glActiveTexture==NULL) { printf("glActiveTexture not supported\n"); exit(1); } else { printf("yes"); } setupSOILTexture("./images/skull.jpg", GL_TEXTURE0); p=setShaders("./gen.vert", "./gen.frag"); glutMainLoop(); return 0; } ------------------ vertex shader: uniform vec3 LightPosition; void main (void) { gl_Position = ftransform(); gl_TexCoord[0] = gl_MultiTexCoord0; } --------------------- fragment shader // Fragment shader for environment mapping with an // equirectangular 2D texture // Authors: John Kessenich, Randi Rost // Copyright (c) 2002-2004 3Dlabs Inc. Ltd. // See 3Dlabs-License.txt for license information uniform sampler2D texture1; void main (void) { vec3 envColor = vec3 (texture2D(texture1, gl_TexCoord[0].st)); // Add lighting to base colour and mix envcolor*=0.7; //for lighting gl_FragColor = vec4(envColor, 1.0); } -------------- the resulting image is the texture coordinate is a constant one for all vertices and it is giving me a single color from the texture please tell me where i went wrong with the texgen thanks
Thanks,Swtsvn
Advertisement
Are you using shaders? If you are, then fixed function mode things like texgen won`t work. You have to code it yourself in the vertex shader, or if you prefer, the fragment shader.
Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);
oh great. now i have to figure out how to do object_plane by myself
i want the texture to stick to the object, and not move with the camera, or rotation.

do u know, how to figure out the texel value in the vertex shader?
using the vertex position as the reference?
Thanks,Swtsvn
gl_TexCoord[0].s = dot(gl_Vertex, gl_ObjectPlaneS[0]);gl_TexCoord[0].t = dot(gl_Vertex, gl_ObjectPlaneT[0]);gl_TexCoord[0].p = dot(gl_Vertex, gl_ObjectPlaneR[0]);gl_TexCoord[0].q = dot(gl_Vertex, gl_ObjectPlaneQ[0]);


Try that

This topic is closed to new replies.

Advertisement