PDA

View Full Version : glColor and GL_LINES



bingofuel
6th January 2010, 02:08
hi!.
I'm using Qt 4.6 in GNU/Linux. i'm working with QGLWidget with kind of easiness but i've a problem when i want to change the color of the Lines.
I've tried all the combinations that i could think.
i've put the glColor after and befor de glBegin, use the qglColor, and glColor3f (and others glColors functions). But always it's a random color between blue and green (never red (i don't know why)).
What am i missing?



glBegin(GL_LINES);
glColor3f(1.0f,0.0,0.0);
glVertex2f(50,1);
glVertex2f(120,1);
glEnd()
;

this very basic code doesn't work



void Plot::paintGL()
{
glBegin(GL_LINES);
glColor3f(1.0f,0.0,0.0);
glVertex2f(50,1);

glVertex2f(120,1);
glEnd();
}

void Plot::initializeGL()
{
// Also i've tried a lot of combinations here. GL_FLAT and others.
glClearColor(1.0, 1.0 , 1.0, 0.0);
glLoadIdentity();
glTranslatef(0,0.0,0);
glDisable(GL_TEXTURE_2D);
glDisable(GL_LIGHTING);
glShadeModel(GL_SMOOTH);

}


void Plot::resizeGL(int w, int h)
{
glViewport( 0, 0, (GLint)w, (GLint)h );
glMatrixMode( GL_PROJECTION );
glLoadIdentity();

glOrtho( 0, 800, yMin, yMax, -5.0, 1.0 );
glMatrixMode( GL_MODELVIEW );

}

jcox23
6th January 2010, 11:34
I dont see any:
glClear(GL_CLEAR_COLOR_BUFFER_BIT | GL _DEPTH_BUFFER_BIT)
at the beginning of your paintGL() routine...

is that on purpose?

bingofuel
6th January 2010, 14:55
I dont see any:
glClear(GL_CLEAR_COLOR_BUFFER_BIT | GL _DEPTH_BUFFER_BIT)
at the beginning of your paintGL() routine...

is that on purpose?

yes, is on porpouse beacouse i'm writing an application that don't erase the screen every frame.
But is the same thing with the color clearing the buffers or not :s


void Plot::paintGL()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glBegin(GL_LINES);
glColor3f(1.0f,0.0,0.0);
glVertex2f(50,1);

glVertex2f(120,1);
glEnd();
}

jcox23
6th January 2010, 21:27
I just copied/pasted your code into the hellogl example....and it's working as intended... (line is red)
so the code is probably ok...

are the Qt OpenGL examples working alright?

mpi
7th January 2010, 07:12
Could be a driver issue. What platform are you running on? What OpenGL driver do you use?

Mads

bingofuel
12th January 2010, 02:08
i'm using a x86 GNU/Linux with an ATI raden 9550 using the open-source drivers ( xf86-video-ati 6.12.4-3 )
Mesa Version mesa 7.7-1

i've tried in a machine with xp and works fine.

ralfi102
7th December 2011, 18:20
if you have


glEnable(GL_LIGHTING);

then you should have


glColorMaterial ( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE );
glEnable ( GL_COLOR_MATERIAL );

otherwise glColor3f() has no meaning at all..