Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 7 of 7

Thread: Hello

  1. #1
    Intern Contributor
    Join Date
    Nov 2006
    Location
    Peru
    Posts
    97

    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:

    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");
    And this is my code for loading all the Cg stuff:

    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");
    Befor drawing I'm calling cgGLEnableTexture parameter. But all the drawing is black!. This is my fragment shader:

    Code :
     
    void main(
    in float3 normal,
    uniform samplerCUBE textura,
    out float4 color:COLOR
    ){
     
    	color = texCUBE(textura, normal);
     
     
    }

  2. #2
    Senior Member OpenGL Guru zed's Avatar
    Join Date
    Jul 2000
    Location
    S41.16.25 E173.16.21
    Posts
    2,609

    Re: Hello

    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)

  3. #3
    Junior Member Regular Contributor
    Join Date
    Jul 2007
    Location
    Alexandria, VA
    Posts
    211

    Re: Hello

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

  4. #4
    Senior Member OpenGL Guru Relic's Avatar
    Join Date
    Apr 2000
    Posts
    2,527

    Re: Hello

    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.

  5. #5
    Senior Member OpenGL Pro sqrt[-1]'s Avatar
    Join Date
    Jun 2002
    Location
    Australia
    Posts
    1,006

    Re: Hello

    Quote Originally Posted by Relic
    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)

  6. #6
    Senior Member OpenGL Guru Relic's Avatar
    Join Date
    Apr 2000
    Posts
    2,527

    Re: Hello

    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.

  7. #7
    Intern Contributor
    Join Date
    Nov 2006
    Location
    Peru
    Posts
    97

    Re: Hello

    Thank you all guys, thank you!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •