GL_LUMINANCE8 problem on 2D Texture

  • Follow


Hi members,

I have a problem with 2D Texture mapping.
To reduce memory, I tried to use GL_LUMINANCE8 instead of GL_RGBA as
follows;


	static GLubyte teximg1[TEX_HEIGHT][TEX_WIDTH];
	glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
	glGenTextures(3, texname);
	unsigned char *data1 = imageZ->GetData();
	for(int y = 0; y < height; y++)
	{
		for(int x = 0; x < width; x++)
		{
			long pos = (y * width + x) * 3;

			teximg1[height - 1 - y][x] = (GLubyte)data1[pos + 0];
		}
	}
	glBindTexture(GL_TEXTURE_2D, texname[0]);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
//	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, TEX_WIDTH, TEX_HEIGHT, 0,
GL_RGBA, GL_UNSIGNED_BYTE, teximg);
	glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE8, TEX_WIDTH, TEX_HEIGHT,
0, GL_LUMINANCE, GL_UNSIGNED_BYTE, teximg1);


But, unfortunately it has failed and the texture region is entirely
white.
I think the cause may be the version of OpenGL or Graphic driver.
I investigated my integrated chip with OpenGL Extensions Viewer and
found as follows;

  Renderer :  Intel 965/963 Graphics Media Accelerator
  Adapter RAM :   256 MB
  OpenGL verion : 1.5
  Graphic driver version :  6.14.10.4864

If you have any idea, please let me know.
0
Reply maty 3/6/2010 5:51:37 AM

In article <567679c9-0f0a-431d-98ff-f7622a3ea0b7@f17g2000prh.googlegroups.com>, 
m-ishihara@3zweb.co.jp says...
> 
> Hi members,
> 
> I have a problem with 2D Texture mapping.
> To reduce memory, I tried to use GL_LUMINANCE8 instead of GL_RGBA as
> follows;
> 
> 
> 	static GLubyte teximg1[TEX_HEIGHT][TEX_WIDTH];
> 	glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
> 	glGenTextures(3, texname);
> 	unsigned char *data1 = imageZ->GetData();
> 	for(int y = 0; y < height; y++)

Is it safe to assume width == TEX_WIDTH, height == TEX_HEIGHT ?

> 	{
> 		for(int x = 0; x < width; x++)
> 		{
> 			long pos = (y * width + x) * 3;
> 

You are just using the red color component?

> 			teximg1[height - 1 - y][x] = (GLubyte)data1[pos + 0];
> 		}
> 	}
> 	glBindTexture(GL_TEXTURE_2D, texname[0]);
> 	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
> 	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
> //	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, TEX_WIDTH, TEX_HEIGHT, 0,
> GL_RGBA, GL_UNSIGNED_BYTE, teximg);
> 	glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE8, TEX_WIDTH, TEX_HEIGHT,
> 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, teximg1);
>

Do you set up the pixel format via glPixelStore? I think this defaults to 4 
bytes for the row alignment.
 
> 
> But, unfortunately it has failed and the texture region is entirely
> white.
> I think the cause may be the version of OpenGL or Graphic driver.
> I investigated my integrated chip with OpenGL Extensions Viewer and
> found as follows;
> 
>   Renderer :  Intel 965/963 Graphics Media Accelerator
>   Adapter RAM :   256 MB
>   OpenGL verion : 1.5
>   Graphic driver version :  6.14.10.4864
> 
> If you have any idea, please let me know.

I doubt if the problem is in the driver. If you are loading the data correctly, 
the next most likely cause is the application of the texture, i.e. are you 
setting up the correct modes when drawing the polygon.


Peter
0
Reply Peter 3/6/2010 5:16:42 PM


On Mar 6, 6:51=A0am, maty <m-ishih...@3zweb.co.jp> wrote:
>
> If you have any idea, please let me know.

Are you getting an error code via glGetError()?


If you are, which function is failing?

If you aren't, you might be doing something
wrong somewhere else in your program.

--
<\___/>
/ O O \
\_____/  FTB.

http://www.topaz3d.com/  - New 3D editor for real time simulation
0
Reply fungus 3/6/2010 6:06:18 PM

Hellow Peter,

Thank you for your advice.

> Is it safe to assume width == TEX_WIDTH, height == TEX_HEIGHT ?

Yes, width equals TEX_WIDTH or under, height as the same.

> You are just using the red color component?

The image is monochrome so there is nothing different among red, green
and blue.

> Do you set up the pixel format via glPixelStore? I think this defaults to 4
> bytes for the row alignment.

Yes, I set up the pixel format via glPixelStore as follows;

>    glPixelStorei(GL_UNPACK_ALIGNMENT, 1);


> I doubt if the problem is in the driver. If you are loading the data correctly,
> the next most likely cause is the application of the texture, i.e. are you
> setting up the correct modes when drawing the polygon.

I'm sorry I don't know about modes when drawing the polygon.
Please let me know the detail about the mode.

Thanks,

Maty
0
Reply maty 3/8/2010 5:21:55 AM

Hello FTB,



> Are you getting an error code via glGetError()?

I tried using glGetError() some times, but there is no error.

