View Full Version : glColorMaterial()'s bug ?

05-12-2004, 08:41 AM
Hi there,

I work on a project with OpenGL and SDL. When I use:
to set the material properties automatically when I issue glColor*(), it doesnt seem to function correctly.

My scene is composed of a world with GL_LIGHT0 activated and a GUI drawn without any light. Of course, I disable GL_LIGHT0, GL_COLOR_MATERIAL and GL_LIGHTING when I draw the GUI. However the last glColor*() I use to draw the GUI modifies the properties of GL_LIGHT0 or/and the material properties. My world which is drawn before the GUI is lighted with the color I set when I draw the GUI after the world.

However, when I replace the
by "many" calls to
everything works well.

I don't know if it's whether driver's bug or the kernel's bug or the XFree's.
Please help !

Here is a screenshot of the world and the GUI (without any light enabled) http://opencity.sourceforge.net/screenshots/opencity-0.0.2-rmb.png

================================================== ===
Development platform:
Linux 2.4.22, gcc-3.3.1 (GCC) 3.3.1 (Mandrake Linux 9.2 3.3.1-2mdk)

================================================== ===
Model: Medion Microstar laptop computer
Processor: P-IV 2.4 GHz - 768 Mb RAM
OS: Linux 2.4.22 - 256 Mb swap; WinXP - 1Gb swap
Patches: drm, fb (mdk for Linux)
Soundcard: SiS SI7012 (driver intel8x0 with ALSA)
Videocard: ATI Radeon 9000 M - 64 Mb
Resolution: 1024x768
DVD/CDR/RW drive

================================================== ===
SDL version 1.2.5

================================================== ===
GL Vendor: 'Tungsten Graphics, Inc.'
GL Renderer: 'Mesa DRI R200 20020827 AGP 4x x86/MMX/SSE TCL'
GL Version: '1.2 Mesa 4.0.4'
GL Extensions: 'GL_ARB_imaging GL_ARB_multitexture GL_ARB_texture_env_add GL_ARB_texture_env_combine GL_ARB_texture_env_dot3 GL_ARB_transpose_matrix GL_EXT_abgr GL_EXT_bgra GL_EXT_blend_color GL_EXT_blend_logic_op GL_EXT_blend_minmax GL_EXT_blend_subtract GL_EXT_clip_volume_hint GL_EXT_convolution GL_EXT_compiled_vertex_array GL_EXT_histogram GL_EXT_packed_pixels GL_EXT_polygon_offset GL_EXT_rescale_normal GL_EXT_secondary_color GL_EXT_stencil_wrap GL_EXT_texture3D GL_EXT_texture_env_add GL_EXT_texture_env_combine GL_EXT_texture_env_dot3 GL_EXT_texture_filter_anisotropic GL_EXT_texture_object GL_EXT_texture_lod_bias GL_EXT_vertex_array GL_IBM_rasterpos_clip GL_MESA_pack_invert GL_MESA_ycbcr_texture GL_MESA_window_pos GL_NV_texgen_reflection GL_NV_texture_rectangle GL_SGI_color_matrix GL_SGI_color_table'

================================================== ===
XFree86 Version 4.3.0
Release Date: 9 May 2003
X Protocol Version 11, Revision 0, Release 6.6
Build Operating System: Linux 2.4.18-23mdksmp i686 [ELF]
Build Date: 10 September 2003
Before reporting problems, check http://www.XFree86.Org/
to make sure that you have the latest version.
Module Loader present

05-12-2004, 09:14 AM
I don't think its a bug, its actually the intended behavior of glColorMaterial.
Look at #14, http://www.opengl.org/resources/features/KilgardTechniques/oglpitfall/
if I understand you correctly this is what is happening

05-13-2004, 07:55 AM
Hi there,

Thank you for your answer but it's not the problem of glColorMaterial() and glEnable()'s orders. My problem can be represented by this listing:

void display(void)
glEnable( GL_LIGHTING );
glEnable( GL_LIGHT0 );

glColor4ub( 255, 0, 0, 255 ); //red
glBegin( GL_TRIANGLES );
// some vertices here

glDisable( GL_LIGHTING );
glDisable( GL_LIGHT0 );



void renderGUI(void)
glColor4ub( 0, 255, 0, 255 ); //green
glBegin( GL_QUADS );
// some vertices here
}Let's say, in the main loop, I call display() every 50ms. At the first call, I have the triangles rendered in RED as expected. But from the second call and so on, the triangles are drawn with a blended color between RED and GREEN.

Another solution that I've found is to insert a call to glColor as

glColor4ub( 255, 255, 255, 255 );

before I call


So can you tell me why ? If you want more informations on my project, don't hesitate to ask.