Virtual OpenGL Pixel Array

Member
Posts: 100
Joined: 2006.05
Post: #1
I am writing a controller for some 2D panels with a 16x16 array of LED's that is entirely written in Python (with PyOpenGL). I need to write a 'virtual' driver with visualization so I can test it without having to go to the lab all the time. I have the array of tiles set up in 3D space and they render fine (texture and all). What I need to do now is find a way to render the LED's (they have 256 degrees of brightness) on top of the tiles facing in their respective directions (the tiles are not all coplanar).

I want to store each tile's bitmap inside the tile's class as a 16x16 array (or later, possibly another OpenGL context). So far, I've made an initial attempt by rendering GL_QUADS from a pre-initialized list of vertices stored in a Pixel class--an array of which is in turn stored in the Tile class--but this is incredibly slow. Does anyone have any ideas for how I can use OpenGL to render LED like objects (bitmaps, particles, polygons, anything) evenly spaced on top of a textured tile from 16x16 arrays stored in 24 different tiles quickly and efficiently? I would really appreciate it. Thanks

Nevada
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #2
I didn't understand a word of that :|
Quote this message in a reply
Sage
Posts: 1,482
Joined: 2002.09
Post: #3
Yeah, I'm a bit confused as well.

It sounds to me like you just want to make a texture of the LED bitmap, and draw that on a quad. Is that what you meant by "Does anyone have any ideas for how I can use OpenGL to render LED like objects ... evenly spaced on top of a textured tile from 16x16 arrays?"?

Scott Lembcke - Howling Moon Software
Author of Chipmunk Physics - A fast and simple rigid body physics library in C.
Quote this message in a reply
Member
Posts: 100
Joined: 2006.05
Post: #4
Basically, I need a quick way to render LED looking 'things' (Polygons, Lights, Particles, I'm open to anything that's quick). It needs to be quick because I have to render about 16*16*24=6144 of them on each render loop. They each have a brightness value between 0 and 255 and I was originally considering rendering them one at a time, but if someone has a quicker version of doing this, I would like to hear it. Basically I'm taking a 16x16 bitmap (which will be drawn and updated in real time) and breaking it up so I can render each pixel as an LED light for 24 tiles. Looking back at my previous post, I can see that it wasn't worded very well (that last bit was a mouth full). I hope this is more clear.
Quote this message in a reply
Member
Posts: 100
Joined: 2006.05
Post: #5
LED bitmaps were what I had in mind actually. I was wondering if I should put it together as polygons (ie. instead of rendering a textured tile, just make the tile composed of 256 LED textured polygons) or perhaps redraw the texture each loop. Just need something fast.
Quote this message in a reply
Moderator
Posts: 3,577
Joined: 2003.06
Post: #6
According to what you are saying (if I understand it correctly), you could do a square power of two image of 128 x 128 pixels and get 16384 pixels (LED's) out of that every frame without OpenGL flexing a muscle. It sounds like your approach is fine, but something is going terribly wrong with your implementation. You're using glTexSubImage2D right? (I don't know PyOpenGL at all, so I don't understand that connection)
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #7
You want to render 6144 possibly-textured quads with independent color each frame?

Just put all the quad geometry in a vertex array, build the color array each frame, and call DrawArrays or DrawElements. It should be more than fast enough on any hardware.
Quote this message in a reply
MarkJ
Unregistered
 
Post: #8
direct draw would probably be fast enough to render 6500 quads really
Quote this message in a reply
Moderator
Posts: 133
Joined: 2008.05
Post: #9
This also seems like you only need to draw once each time you set a configuration. So you don't need a rendering loop or anything, just draw when something changes. May seem obvious, but you'd be surprised how many people draw something at maximum frames per second when they only need one render.
Quote this message in a reply
Member
Posts: 100
Joined: 2006.05
Post: #10
You guys were right about OpenGL, it wasn't the drawing commands that were slowing it down. I took them out and had my pixel rendering code pass. It was still way too slow. Apparently there is a lot of overhead in what I did. My code basically looks like this:

Code:
for tile in self.tiles:
            for pixel in tile.pixels:
                pass
                """
                glColor3f(pixel.val/256, pixel.val/256, pixel.val/256)
                glTexCoord2d(0.0, 0.0)
                glVertex3f(pixel.vert0[0], pixel.vert0[1], pixel.vert0[2])
                glTexCoord2d(0.0, 1.0)
                glVertex3f(pixel.vert1[0], pixel.vert1[1], pixel.vert1[2])
                glTexCoord2d(1.0, 1.0)
                glVertex3f(pixel.vert2[0], pixel.vert2[1], pixel.vert2[2])
                glTexCoord2d(1.0, 0.0)
                glVertex3f(pixel.vert3[0], pixel.vert3[1], pixel.vert3[2])
                """

I guess I'll have to work at a higher level (rather than iterating through two lists of classes).

LongJumper Wrote:This also seems like you only need to draw once each time you set a configuration. So you don't need a rendering loop or anything, just draw when something changes. May seem obvious, but you'd be surprised how many people draw something at maximum frames per second when they only need one render.

The pixels are updated (well, their color values are at least) every cycle.
Quote this message in a reply
Sage
Posts: 1,482
Joined: 2002.09
Post: #11
Use vertex arrays like OSC said. It will reduce the number of functioncalls you need to make by orders of magnitudes. Using several method calls for each of a few thousand vertexes is going to be way slow.

Scott Lembcke - Howling Moon Software
Author of Chipmunk Physics - A fast and simple rigid body physics library in C.
Quote this message in a reply
Member
Posts: 100
Joined: 2006.05
Post: #12
I've been trying to implement glDrawArrays, but nothing seems to work. I copied some example code straight from sourceforge and I can't even get that to work. This is the code I used:

Code:
from Numeric import asarray, take
points = asarray([
        [1.000,0.000,0.000],
        [0.959,0.282,0.000],
        [0.841,0.541,0.000],
        [0.655,0.756,0.000],
        [0.415,0.910,0.000],
        [0.142,0.990,0.000],
        [-0.142,0.990,0.000],
        [-0.415,0.910,0.000],
        [-0.655,0.756,0.000],
        [-0.841,0.541,0.000],
        [-0.959,0.282,0.000],
        [-1.000,0.000,0.000],
        [-0.959,-0.282,0.000],
        [-0.841,-0.541,0.000],
        [-0.655,-0.756,0.000],
        [-0.415,-0.910,0.000],
        [-0.142,-0.990,0.000],
        [0.142,-0.990,0.000],
        [0.415,-0.910,0.000],
        [0.655,-0.756,0.000],
        [0.841,-0.541,0.000],
        [0.959,-0.282,0.000],
        [0.000,0.000,0.500],
], 'd')
indices =  asarray([
        22, 1, 2, 22, 3, 4, 22, 5, 6, 22, 7, 8, 22, 9, 10, 22, 11, 12,
        22, 13, 14, 22, 15, 16, 22, 17, 18, 22, 19, 20, 22, 21, 0], 'i')

points_expanded = take( points, indices )

normals = asarray([
        [-0.127,-0.433,0.892],
        [0.244,0.379,0.892],
        [0.410,0.187,0.892],
        [0.000,0.451,0.892],
        [-0.244,0.379,0.892],
        [-0.410,0.187,0.892],
        [0.446,-0.064,0.892],
        [0.341,-0.295,0.892],
        [0.000,0.000,1.000],
        [-0.446,-0.064,0.892],
        [0.127,-0.433,0.892],
        [-0.341,-0.295,0.892],
], 'd')
normalIndices = asarray([
        8, 2, 2, 8, 1, 1, 8, 3, 3, 8, 4, 4, 8, 5, 5, 8, 9, 9, 8, 11,
        11, 8, 0, 0, 8, 10, 10, 8, 7, 7, 8, 6, 6], 'i')

normals_expanded = take( normals, normalIndices )

.
.
.

# I've tried this
glVertexPointerd( points )
glEnableClientState(GL_VERTEX_ARRAY);
glDrawElementsui( GL_TRIANGLES, indices )

...

# This
glVertexPointerd(flower_geometry.points_expanded )
glNormalPointerf(flower_geometry.normals_expanded )
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY);
glDrawArrays(GL_TRIANGLES, 0, len(flower_geometry.points_expanded))

