PDA

View Full Version : Cubemap Texture loading



DerTherion
11-08-2008, 04:23 AM
hello,

i work with java/jogl opengl and found an
tutorial about cubemap, but the face textures
of the cubemap are only simpel colored textures.

i didnt found a way to load my textures into
the cubemap.

i try google but didnt find anything and the
redbook on opengl.org is offline since a few days


gl.glTexImage2D(GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, GL.GL_RGBA,imageSize, imageSize, 0, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE,texture[nr]<-error );

i see that the gltextimage2d want this:

private static ByteBuffer imageBuf1 = BufferUtil.newByteBuffer(imageSize * imageSize * 4);

but how did i copy my textures into that imageBuf1 for example


much thx for any help




...

...
import com.sun.opengl.util.*;
import javax.media.opengl.*;
import javax.media.opengl.glu.*;
...
Texture[] texture= new Texture[200];
...

//Texture Loader
texture[nr] = TextureIO.newTexture(new File("gfx/d00"+nr+".JPG"), true);
texture[nr].bind();

gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR);
gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR_MIPMAP_NEAREST);

gl.glPixelStorei(GL.GL_UNPACK_ALIGNMENT, 2);
gl.glTexEnvf(GL.GL_TEXTURE_ENV, GL.GL_TEXTURE_ENV_MODE, GL.GL_MODULATE);
....

Brolingstanz
11-09-2008, 05:01 PM
I'd look into the dds texture format and maybe one of free image libraries, great for cubemaps an just about everything else.

DerTherion
11-09-2008, 11:29 PM
hello modus,

i have the cubemap images already inside the project
i use them as skybox and now i also want
the
same textures to use in the cubemap

the only problem i have, i dont know how get them
into the gl.glTexImage2D.

texture[nr] -> 'convert/copy/whatever' -> private static ByteBuffer imageBuf1 ?!?!?!

:)

_NK47
11-10-2008, 07:24 AM
DerTherion: the only problem i have, i dont know how get them into the gl.glTexImage2D.

thru glTexImage2D. you need to upload pixels for EACH direction one by one.
GL_TEXTURE_CUBE_MAP_POSITIVE_X
GL_TEXTURE_CUBE_MAP_NEGATIVE_X
GL_TEXTURE_CUBE_MAP_POSITIVE_Y
GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
GL_TEXTURE_CUBE_MAP_POSITIVE_Z
GL_TEXTURE_CUBE_MAP_NEGATIVE_Z

DerTherion
11-10-2008, 07:36 AM
hello _NK47 :)

i know that i have to feed glTexImage2D with pixels...

my problem is simple...

i got some textures loaded..and i search for a way
go get the pixels (of that textures) and
copy/put/whatever into imageBuf1

(at moment the imagebuf1-6 pixeldata are simple
created colors that shows me that cubemap is working
but instead of an green reflection i want an pictures in
the cubemap,but i cant find commands/code/demos with source
for that copy tetxurepixel to buffer )

gl.glTexImage2D(GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, GL.GL_RGBA,
imageSize, imageSize, 0, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE,
imageBuf1);

...
...
...

_NK47
11-10-2008, 09:26 AM
you want to download pixels from GPU to CPU? if yes use glGetTexImage().

basically you upload texture data with glTexImage2d() and download it with glGetTexImage().