Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

adam17

Normal mapping

This topic is 5232 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

right now i am trying to implement normal mapping via shaders into my program. i think its working but i get errors whenever i put this into my code....
	glTexGenfv(GL_S, GL_TEXTURE_GEN_MODE, GL_NORMAL_MAP_EXT);
	glTexGenfv(GL_T, GL_TEXTURE_GEN_MODE, GL_NORMAL_MAP_EXT);
	glTexGenfv(GL_R, GL_TEXTURE_GEN_MODE, GL_NORMAL_MAP_EXT);
	glEnable(GL_TEXTURE_GEN_S);
	glEnable(GL_TEXTURE_GEN_T);
	glEnable(GL_TEXTURE_GEN_R);
 
VC++6 keeps giving me this error
H:\Adam\Software\Visual C++\cgflipflop\cgflipflop\cgflipflop.cpp(106) : error C2664: ''glTexGenfv'' : cannot convert parameter 3 from ''const int'' to ''const float *''
        Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
 
i pulled this from nvidia''s website. any ideas on what i can do to fix this? also here is there code for generating a normalization cubemap. it doesnt look right either.
	glEnable(GL_TEXTURE_CUBE_MAP_EXT);

	GLubyte face[6][64][64][3];	

	for(int i=0; i<6; i++)
	{
		glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X_EXT + i,
			0,
			GL_RGB8,
			64,
			64,
			0,
			GL_RGB,
			GL_UNSIGNED_BYTE,
			&face[0][0][0]);
	}

	glTexParameteri(GL_TEXTURE_CUBE_MAP_EXT, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
	glTexParameteri(GL_TEXTURE_CUBE_MAP_EXT, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

	glTexGenfv(GL_S, GL_TEXTURE_GEN_MODE, GL_NORMAL_MAP_EXT);
	glTexGenfv(GL_T, GL_TEXTURE_GEN_MODE, GL_NORMAL_MAP_EXT);
	glTexGenfv(GL_R, GL_TEXTURE_GEN_MODE, GL_NORMAL_MAP_EXT);
	glEnable(GL_TEXTURE_GEN_S);
	glEnable(GL_TEXTURE_GEN_T);
	glEnable(GL_TEXTURE_GEN_R);
 
thanks ahead of time.

Share this post


Link to post
Share on other sites
Advertisement
This assumes that your cubemap textures are already generated
& present in the face[][][][] variable.

instead of what you have, try these:


#include "glext.h"

unsigned int cmap;

glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP_EXT);
glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP_EXT);
glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP_EXT);
glEnable(GL_NORMALIZE);
glEnable(GL_TEXTURE_CUBE_MAP_EXT);
glBindTexture(GL_TEXTURE_CUBE_MAP_EXT, cmap);


AND... because your "face" variable is a quadruple array,
6 textures, 64x64 pixels each with 3 bytes per pixel,
in your loop, I assume you want to use your "i" variable
like this too:


for(int i=0; i<6; i++) {
glTexImage2D(
GL_TEXTURE_CUBE_MAP_POSITIVE_X_EXT + i,
0, GL_RGB8,
64, 64, 0,
GL_RGB,
GL_UNSIGNED_BYTE,
&face[i][0][0][0] );
}



maybe leave off the last "[0]" I'm not sure, I didn't look up what glTexImage2D() asks for. The part with the "GL_TEXTURE_CUBE_MAP_POSITIVE_X_EXT + i" is correct, the faces just have to be in this order:
POSITIVE_X_DIRECTION
NEGATIVE_X_DIRECTION
POSITIVE_Y_DIRECTION
NEGATIVE_Y_DIRECTION
POSITIVE_Z_DIRECTION
NEGATIVE_Z_DIRECTION


any Qs ?

[edited by - Luke Miklos on June 3, 2004 3:23:26 AM]

Share this post


Link to post
Share on other sites
forgot to mention, there are 2 simple parts to cube-mapping, or normal-mapping as you call it:

1) Generating the cube map textures & telling the system that thats what they are (the part with glTexImage2D)

2) Binding to the cubemap & drawing your cool object, example:

glBindTexture(GL_TEXTURE_CUBE_MAP_EXT, cmap);
glTexParameteri(GL_TEXTURE_CUBE_MAP_EXT, GL_TEXTURE_MIN_FILTER,GL_NEAREST);
glTexParameteri(GL_TEXTURE_CUBE_MAP_EXT, GL_TEXTURE_MAG_FILTER,GL_NEAREST);
//PARAMETER OPTION 2
glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP_EXT);
glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP_EXT);
glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP_EXT);
glEnable(GL_NORMALIZE);
glEnable(GL_TEXTURE_CUBE_MAP_EXT);
glEnable(GL_TEXTURE_GEN_S);
glEnable(GL_TEXTURE_GEN_T);
glEnable(GL_TEXTURE_GEN_R);
gluSphere(quadricPointer[0],radius,64,64);


A lot of this is just to be sure you aren''t forgetting something, you don''t have to do ALL these commands every frame.
also... if you don''t like GL_NEAREST for a TexParamter(), then try GL_LINEAR. good luck

Share this post


Link to post
Share on other sites
okay i have everything put together except for the cube map construction. i know the xyz vectors are rgb. now my problem is i dont know how opengl will read the face array into the cube map.
which variable needs to go where in the blank spots of my loop?