# And this
glVertexPointer(3, GL_DOUBLE, 0, flower_geometry.points_expanded.tostring() );
glNormalPointer(GL_DOUBLE, 0, flower_geometry.normals_expanded.tostring() )
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY);
glDrawArrays(GL_TRIANGLES, 0, len(flower_geometry.points_expanded))

They all just give me a black screen. I really don't know what's going on here (I've never used vertex arrays before).
Quote this message in a reply
Moderator
Posts: 1,140
Joined: 2005.07
Post: #13
The last block is the closest, but try using glDrawRangeElements instead of glDrawArrays, and don't expand the arrays, since that just destroys one of the major advantages of vertex arrays. (there's also glDrawElements, but IIRC glDrawRangeElements is a little bit faster) Also, is there any particular reason why you're transforming the arrays to strings? They are supposed to be passed in as regular arrays. This brings me to my next point: I noticed you use arrays of arrays (or lists of lists), but at least in C, you need to pass in 1 continuous block of data as opposed to an array of arrays. If the Python bindings work in a similar manner, you will need to have all of the points in a single list where every third element is the beginning of a new point.
Quote this message in a reply
Moderator
Posts: 3,577
Joined: 2003.06
Post: #14
Nevada, you seem kind of urgent to get this working for you ASAP (if I may read into it that way). Python really kicks ass, but maybe you would get the help you need much faster if you did it in GLUT first, as a prototype for what you want to do in Python. My guess is that there might not be anyone familiar enough with PyOpenGL on hand here to address your problem directly at the moment.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  OpenGL Pixel Buffer Object setup issue dotbianry 2 3,272 Jan 6, 2013 11:03 AM
Last Post: dotbianry
  iPad Virtual keyboard height = 352 Baldock 0 4,487 Feb 3, 2011 04:36 AM
Last Post: Baldock
  [CoreGraphics] Image manipulation - pixel by pixel g00se 5 10,198 Jul 28, 2010 08:27 AM
Last Post: ThemsAllTook
  Vertex Array & Interleaved Array troubles TomorrowPlusX 5 5,561 Nov 17, 2007 09:59 AM
Last Post: TomorrowPlusX
  Pixel Access in an OpenGL Context? geezusfreeek 6 4,282 Jul 22, 2002 06:43 PM
Last Post: geezusfreeek