minimum needed to render VertexDomains?

57 views
Skip to first unread message

Josh

unread,
Aug 22, 2018, 2:13:34 PM8/22/18
to pyglet-users
Hi all,

I have what (I thought) is a MWE for drawing primitives with a VertexDomain:
import pyglet
from pyglet.gl import *

if __name__ == '__main__':

    display
= pyglet.window.Window(400, 400)


    domain
= pyglet.graphics.vertexdomain.create_domain('v2i/stream', 'c4b/stream')
    vertex_list
= domain.create(4)
    vertex_list
.vertices = [50, 50, 50, 100, 100, 100, 100, 50]
    vertex_list
.colors = [
                       
255, 255, 255, 255,
                       
255, 0, 0, 255,
                       
0, 255, 0, 255,
                       
0, 0, 255, 255
   
]

   
@display.event
   
def on_draw():
        display
.clear()
        pyglet
.graphics.draw(1, GL_POINTS, ('v2i',(10,20)))
        domain
.draw(GL_POINTS)
               
    pyglet
.app.run()

However, while the single pixel drawn directly by pyglet.graphics.drawshows up, the points from the vertex domain don't. What am I missing?


Neon22

unread,
Aug 23, 2018, 5:50:02 AM8/23/18
to pyglet-users
I might be reading the opengl docs wrong (and I'm not familiar with vertexdomains) but don't you need normals, or a shader as well/instead ?

Joshua Dempster

unread,
Aug 23, 2018, 10:09:53 PM8/23/18
to pyglet...@googlegroups.com
It's certainly possible, I don't know much about OpenGL. But it doesn't look like much else is happening when, say, a sprite is rendered, except a texture is bound. I don't think it should be necessary to bind textures to draw points? Adding normals doesn't help, neither does enabling blend or disabling lighting.

On Thu, Aug 23, 2018 at 5:50 AM Neon22 <neon...@gmail.com> wrote:
I might be reading the opengl docs wrong (and I'm not familiar with vertexdomains) but don't you need normals, or a shader as well/instead ?

--
You received this message because you are subscribed to a topic in the Google Groups "pyglet-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/pyglet-users/WRLoiTtztqM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to pyglet-users...@googlegroups.com.
To post to this group, send email to pyglet...@googlegroups.com.
Visit this group at https://groups.google.com/group/pyglet-users.
For more options, visit https://groups.google.com/d/optout.

Benjamin Moran

unread,
Aug 23, 2018, 10:37:38 PM8/23/18
to pyglet-users
Hi Josh,

There is a typo with the vertex color type. It looks like you want to use 8bit values, so If you change c4b to c4B it should work.

By the way, is there a specific reason you're using Domains directly, instead of just creating a Batch? There is nothing wrong with your approach, but using a Batch might save a bit of boilerplate.

-Ben

Joshua Dempster

unread,
Aug 25, 2018, 9:54:05 AM8/25/18
to pyglet...@googlegroups.com
Thanks Ben! No reason not to use batches, just trying to understand the low-level module.

Joshua Dempster

unread,
Aug 26, 2018, 7:29:29 PM8/26/18
to pyglet...@googlegroups.com
Is there a more efficient way to update large vertex list buffers than vertex_list.attribute = some_iterable? For example, I'm guessing that by default vertex_list.set_attribute is converting the iterable to a ctypes array at some point. If I have the data in a numpy array and access it directly as a ctypes array, could I skip this step?

Benjamin Moran

unread,
Sep 3, 2018, 3:27:25 AM9/3/18
to pyglet-users
Hi Josh,

If you look at the AbstractAttribute class in pyglet/graphics/vertexattribute.py, it might shed some light on things.

The vertex_list attributes are just ctype arrays, which are part of a large buffer. If you look at `domain.attributes`, you can find the buffers there. 
You should be able to move the data directly into those buffers.
Reply all
Reply to author
Forward
0 new messages