CubeMap

Hi,
I want to make a simple cubeMap texture.
I wrote this code for do it:


	// Cube Map
	glEnable(GL_TEXTURE_CUBE_MAP_ARB);
	glGenTextures(1, &CubeMap);
	glBindTexture(GL_TEXTURE_CUBE_MAP_ARB, CubeMap);
	Textures.InitCubeMap(128);
        glTexParameterf( GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
        glTexParameterf( GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
        glTexParameterf( GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
        glTexParameterf( GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_MIN_FILTER, GL_LINEAR );

---------------------------------------------------------------------------------------
//Textures.cpp

/*
	 ----------
	|\    A     \
	| \__________\
	| |          |
	|C|          |
	| |    B     |
	| |          |
	 \|__________|
*/

void _Textures::InitCubeMap(int size){
	unsigned char * data=new unsigned char[size*size*3];
	int Index=0;
	for(int t=0;t<size;t++){
		for(int v=0;v<size;v++){
			data[Index]=255;
			data[Index+1]=0;
			data[Index+2]=0;
			Index+=3;
		}
	}
	glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X,0, GL_RGB8, size, size, 0, GL_RGB, GL_UNSIGNED_BYTE, data);	\\C' Face
	Index = 0;
	for( t=0;t<size;t++){
		for(int v=0;v<size;v++){
			data[Index]=0;
			data[Index+1]=255;
			data[Index+2]=0;
			Index+=3;
		}
	}
	glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X,0, GL_RGB8, size, size, 0, GL_RGB, GL_UNSIGNED_BYTE, data);	\\C Face
	Index = 0;
	for( t=0;t<size;t++){
		for(int v=0;v<size;v++){
			data[Index]=255;
			data[Index+1]=255;
			data[Index+2]=0;
			Index+=3;
		}
	}
	glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y,0, GL_RGB8, size, size, 0, GL_RGB, GL_UNSIGNED_BYTE, data);	\\A Face
	Index = 0;
	for( t=0;t<size;t++){
		for(int v=0;v<size;v++){
			data[Index]=0;
			data[Index+1]=255;
			data[Index+2]=0;
			Index+=3;
		}
	}
	glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y,0, GL_RGB8, size, size, 0, GL_RGB, GL_UNSIGNED_BYTE, data); \\A' Face
	Index = 0;
	for( t=0;t<size;t++){
		for(int v=0;v<size;v++){
			data[Index]=0;
			data[Index+1]=255;
			data[Index+2]=255;
			Index+=3;
		}
	}

	glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z,0, GL_RGB8, size, size, 0, GL_RGB, GL_UNSIGNED_BYTE, data); \\B Face
	Index = 0;
	for( t=0;t<size;t++){
		for(int v=0;v<size;v++){
			data[Index]=255;
			data[Index+1]=0;
			data[Index+2]=255;
			Index+=3;
		}
	}
	glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z,0, GL_RGB8, size, size, 0, GL_RGB, GL_UNSIGNED_BYTE, data); \\B' Face
	delete [] data;
};

And resault is this:

But i think this is wrong and this isnt valid resault!
Please help me and say where are my mistakes?

Please answer my question…

I agree that your result is not what you are expecting.

I’m no expert, but…

You didn’t say which version of OpenGL you are using. If you are using a fragment shader rather than the fixed function pipeline, then you need to use the GLSL builtin function texture() within your fragment shader program to access your cube map. I’m assuming you are using the fixed function pipeline and so have no fragment shader, though. I’ve never done that (I’m a newbie working exclusively with core profile 4.0 OpenGL), but I imagine you still need to tell OpenGL how to access the cube map while rendering; I mean there has to be a 3D vector used to select (1) which of the six cube faces and (2) the (s, t) coordinate within that selected cube face from which to obtain the texel to be mapped onto each fragment.

I’m sorry I can’t provide more help than that because I don’t know the fixed function pipeline well. Maybe that will get you pointed in the right direction, though.

Hi David,Thanks a lot for your answer.
My present OpenGL version is 1.3! and can’t support
ShaderLanguage.But can support GL_TEXTURE_CUBE_MAP.

I think understand why my program not work well.
I used from glut library for drawing teapot,this library use from
2D coordinate for set textures on its ready models.But GL_TEXTURE_CUBE_MAP need to 3D coordinate for seting texture.