Hello

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:


	
	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");


And this is my code for loading all the Cg stuff:


	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");


Befor drawing I’m calling cgGLEnableTexture parameter. But all the drawing is black!. This is my fragment shader:



void main(
in float3 normal,
uniform samplerCUBE textura,
out float4 color:COLOR
){

	color = texCUBE(textura, normal);
	

}



try it without mipmaps
ie u have GL_LINEAR_MIPMAP_LINEAR, yet it looks like youre supplying only texture level 0 (unless u have automatic mipmap creation enabled, which i dont see)

btw GL_TEXTURE_WRAP_R is only needed for 3d textures not cubemaps (i think)

There is also a Cg specific forum:
http://developer.nvidia.com/forums/index.php?showforum=14

btw GL_TEXTURE_WRAP_R is only needed for 3d textures not cubemaps (i think)

No, cubemap texture lookup is using (s,t,r). Wrap modes need to be set for all three coordinates.

Really? I always assumed that once OpenGL had used the s,t,r to calculate a face and new s,t coordinates, it used standard 2D texture lookups. (with standard wrappings)

Ok, I stand corrected. Should have read the specs more thoroughly.
The user’s (s,t,r) is used as a direction vector and the new (s,t) coordinates determined after the face has been selected are used as described in chapter 3.8.7 which deals with the wrap mode.

Thank you all guys, thank you!