PDA

View Full Version : Cubemapping, what am i doing wrong?



longshotnl
02-11-2005, 03:48 PM
What am i doing wrong or what could be interfering with this code?
The result of this code is that i see absolutely nothing textured.

on startup :

CUBE_MAPPING_EXTENSION_ENABLE = 1;
char *ext = (char*)glGetString(GL_EXTENSIONS);
if( strstr(ext, "EXT_texture_cube_map") == NULL ){
CUBE_MAPPING_EXTENSION_ENABLE = 0;
return;
}
glDisable(GL_TEXTURE_GEN_S);
glDisable(GL_TEXTURE_GEN_T);
glDisable(GL_TEXTURE_GEN_R);When drawing:


if (!CUBE_MAPPING_EXTENSION_ENABLE) return;

glDisable( GL_TEXTURE_2D );
glEnable( GL_TEXTURE_CUBE_MAP_EXT );

if (!cubemap->ID){
glGenTextures(1, &cubemap->ID);
//ERRORLOG->Add("creating cubemap");
glBindTexture(GL_TEXTURE_CUBE_MAP_ARB, cubemap->ID);

// create the cubemap.
if (cubemap->RIGHT)
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X_EXT, 0, GL_RGBA, cubemap->RIGHT->WIDTH, cubemap->RIGHT->HEIGHT, 0, GL_RGBA, GL_UNSIGNED_BYTE, cubemap->RIGHT->TEXTURE );
if (cubemap->LEFT)
glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X_EXT, 0, GL_RGBA, cubemap->LEFT->WIDTH, cubemap->LEFT->HEIGHT, 0, GL_RGBA, GL_UNSIGNED_BYTE, cubemap->LEFT->TEXTURE );
if (cubemap->FRONT)
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y_EXT, 0, GL_RGBA, cubemap->FRONT->WIDTH, cubemap->FRONT->HEIGHT, 0, GL_RGBA, GL_UNSIGNED_BYTE, cubemap->FRONT->TEXTURE );
if (cubemap->BACK)
glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_EXT, 0, GL_RGBA, cubemap->BACK->WIDTH, cubemap->BACK->HEIGHT, 0, GL_RGBA, GL_UNSIGNED_BYTE, cubemap->BACK->TEXTURE );
if (cubemap->TOP)
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z_EXT, 0, GL_RGBA, cubemap->TOP->WIDTH, cubemap->TOP->HEIGHT, 0, GL_RGBA, GL_UNSIGNED_BYTE, cubemap->TOP->TEXTURE );
if (cubemap->BOTTOM)
glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_EXT, 0, GL_RGBA, cubemap->BOTTOM->WIDTH, cubemap->BOTTOM->HEIGHT, 0, GL_RGBA, GL_UNSIGNED_BYTE, cubemap->BOTTOM->TEXTURE );
} else {
//ERRORLOG->Add("binding cubemap");
glBindTexture(GL_TEXTURE_CUBE_MAP_ARB, cubemap->ID);
}

Mikkel Gjoel
02-11-2005, 05:46 PM
Have you tried using glGetError(..) (http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/geterror.html) ?

You seem to be confusing the EXT cubemap-extension with the ARB one. You should probably use the latter.

Also, instead of all the

if( cubemap->right )- etc., add assertions in the beginning, ie.


#include <assert.h>
.
.
assert( cubemap->right );
assert( cubemap->left );
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X_EXT, 0, GL_RGBA, cubemap->RIGHT->WIDTH, cubemap->RIGHT->HEIGHT, 0, GL_RGBA, GL_UNSIGNED_BYTE, cubemap->RIGHT->TEXTURE );
.
.
.
glGetError(..);At least then you know if you actually upload something. Have you checked that all the parameters for glTexImage2D are valid?

Hope this helps,
\\hornet

longshotnl
02-12-2005, 02:33 AM
I didn't know there were two types of cubemaps.
I got what i did from this document which apparently is wrong :
http://webster.fhs-hagenberg.ac.at/staff/haller/cg_20032004/05-Cg%20OpenGL%202.pdf

Anyways, i replaced all EXT's with ARB's and the other way around but it still doesn't do anything. The 3D-model stays plain white.

Do i have to do something to scale the cube of the cubemap or to position it?

Nico_dup1
02-12-2005, 03:09 AM
Did you set min/mag filters for the cubemap?

longshotnl
02-12-2005, 05:24 AM
Ah, well now i see something, but it still looks crappy...

This character should be mapped with the NESW image below it mapped on it from all sides :
http://www.gunfight.net/img/misc/problem_03.jpg

Mikkel Gjoel
02-12-2005, 07:51 AM
Looks like you should compute (averaged) per vertex normals, instead of per face. You probably also need to set glShadeModel( GL_SMOOTH ) - and not GL_FLAT... in case you didn't already :)

\\hornet

longshotnl
02-12-2005, 05:37 PM
Easyer sayed than done.
Since it is a deformable shape, i need to recalculate these normals per frame.
I stored my vertexes in the polygons so i had to rewrite a big chunk of my engine.
Anyways, here's the result:
http://www.gunfight.net/img/misc/problem_04.jpg

How does it look to you? I think it looks very well, especially when it is moving. It has something metalic about it, which is exactly what i wanted.

I come back to read your replies but thanks already for your help.

SeskaPeel
02-14-2005, 05:37 AM
ARB and EXT both define the same value. Using one or antoher won't change anything. You can even use GL_TEXTURE_CUBE_MAP alone if you have recent headers.

SeskaPeel