> If you aren't, you might be doing something
> wrong somewhere else in your program.

I have no idea, the place where is wrong.

Thanks,

Maty

0
Reply maty 3/8/2010 5:25:15 AM

maty wrote:
> Hello FTB,
> 
> 
> 
>> Are you getting an error code via glGetError()?
> 
> I tried using glGetError() some times, but there is no error.
> 
>> If you aren't, you might be doing something
>> wrong somewhere else in your program.
> 
> I have no idea, the place where is wrong.
> 

Maybe the rendering is wrong. How do you display your texture?
0
Reply Vladimir 3/8/2010 8:31:08 AM

Hello FTB,

Thank you for your quick reply.

> Maybe the rendering is wrong. How do you display your texture?

I don't use any specific renderers, but just buffer swapping as
follows;

glFlush();
SwapBuffers();

According to your opinion, this way seems to be wrong?

Thanks,

Maty
0
Reply maty 3/8/2010 10:29:24 AM

maty wrote:
>> Maybe the rendering is wrong. How do you display your texture?
> 
> I don't use any specific renderers, but just buffer swapping as
> follows;
> 
> glFlush();
> SwapBuffers();
> 
> According to your opinion, this way seems to be wrong?
> 

Remove glFlush(), and show what you do before that. The 
glBegin()/glEnd() block
0
Reply Vladimir 3/8/2010 10:39:54 AM

On 3=E6=9C=888=E6=97=A5, =E5=8D=88=E5=BE=8C7:39, Vladimir Jovic <vladasp...=
@gmail.com> wrote:
> maty wrote:
> >> Maybe the rendering is wrong. How do you display your texture?
>
> > I don't use any specific renderers, but just buffer swapping as
> > follows;
>
> > glFlush();
> > SwapBuffers();
>
> > According to your opinion, this way seems to be wrong?
>
> Remove glFlush(), and show what you do before that. The
> glBegin()/glEnd() block

Thanks FTB.
I eliminated glFlush(), but it can't fix the problem.
Next, my glBegin()/glEnd() block is as follows;

		glBegin(GL_QUADS);
		glTexCoord2f(0.0, 0.0);						glVertex3f(-w, -ry,-v);
		glTexCoord2f(0.0, ratio_voxel);				glVertex3f(-w, -ry, v);
		glTexCoord2f(ratio_width, ratio_voxel);		glVertex3f( w, -ry, v);
		glTexCoord2f(ratio_width, 0.0);				glVertex3f( w, -ry,-v);
		glEnd();

Thanks,

Maty
0
Reply maty 3/8/2010 11:03:40 AM

"maty" <m-ishihara@3zweb.co.jp> wrote in message 
news:2dc28db3-37f2-40d9-8260-8e9f66007908@s36g2000prf.googlegroups.com...
On 3?8?, ??7:39, Vladimir Jovic <vladasp...@gmail.com> wrote:
> maty wrote:
> >> Maybe the rendering is wrong. How do you display your texture?
>
> > I don't use any specific renderers, but just buffer swapping as
> > follows;
>
> > glFlush();
> > SwapBuffers();
>
> > According to your opinion, this way seems to be wrong?
>
> Remove glFlush(), and show what you do before that. The
> glBegin()/glEnd() block

!Thanks FTB.
!Next, my glBegin()/glEnd() block is as follows;

!glBegin(GL_QUADS);
!glTexCoord2f(0.0, 0.0); glVertex3f(-w, -ry,-v);
!glTexCoord2f(0.0, ratio_voxel); glVertex3f(-w, -ry, v);
!glTexCoord2f(ratio_width, ratio_voxel); glVertex3f( w, -ry, v);
!glTexCoord2f(ratio_width, 0.0); glVertex3f( w, -ry,-v);
!glEnd();

!Thanks,

!Maty


Maty,
   I think you are misunderstanding some fundamentals. Without blending, and 
by default, you get your texture superimposed on your slices. Now, white on 
white = white, whereas colored textures on white gives you some color. But 
this isn't 3D texture mapping in a volumetric sense -- you aren't seeing the 
volume as a whole with bits of it visible as a function of alpha.

For volumetric volume rendering, as in bone in a CAT scan or MRI, (very 
simply...)you want to "classify" the bone as an opaque range of values, and 
other stuff as more transparent so you can "see through" the "skin".

So, you need to have ALPHA BLENDING turned on, as you are compositing slices 
back-to-front, and you want the
bone to add up but you don't want the skin to be so much visible;

Try this -- I'll bet it works

If it does, then a TLUT shader will get you color.

jbw

=================================================
/*
 * Shows a 3D texture by drawing slices through it.
 */
/* compile: cc -o tex3d tex3d.c -lglut -lGL  */


#include <GL/glu.h>
#include <GL/glut.h>

#include <stdio.h>


unsigned char tex[64][64][64];

