Unecpected colours in GL_COLOR_ARRAY with glDrawArrays>GL_LINE_STRIP

<pyopengl 3.0.2>

<pyhton 2.7>

<wxpython 2.8.12.0> & <wxpython 3.0.0.0>

Hi !

I made a small change in NeHe's Lesson48.py file in Draw() function and made it look like this :

import numpy as np;
def Draw ():
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
NumpyDraw(); glFlush ();
glutSwapBuffers()
return;

#array = np.array([[0.0, 0.0, 0.0], [1.0, 0, 0], [0.0, 1.0, 0]]);
#colNpArray = np.array([[255, 255, 255], [255, 0, 0], [0, 255, 0]], dtype=np.ubyte);
#print type(array), array
#print type(colNpArray), colNpArray

def NumpyDraw():
array = np.array([[0.0, 0.0, 0.0], [1.0, 0, 0], [0.0, 1.0, 0]]);
colNpArray = np.array([[255, 255, 255], [255, 0, 0], [0, 255, 0]], dtype=np.ubyte);

glEnableClientState(GL_COLOR_ARRAY)
glEnableClientState(GL_VERTEX_ARRAY)

glVertexPointer(3, GL_FLOAT, 0, array);
glColorPointer(3, GL_UNSIGNED_BYTE, 0, colNpArray)

glDrawArrays( GL_LINE_STRIP, 0, len(array));

glDisableClientState(GL_COLOR_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);

return;

This gave me a Red Horizontal line and Green Vertical line as a result (using glutCreateWindow, glutMainLoop).

<win7 32bit>, but it did gave a white horizontal line and a red vertical line on other 4-PC’c all being win7 32-bit

except for one 64-bit.

<pyopengl 3.0.2>

<pyhton 2.7>

<wxpython 2.8.12.0>

When tried with 3.0.0.0 it gave a line with two colours merging rightin the centre on the line.

<pyopengl 3.0.2>

<pyhton 2.7>

<wxpython 3.0.0.0>

I expected consistency as my next try would be ‘object picking’ using glReadPixel with hundreds of unique colours and

objects.

Also how is this suppose to work, I want one colour line how can I achieve it ?

-Rushabh

You have two line strips and three colors. I couldn’t find any
document that described how that was supposed to be handled. Is it
specified by OpenGL?

···

Rushabh wrote:

Hi !

       I

made a small change in NeHe’s Lesson48.py file in Draw()
function and made it look like this :

      def NumpyDraw():

                   array

= np.array([[0.0, 0.0, 0.0], [1.0, 0, 0], [0.0, 1.0, 0]]);

                   colNpArray

= np.array([[255, 255, 255], [255, 0, 0], [0, 255, 0]],
dtype=np.ubyte);

         glEnableClientState(GL_COLOR_ARRAY)

       glEnableClientState(GL_VERTEX_ARRAY)



                     glVertexPointer(3,

GL_FLOAT, 0, array);

                   glColorPointer(3,

GL_UNSIGNED_BYTE, 0, colNpArray)

                     glDrawArrays(

GL_LINE_STRIP, 0, len(array));

         glDisableClientState(GL_COLOR_ARRAY);

       glDisableClientState(GL_VERTEX_ARRAY);



         return;
-- Tim Roberts, Providenza & Boekelheide, Inc.

timr@probo.com

Yes length of vertex array & color array should be same in size (tutorial, tutorial, tutorial) & also this simple code do works on all of my test PC’s using glutWindow in same way & as expected. I think it is something with glCanvas simply because it runs well with pyOpenGL + glutCreateWindow.

···

On Monday, June 2, 2014 10:55:07 PM UTC+5:30, Tim Roberts wrote:

Rushabh wrote:

Hi !

       I

made a small change in NeHe’s Lesson48.py file in Draw()
function and made it look like this :

      def NumpyDraw():

                   array

= np.array([[0.0, 0.0, 0.0], [1.0, 0, 0], [0.0, 1.0, 0]]);

                   colNpArray

= np.array([[255, 255, 255], [255, 0, 0], [0, 255, 0]],
dtype=np.ubyte);

         glEnableClientState(GL_COLOR_ARRAY)

       glEnableClientState(GL_VERTEX_ARRAY)



                     glVertexPointer(3,

GL_FLOAT, 0, array);

                   glColorPointer(3,

GL_UNSIGNED_BYTE, 0, colNpArray)

                     glDrawArrays(

GL_LINE_STRIP, 0, len(array));

         glDisableClientState(GL_COLOR_ARRAY);

       glDisableClientState(GL_VERTEX_ARRAY);



         return;
You have two line strips and three colors.  I couldn't find any

document that described how that was supposed to be handled. Is it
specified by OpenGL?

-- Tim Roberts, ti...@probo.com
Providenza & Boekelheide, Inc.

Yes, of course you’re right. Each color is associated with a
vertex, not with a line. So, your wxPython 3.0.0 result is the
correct one – a horizontal line going from white to red, and a
vertical line to going from red to green. That’s what I get when I
run your code in C (that is, once I change the third coordinate to
1.0, 1.0, 0.0).
Interesting that wxPython 2.8 gets different results. wxPython
shouldn’t be doing any of the drawing; it should just be passing the
calls through to OpenGL.

···

Rushabh wrote:

    Yes length of vertex array & color array should

be same in size (tutorial, tutorial, tutorial )
& also this simple code do works on all of my test PC’s
using glutWindow in same way & as expected.

-- Tim Roberts, Providenza & Boekelheide, Inc.

timr@probo.com

Hi !

I found that glShadeModel(GL_SMOOTH) was giving that dual colors on single line strip, changing it to **GL_FLAT**gave single color. But still I’m getting <Red horizontal & Green Vertical line strips> on one PC and <White horizontal & Red Vertical line strips> on other.

I've attached my code, Am I doing any thing wrong ?

-Rushabh

test.py (3.68 KB)

Red horizontal and green vertical is the correct rendering. With
GL_FLAT, the color of each line segment is given by the color of the
second vertex.
Sounds like you found a bug in that machine’s OpenGL renderer. Does
that machine have a cheap graphics card?

···

Rushabh wrote:

Hi !

I found that glShadeModel(GL_SMOOTH) * was
giving that dual colors on single line strip, changing it to GL_FLAT
* gave single
color. But still I’m getting <Red horizontal
& Green Vertical line strips> on one PC and <White
horizontal & Red Vertical line strips> on other.

-- Tim Roberts, Providenza & Boekelheide, Inc.

timr@probo.com

*Red horizontal and green vertical is the correct rendering. *

  • With
    GL_FLAT, the color of each line segment is given by the color of the
    second vertex.*

Yes, even I expected the same.

  • Sounds like you found a bug in that machine’s OpenGL renderer. Does
    that machine have a cheap graphics card?*

If this would be the scenario then pyOpenGL’s glut window would also have give the different result.

My point is that on same hardware & with same software if glut is giving expected results then why not glCanvas ?

I also posted this in (wxpython-users group) here for this reason.

I’ve also attached glutTest.py & wxTest.py

glutTest.py (2.14 KB)

wxTest.py (3.5 KB)