Page 1 of 2 12 LastLast
Results 1 to 10 of 15

Thread: glTexImage3D works! but... not. (PIC included)

  1. #1
    Member Newbie
    Join Date
    Jun 2005
    Posts
    42

    glTexImage3D works! but... not. (PIC included)

    So I'm trying to render my terrain with a grass and rock texture using a 3D texture to blend between them. But when I go to render, it tiles the textures next to eachother. In this sample, I'm actually trying to render just the grass texture on a quad but its rendering the rock on the top half and the grass on the bottom half. Oops, that's my water texture in the picture, not grass.

    Code :
    void initTextures(void) {
    	glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
     
    	glGenTextures(1, &gui_tex);
    	glBindTexture(GL_TEXTURE_3D, gui_tex);
     
    	importBMP("512A.bmp", &bmp[0][0][0][0], 512);
    	importBMP("512B.bmp", &bmp[1][0][0][0], 512);
     
    	glTexImage3D(GL_TEXTURE_3D, 0, GL_RGB, 4, 512, 
    		512, 0, GL_RGB, GL_UNSIGNED_BYTE, gui_bmp);
    	glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    	glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    	glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_REPEAT);
    	glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_REPEAT);
    	glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_REPEAT);
    }
     
    void renderScene(void) //**RENDERSCENE**//
    {
    	glutTimerFunc( 1000/30.0, timer, 0);
    	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
     
    	glEnable(GL_TEXTURE_3D);
    	glBegin(GL_QUADS);
    	glTexCoord3d(0,0,1);		glVertex3f( 3,  3,0);
    	glTexCoord3d(0,0,0);		glVertex3f( 3, -3,0);
    	glTexCoord3d(0,1,0);		glVertex3f(-3, -3,0);
    	glTexCoord3d(0,1,1);		glVertex3f(-3,  3,0);
    	glEnd();
     
    	glutSwapBuffers();
    }

  2. #2
    Senior Member Regular Contributor
    Join Date
    Aug 2003
    Posts
    369

    Re: glTexImage3D works! but... not. (PIC included)

    Well, I'd say you complicate things too much. Loading the bmp's in 4-D arrays? Anyway I think that your problem is the memory is not mapped as you expect it to be (or OpenGL reads the arrays different than you think) so one image interferes with the other. A simple pointer of GLubyte is enough for an image.

    You could try using two different variables of 3 dimensions each I guess. That should seperate the memory. Ofcourse since C doesn't provide bounds checking you could still have problems. If that's the case I'd suggest using a pointer to GLubyte. Though, you've managed to get this far, I couldn't load 3D textures myself

  3. #3
    Senior Member Regular Contributor
    Join Date
    Jan 2004
    Posts
    314

    Re: glTexImage3D works! but... not. (PIC included)

    Code :
     importBMP("512A.bmp", &bmp[0][0][0][0], 512);	importBMP("512B.bmp", &bmp[1][0][0][0], 512);	glTexImage3D(GL_TEXTURE_3D, 0, GL_RGB, 4, 512, 		512, 0, GL_RGB, GL_UNSIGNED_BYTE, gui_bmp);
    What does gui_bmp point to? You seem to be loading into a different buffer. (Unless it points to the same memory)

  4. #4
    Member Newbie
    Join Date
    Jun 2005
    Posts
    42

    Re: glTexImage3D works! but... not. (PIC included)

    Oh, the 3d texture is in
    Code :
    unsigned char bmp[4][512][512][3]
    //[depth][height][width][rgb]
    And gui_bmp does point to bmp, I meant to change that for clarity as there is no reason for it anymore.

    I'm having some kind of misunderstanding even though both textures are intact. They are rendered as one texture of 512x1024x3 for some reason. Notice how this quad with tex coords from 0,0 to 1,1 is rendering the 512x1024 monstrocity twice from left to right.

    And I just realized my pic is from calling glTexImage3d and giving the texture a depth of 2, not 4 like I wrote above. Here's what it looks like with 4, as you can see, it then repeats 4 times left to right and the texture is now 512x2048.

  5. #5
    Senior Member Regular Contributor
    Join Date
    Aug 2003
    Posts
    369

    Re: glTexImage3D works! but... not. (PIC included)

    Hmm, as I've said, maybe opengl does not expect having such a big array. Can't you change it to a single pointer to GLubyte for each image;

  6. #6
    Senior Member Regular Contributor
    Join Date
    Jan 2004
    Posts
    314

    Re: glTexImage3D works! but... not. (PIC included)

    OK. Something else (I had to look it up first):

    According to the bluebook, it's:
    void glTexCoord3d( GLdouble s, GLdouble t, GLdouble r )
    That means that the slice is the third parameter, not the first.
    Which would explain why the top part is different from the bottom half.
    But I don't know why you're not getting interpolation.

  7. #7
    Member Newbie
    Join Date
    Jun 2005
    Posts
    42

    Re: glTexImage3D works! but... not. (PIC included)

    DVM, I'm not sure how I could store the array differently. A GLubyte is the same as an unsigned char, right? And I think openGL just reads 4*512*512*3 bytes in memory after my pointer, so the number of arrays wouldn't matter. Although... maybe I'll take a closer look and make sure the textures aren't losing resolution somehow.

  8. #8
    Member Newbie
    Join Date
    Jun 2005
    Posts
    42

    Re: glTexImage3D works! but... not. (PIC included)

    Its true, they listed the texture coord axes in a different order but its all relative!

  9. #9
    Senior Member Regular Contributor
    Join Date
    Aug 2003
    Posts
    369

    Re: glTexImage3D works! but... not. (PIC included)

    Well, for what I know even if I have a 1-D or 2-D texture I go on declaring it as a
    GLubyte *bmpData;
    Spot on for Glubyte being an unsigned char. I really don't know how opengl is reading the data, I'm just guessing since you have problems. Maybe you could try creating a small 4-D array and see in the debugger how the memory is mapped out.
    My guess is that gl reads the first row_length * color_components * components_size bytes for each row. Then it reads the next row etc for image height . Then it goes to the next slice until it has all the slices. It's a bit hard as a concept to start with, 3D textures. Good luck!

  10. #10
    Senior Member Regular Contributor
    Join Date
    Jan 2004
    Posts
    314

    Re: glTexImage3D works! but... not. (PIC included)

    OK. Now I'm confused:

    According to what I've read (and according to the description of the various versions of texcoord in the bluebook), the r coordinate selects the slice, and s and t select the horizontal/vertical.
    </font><blockquote><font size="1" face="Verdana, Arial">code:</font><hr /><pre style="font-size-small; font-family: monospace;"> +--------+
    +--------+2|
    +--------+1| |
    |t 0| | |
    |^ | | |

Page 1 of 2 12 LastLast

Similar Threads

  1. Can GL_SHADER_STORAGE_BUFFER be included in a VAO?
    By David Lofstrand in forum OpenGL: Advanced Coding
    Replies: 4
    Last Post: 08-29-2014, 08:36 AM
  2. What is included?:
    By Running_Wolf in forum OpenGL: GLSL
    Replies: 1
    Last Post: 12-27-2004, 12:24 PM
  3. What's wrong here? (code included)
    By Andrewinator in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 01-08-2004, 04:13 PM
  4. PIVOTING--HELP! code included
    By Andrewinator in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 11-17-2003, 02:25 PM
  5. When will it be included in the drivers ?
    By fuxifuxi in forum OpenGL: Advanced Coding
    Replies: 0
    Last Post: 11-06-2003, 09:01 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean