Recent

Author Topic: Loading a cube map from existing textures in OpenGL  (Read 5068 times)

soerensen3

  • Full Member
  • ***
  • Posts: 213
Loading a cube map from existing textures in OpenGL
« on: February 21, 2018, 06:38:05 pm »
Dear All,

I'm trying to load an hdr cube map. For loading the radiance/hdr file I'm using VampyreImagingOpenGL from trunk (The rest of the package is the latest release because I couldn't get trunk working for me and the release version of VampyreImagingOpenGL is converting hdr images to 8-bit before loading).
I want to load it into a cube map but it does not seem to work (I get a black image).

Here is the relevant "pseudo" code:

Code: Pascal  [Select][+][-]
  1. //For each file...
  2. PX:= LoadGLTextureFromFile( path + 'PX.hdr' );
  3. //...
  4. glGenTextures( 1, @GLTexture );
  5. glBindTexture( GL_TEXTURE_CUBE_MAP, GLTexture );
  6. //For each side
  7. glBindTexture( GL_TEXTURE_CUBE_MAP_POSITIVE_X, PX );
  8. //...
  9. glBindTexture( GL_TEXTURE_CUBE_MAP, 0 );
  10.  

From the OpenGL Documentation it says:
Quote
When a texture is first bound, it assumes the specified target: A texture first bound to GL_TEXTURE_1D becomes one-dimensional texture, ...
(https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glBindTexture.xhtml)
So my guess is that ImagingOpenGL initializes the texture as GL_TEXTURE_2D.
Is there a simple way to copy/convert a texture to another? I'm of course also open to other solutions. I'm trying to target OpenGL 2.1.  Maybe glCopyTexImage2D is the solution but I'm not sure on how to use it. What I tried is this:

Code: Pascal  [Select][+][-]
  1. //For each file...
  2. PX:= LoadGLTextureFromFile( path + 'PX.hdr' );
  3. //...
  4. glGenTextures( 1, @GLTexture );
  5. glBindTexture( GL_TEXTURE_CUBE_MAP, GLTexture );
  6. //For each side...
  7. glBindTexture( GL_TEXTURE_2D, PX );
  8. glGetTexLevelParameteriv( GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, @Width );
  9. glGetTexLevelParameteriv( GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, @Height );
  10. glGetTexLevelParameteriv( GL_TEXTURE_2D, 0, GL_TEXTURE_INTERNAL_FORMAT, @Internal );
  11. glCopyTexImage2D( GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, Internal, 0, 0, Width, Height, 0 );
  12. glDeleteTextures( 0, @PX );
« Last Edit: February 21, 2018, 07:09:56 pm by soerensen3 »
Lazarus 1.9 with FPC 3.0.4
Target: Manjaro Linux 64 Bit (4.9.68-1-MANJARO)

ChrisR

  • Full Member
  • ***
  • Posts: 247
Re: Loading a cube map from existing textures in OpenGL
« Reply #1 on: March 03, 2018, 03:45:55 pm »
Not seeing all your code, it is hard to give advice. I think you want to break this down into simpler questions if you want someone to provide advice. For example, maybe you want to upload your source image or a minimalistic project that illustrates your issue. The current question is too vague to provide a solution.

 

TinyPortal © 2005-2018