PDA

View Full Version : Multitexturing problems in pbuffer?



alantangcs
12-01-2003, 09:16 PM
Hi all,

Does anyone know if there are any issues when using multitexturing on a pbuffer?

Right now, I have written a tile engine and using register combiners to create a dynamic lightmap for the scene. I think I have set everything up correctly.

wglMakeCurrent( hdc_pbuffer, rc_pbuffer );
// Set up an ortho projection
glMatrixMode( GL_PROJECTION );
glLoadIdentity( );
glPushMatrix( );
gluOrtho2D( 0, 512, 0, 512 );

// I have disabled stage 1 and got rid of
// the texture combiners already to narrow
// down the problem
glActiveTextureARB( GL_TEXTURE0_ARB );
glEnable( GL_TEXTURE_2D );
glBindTexture( GL_TEXTURE_2D, normalmap );
glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE );

glActiveTextureARB( GL_TEXTURE1_ARB );
glDisable( GL_TEXTURE_2D );

glDisable( GL_BLEND );
glDisable( GL_LIGHTING );
glDisable( GL_COLOR_MATERIAL );

// Draw the texture to the pbuffer
glColor4f( 1.f, 0.f, 0.f, 1.f );
glBegin( GL_QUADS );
glTexCoord2i( 0, 0 );
glVertex3i( 0, 0, 0 );
glTexCoord2i( 1, 0 );
glVertex3i( 100, 0, 0 );
glTexCoord2i( 1, 1 );
glVertex3i( 100, 100, 0 );
glTexCoord2i( 0, 1 );
glVertex3i( 0, 100, 0 );
glEnd( );

glPopMatrix( );

//glFlush( ); // Makes no difference if used

wglMakeCurrent( hdc_window, rc_window );

Now what I do to test is to just draw a textured quad of the pbuffer to screen. This works fine so I won't bother posting the code.

However, the actual contents of the pbuffer is not what I expected. First of all, the quad I draw in the code above is not textured (it should be because I enabled texturing on stage 0). It IS colored (it should NOT be because I disabled COLOR_MATERIAL). Everything else works fine. It's just the texturing that has me stumped.

And fyi, the code above definitely works on the screen (i.e., if I comment out 'wglMakeCurrent( hdc_pbuffer, rc_pbuffer )', it will draw directly to the screen - and the texturing works fine like that).

This leads me to suspect that there is an issue with multitexturing on pbuffers. Another possibility is that I need to set up the pbuffer slightly differently to allow for multitexturing.

Does anyone have any ideas?

Thanks,

Alan

Relic
12-01-2003, 10:00 PM
Which texparameters has your normalmap?Default filtering is mipmapping. If you didn't download mipmaps initializing the texture object the texture is inconsistent and the unit gets disabled. You'll get no texture and the base color takes over.
Same if you have generated the normalmap in another context and forgot to call wglShareLists to share the texture object IDs.
Add calls to glGetError to find other problems.

alantangcs
12-02-2003, 12:05 AM
Relic,

Thanks for your reply. I set the filtering mode to MAX=LINEAR, MIN=NEAREST elsewhere, so there shouldn't be any mipmapping going on.

As for sharing display lists : I followed samples from the NVidia website. I'm rendering directly to the pbuffer and I don't think they had to share lists in that method - am I correct?

The confusing thing is why it works perfectly when being drawn to the screen, but texturing just 'turns off' when I render to the pbuffer.

Thanks for your help. Have any more suggestions?

Alan

Mazy
12-02-2003, 12:22 AM
Sharelists shares both displaylists and Textures.. without that the textures are only in the rendercontext where they are creates.

Lev
12-02-2003, 12:41 AM
Originally posted by alantangcs:
Relic,

Thanks for your reply. I set the filtering mode to MAX=LINEAR, MIN=NEAREST elsewhere, so there shouldn't be any mipmapping going on.


Filtering modes are per-texture properties, make sure you really set them for that particular texture.

Regards
-Lev

ZbuffeR
12-02-2003, 01:51 AM
I had exactly the same problems (no texture, or ugly artifacts), and it was caused by :

1) mipmaping so double-check your texparameters for this texture AND this context.

2) initializing texture on the wrong context.

You can easily fix those 2 problems by using wglShareLists to share lists and texture objects.