for(int i=0; i<6; i++)
{
for(int j=0; j<64; j++)
{
for(int k=0; k<64; k++)
{
if(i == 0)
face[i][255][ ][ ];
if(i == 1)
face[i][0][ ][ ];
if(i == 2)
face[i][ ][255][ ];
if(i == 3)
face[i][ ][0][ ];
if(i == 4)
face[i][ ][ ][255];
if(i == 5)
face[i][ ][ ][0];
}
}
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X_EXT + i,
0,
GL_RGB8,
64,
64,
0,
GL_RGB,
GL_UNSIGNED_BYTE,
&face[ i ][0][0][0]);
}

Share this post


Link to post
Share on other sites
huh?

this is how I perceive the face array:

face[f][g][h][j]

f = 6, for 6 pictures, one for each side of the cube
g = 64 & h = 64,
which means each of the 6 pictures is 64x64 pixels in size.
j = 3, for red, green, & blue

so say you render a scene in a 64x64 frame buffer, call glReadPixels() like this to read that scene into the face[][][][] texture:

for(i=0;i<6;++i) {
drawScene(i);
glReadPixels(0,0,64,64,GL_RGB,GL_UNSIGNED_BYTE,&face[i][0][0][0]);
glTexImage2D(
GL_TEXTURE_CUBE_MAP_POSITIVE_X_EXT + i,
0,
GL_RGB8,
64,
64,
0,
GL_RGB,
GL_UNSIGNED_BYTE,
&face[i][0][0][0] );
}

OR... something like this (simpler):

for(i=0;i<6;++i) {
drawScene(i);
void glCopyTexImage2D(
GL_TEXTURE_CUBE_MAP_POSITIVE_X_EXT + i,
0,
GL_RGB,
0,
0,
64,
64,
0);
}



[edited by - Luke Miklos on June 3, 2004 3:01:36 PM]

Share this post


Link to post
Share on other sites
this normalization cube map is throwin my head into a spin. does anyone have some code that will make it? i feel bad about asking but balancing all of these numbers in my head and wondering how opengl will percieve the maps is driving me crazy.

Share this post


Link to post
Share on other sites
quote:
Original post by adam17
does anyone have some code that will make it?

You can get it on Nutty''s page. Is included by some demos.. but I don''t know witch ones



You should never let your fears become the boundaries of your dreams.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Adam,

You won''t have much luck with nutty''s cubemap, I didn''t.

You have to understand that the face[][][][] is really just a buffer that holds texture data. you have to fill it with data somehow.

If you ask better questions, we can give you better answers, don''t look for a shortcut. All you have done is shown us snipets of code & kinda asked us to explain them or fix them. What you need is a big picture understanding first, & then you can code in the particulars.

Try & understand the help we give you here. Now what exactly do you want to do? Do you have 6 textures already saved on your computer that you want to use ? Do you want a dynamic cubemap effect? Where you render the textures all the time to make a reflection of some sort?

Share this post


Link to post
Share on other sites
ok i think i have everything under control now. i am just having one problem though. i dont know how to convert the face array into GLuint for the image. heres my code...

void BuildCUBE()
{
glEnable(GL_TEXTURE_CUBE_MAP_EXT);

GLubyte face[6][64][64][3];
GLuint cube;

for(int i=0; i<6; i++)
{
for(int j=0; j<64; j++)
{
for(int k=0; k<64; k++)
{
if(i == 0)
{
face[i][j][k][0] = 255;
face[i][j][k][1] = k*4;
face[i][j][k][2] = j*4;
}
if(i == 1)
{
face[i][j][k][0] = 0;
face[i][j][k][1] = k*4;
face[i][j][k][2] = j*4;
}
if(i == 2)
{
face[i][j][k][0] = k*4;
face[i][j][k][1] = 255;
face[i][j][k][2] = j*4;
}
if(i == 3)
{
face[i][j][k][0] = k*4;
face[i][j][k][1] = 0;
face[i][j][k][2] = j*4;
}
if(i == 4)
{
face[i][j][k][0] = k*4;
face[i][j][k][1] = j*4;
face[i][j][k][2] = 255;
}
if(i == 5)
{
face[i][j][k][0] = k*4;
face[i][j][k][1] = j*4;
face[i][j][k][2] = 0;
}
}
}
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X_EXT + i,
0,
GL_RGB8,
64,
64,
0,
GL_RGB,
GL_UNSIGNED_BYTE,
&face[i]/*[0][0][0]*/);
}

glTexParameteri(GL_TEXTURE_CUBE_MAP_EXT, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_CUBE_MAP_EXT, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP_EXT);
glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP_EXT);
glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP_EXT);
glEnable(GL_TEXTURE_GEN_S);
glEnable(GL_TEXTURE_GEN_T);
glEnable(GL_TEXTURE_GEN_R);
glEnable(GL_NORMALIZE);
glBindTexture(GL_TEXTURE_CUBE_MAP_EXT, face);
}

incase some of you guys are still a little lost on the subject i had to create 6 different images for the normalization cube map. photoshop just seems like too much trouble.

Share this post


Link to post
Share on other sites
looking good, at least much better....

now... face is not the handle that you bind to, do this:


//global variable for now

unsigned int CMAP;

//do this before any calls to: glTexImage2D()

glGenTextures ( 1, &CMAP );
glBindTexture( GL_TEXTURE_CUBE_MAP_EXT, CMAP);


& go ahead & remove the bind at the end... since you are adding this one at the "beginning"

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!