/* generate a simple 3D texture */
static void
make_texture(void) {
    int i, j, k;
    unsigned char *p = &tex[0][0][0];

    for (i=0; i<64; i++) {
        for (j=0; j<64; j++) {
            for (k=0; k<64; k++) {
                if (i < 10 || i > 48 ||
                    j < 10 || j > 48 ||
                    k < 10 || k > 48) {
                    if (i < 2 || i > 62 ||
                        j < 2 || j > 62 ||
                        k < 2 || k > 62) {
                        *p++ = 0x00000000;
                    } else {
                        *p++ = 255;
                    }
                } else {
                    *p++ = 0;
}
            }
        }
    }
}

static void
init(void) {
    make_texture();
    glEnable(GL_TEXTURE_3D_EXT);
    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE);
    glClearColor(0.,0.,0.,.0);
    glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

    glMatrixMode(GL_PROJECTION);
    gluPerspective(60.0, 1.0, 1.0, 100.0 );
    glMatrixMode(GL_MODELVIEW);
    glTranslatef(0.,0.,-3.0);
    glMatrixMode(GL_TEXTURE);


    /* Similar to defining a 2D texture, but note the setting of the */
    /* wrap parameter for the R coordinate.  Also, for 3D textures   */
    /* you probably won't need mipmaps, hence the linear min filter. */
    glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
    glTexParameteri(GL_TEXTURE_3D_EXT, GL_TEXTURE_MIN_FILTER,
                                                         GL_LINEAR);
    glTexParameteri(GL_TEXTURE_3D_EXT, GL_TEXTURE_WRAP_S, GL_CLAMP);
    glTexParameteri(GL_TEXTURE_3D_EXT, GL_TEXTURE_WRAP_T, GL_CLAMP);
    glTexParameteri(GL_TEXTURE_3D_EXT, GL_TEXTURE_WRAP_R_EXT,
                                                          GL_CLAMP);
    glTexImage3DEXT(GL_TEXTURE_3D_EXT, 0, GL_COMPRESSED_INTENSITY, 64, 64, 
64, 0,
                    GL_LUMINANCE, GL_UNSIGNED_BYTE, tex);
}

#define NUMSLICES 256
static int inited = 0;
static void
draw_scene(void) {
    int i;
    float r, dr, z, dz;

    if (!inited) {
        init();
        inited = 1;
    }
    glColor4f(1, 1, 1, 1.4/NUMSLICES);
    glClear(GL_COLOR_BUFFER_BIT);
    /* Display the entire 3D texture by drawing a series of quads */
    /* that  slice through the texture coordinate space.  Note that */
    /* the transformations below are applied to the texture matrix, */
    /* not the modelview matrix. */

    glLoadIdentity();
    /* center the texture coords around the [0,1] cube */
    glTranslatef(.5,.5,.5);
    /* a rotation just to make the picture more interesting */
    glRotatef(45.,1.,1.,.5);

    /* to make sure that the texture coords, after arbitrary */
    /* rotations, still fully contain the [0,1] cube, make them span */
    /* a range sqrt(3)=1.74 wide */
    r = -0.87; dr = 1.74/NUMSLICES;
    z = -1.00; dz = 2.00/NUMSLICES;
    for (i=0; i < NUMSLICES; i++) {
        glBegin(GL_TRIANGLE_STRIP);
        glTexCoord3f(-.87,-.87,r); glVertex3f(-1,-1,z);
        glTexCoord3f(-.87, .87,r); glVertex3f(-1, 1,z);
        glTexCoord3f( .87,-.87,r); glVertex3f( 1,-1,z);
        glTexCoord3f( .87, .87,r); glVertex3f( 1, 1,z);
        glEnd();
        r += dr;
        z += dz;
    }
   glutSwapBuffers();
   printf(".");
   sleep(1);
}

/* process input and error functions and main(), which handles window
 * setup, go here.
 */

int
main(int argc, char **argv)
{
  glutInit(&argc, argv);
  glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
  glutCreateWindow("glut3d");
  glutDisplayFunc(draw_scene);
  glutIdleFunc(draw_scene);
  glutMainLoop();
  return 0;             /* ANSI C requires main to return int. */
}


0
Reply jbwest 3/9/2010 3:24:34 AM

Hi jbw,

Thank you for your perfect program using 3D Texture.
After reading your reply, I immediately tried executing the program.
Then, I succeeded in 3D Texture mapping using GL_LUMINANCE.
From now on, I will investigate the program to apply to my OpenGL
program.

Thanks,

Maty
0
Reply maty 3/10/2010 10:04:31 AM

"maty" <m-ishihara@3zweb.co.jp> wrote in message 
news:0081083e-f03a-4de1-97a6-d67a756a6b0a@z10g2000prh.googlegroups.com...
> Hi jbw,
>
> Thank you for your perfect program using 3D Texture.
> After reading your reply, I immediately tried executing the program.
> Then, I succeeded in 3D Texture mapping using GL_LUMINANCE.
> From now on, I will investigate the program to apply to my OpenGL
> program.
>
> Thanks,
>
> Maty

You are welcome. They key is the alpha blending. Disable blending and that 
test turns intoa white box.

jbw


0
Reply jbwest 3/11/2010 4:00:49 AM

11 Replies
207 Views

(page loaded in 0.263 seconds)

Similiar Articles:




7/24/2012 1:02:16 AM


Reply: