I've been working almost a week in a very simplistic environment map demo for my Cg language learning. The problem is the cubemap is not loaded correctly, and I can't see the problem. This is my code for load the faces:
And this is my code for loading all the Cg stuff:Code :glGenTextures(1, &texturaID); glBindTexture(GL_TEXTURE_CUBE_MAP, texturaID); revisarErrores("'Binding' la textura para cargarla"); int w, h; char* text;//Buffer en RAM donde se alamcena la imagen en formato RGBA char* pixeles; for(int i =0; i<6; i++){ formato = FreeImage_GetFileType(texturas[i]); imagen = FreeImage_Load( formato,texturas[i] ); if(imagen == 0 || formato == 0){ cout<<"No se encontró la cara "<<i<<endl; } temp =imagen; cout<<"BPP inicial: "<< FreeImage_GetBPP(imagen)<<endl; imagen = FreeImage_ConvertTo32Bits(imagen); FreeImage_Unload(temp); w = FreeImage_GetWidth(imagen); h = FreeImage_GetHeight(imagen); text = new char[4*w*h]; pixeles = (char*) FreeImage_GetBits(imagen); cout<<"La textura "<<i+1<<" tiene el tamańo " <<w<<"*"<<h<<", BPP: "<<FreeImage_GetBPP(imagen)<<endl; //Format conversion BRGA->RGBA for( int j=0; j<w*h; j++){ text[j*4] = pixeles[j*4+2]; text[j*4+1] = pixeles[j*4+1]; text[j*4+2] = pixeles[j*4]; text[j*4+3] = pixeles[j*4+3]; } glTexImage2D( GL_TEXTURE_CUBE_MAP_POSITIVE_X+i, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, (GLvoid*)text ); //cout<<"Primer byte en la textura: "<<text[579]<<text[100]<<endl; revisarErrores("Cargando una cara"); FreeImage_Unload(imagen); delete [] text; } revisarErrores("Cargando la textura"); glTexParameteri( GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE ); glTexParameteri( GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE ); glTexParameteri( GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE ); glTexParameteri( GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR ); glTexParameteri( GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); revisarErrores("Configurando los parámetros de la textura");
Befor drawing I'm calling cgGLEnableTexture parameter. But all the drawing is black!. This is my fragment shader:Code :contextoCg = cgCreateContext(); vertexProfile = cgGLGetLatestProfile(CG_GL_VERTEX); fragmentProfile = cgGLGetLatestProfile(CG_GL_FRAGMENT); cgGLSetOptimalOptions(vertexProfile);//Muy importante!, permite el uso de toda la capacidad de tu GPU cgGLSetOptimalOptions(fragmentProfile); revisarErrores("cargando los perfiles"); cgSetErrorCallback(MyErrorCallback); vertexProgram = cgCreateProgramFromFile( contextoCg, CG_SOURCE, shaderFiles[0], vertexProfile, "main", 0 ); cgGLLoadProgram(vertexProgram); revisarErrores("Cargando el vertexShader"); fragmentProgram = cgCreateProgramFromFile( contextoCg, CG_SOURCE, shaderFiles[1], fragmentProfile, "main", 0 ); cgGLLoadProgram(fragmentProgram); revisarErrores("Cargando el fragmentShader"); textura = cgGetNamedParameter(fragmentProgram, "textura"); revisarErrores("obteniendo el parametro textura"); if(textura == 0){ cout<<"No se pudo recuperar el parámetro 'textura'"<<endl; revisarErrores("obteniendo el parámetro 'textura'"); } cout<<"Textura válida?: "<<(bool)glIsTexture(texturaID)<<endl; cgGLSetTextureParameter(textura, texturaID); revisarErrores("Setting the texture parameter"); cgGLEnableTextureParameter(textura);//Activamos la textura revisarErrores("cargando el parametro textura");
Code :void main( in float3 normal, uniform samplerCUBE textura, out float4 color:COLOR ){ color = texCUBE(textura, normal); }



