First person perspective in an rpg

169 views
Skip to first unread message

Wallace Davidson

unread,
Oct 7, 2012, 10:08:18 PM10/7/12
to pyglet...@googlegroups.com
I am trying to make an rpg from a first person perspective with 2d sprites (similar to doom or wolfenstein 3d) and I understand I probably need to read into the pyglet opengl section of the programming guide. I've read through all I could find that is related and can draw quads and triangles on the screen and move the vertices about, but the thing I don't understand and that has stopped my progress is how to use matrices to do transformations to make the screen first person.

Am I meant to use a camera class (I don't really understand what this does :/ ) or something similar? I am pretty new to the opengl side of things haven't used solely pyglet sprites and textures in the past.

Wallace Davidson

unread,
Oct 7, 2012, 10:09:56 PM10/7/12
to pyglet...@googlegroups.com
I meant to say "I have used pyglet sprites and textures solely in the past"

cheers

Anonymouse

unread,
Oct 10, 2012, 1:34:36 PM10/10/12
to pyglet...@googlegroups.com
You'll want to do the projection in the on_resize handler. As for
drawing the sprites, I think you'll have to do it manually if you set
your own projection. I can't really say much more on the topic because
I don't know much more. Hope it still helps!
> --
> You received this message because you are subscribed to the Google Groups
> "pyglet-users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/pyglet-users/-/Q5kAqdewGPgJ.
>
> To post to this group, send email to pyglet...@googlegroups.com.
> To unsubscribe from this group, send email to
> pyglet-users...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/pyglet-users?hl=en.

Wallace Davidson

unread,
Oct 10, 2012, 4:59:54 PM10/10/12
to pyglet...@googlegroups.com
Thanks that does help :) Would you know how I can get a python matrix usable in opengl? :/ It just says "expected LP_c_float instance instead of matrix" when I try use a numpy one :(

Adam Bark

unread,
Oct 10, 2012, 5:09:02 PM10/10/12
to pyglet...@googlegroups.com
On 10/10/12 21:59, Wallace Davidson wrote:
> Thanks that does help :) Would you know how I can get a python matrix
> usable in opengl? :/ It just says "expected LP_c_float instance
> instead of matrix" when I try use a numpy one :(
>
If you want to use numpy matrices and opengl then get pyopengl, it's a
nicer library anyway as you don't have to mess around with ctypes.

Wallace Davidson

unread,
Oct 10, 2012, 5:11:15 PM10/10/12
to pyglet...@googlegroups.com
I heard it was slower :/ would it be much different?

Adam Bark

unread,
Oct 10, 2012, 5:38:14 PM10/10/12
to pyglet...@googlegroups.com
On 10/10/12 22:11, Wallace Davidson wrote:
I heard it was slower :/ would it be much different?

On Thu, Oct 11, 2012 at 10:09 AM, Adam Bark <adam....@gmail.com> wrote:
On 10/10/12 21:59, Wallace Davidson wrote:
Thanks that does help :) Would you know how I can get a python matrix usable in opengl? :/ It just says "expected LP_c_float instance instead of matrix" when I try use a numpy one :(

If you want to use numpy matrices and opengl then get pyopengl, it's a nicer library anyway as you don't have to mess around with ctypes.


If you're using core opengl it shouldn't make much difference as you won't need to make many calls, immediate mode is where you might find some slowdown. I use it personally and haven't had any performance issues that weren't related to either poor programming on my part or my incredibly old graphics card (NVidia 7950GT).

Wallace Davidson

unread,
Oct 10, 2012, 5:44:45 PM10/10/12
to pyglet...@googlegroups.com
That sounds good then :) It can be used with pyglet can't it?

Adam Bark

unread,
Oct 10, 2012, 6:07:46 PM10/10/12
to pyglet...@googlegroups.com
On 10/10/12 22:44, Wallace Davidson wrote:
That sounds good then :) It can be used with pyglet can't it?

On Thu, Oct 11, 2012 at 10:38 AM, Adam Bark <adam....@gmail.com> wrote:
On 10/10/12 22:11, Wallace Davidson wrote:
I heard it was slower :/ would it be much different?

On Thu, Oct 11, 2012 at 10:09 AM, Adam Bark <adam....@gmail.com> wrote:
On 10/10/12 21:59, Wallace Davidson wrote:
Thanks that does help :) Would you know how I can get a python matrix usable in opengl? :/ It just says "expected LP_c_float instance instead of matrix" when I try use a numpy one :(

If you want to use numpy matrices and opengl then get pyopengl, it's a nicer library anyway as you don't have to mess around with ctypes.


If you're using core opengl it shouldn't make much difference as you won't need to make many calls, immediate mode is where you might find some slowdown. I use it personally and haven't had any performance issues that weren't related to either poor programming on my part or my incredibly old graphics card (NVidia 7950GT).
--
Yes, that's what I'm using. Just post if you need any pointers.

Wallace Davidson

unread,
Oct 10, 2012, 6:10:00 PM10/10/12
to pyglet...@googlegroups.com
Thanks :)

Adam Griffiths

unread,
Oct 18, 2012, 11:52:09 AM10/18/12
to pyglet...@googlegroups.com
You can convert to the appropriate data type by using this convension

>>> from pyglet.gl import *

# single values
>>> a = (GLfloat)(1.0)
>>> a
c_float(1.0)

# arrays
>>> data = [1.0, 2.0, 3.0]
>>> a = (GLfloat * len(data))(*data)
>>> a
<__main__.c_float_Array_3 object at 0x106078e60>

# numpy (nicer than arrays
>>> import numpy
>>> data = numpy.array([1.0, 2.0, 3.0])
>>> a = (GLfloat * data.size)(*data)
>>> a
<__main__.c_float_Array_3 object at 0x108931b90>
>>> for val in a: print val
... 
1.0
2.0
3.0


Be aware that using len(list) will only get you the first dimension.
This is why I prefer numpy, as you can simply use 'data.size' to get the entire size of the array.

Eg.
>>> a = [[1,2,3],[4,5,6]]
>>> len(a)
2
>>> a = numpy.array( a )
>>> len(a)
2
>>> a.size
6

This also applies for textures.
I've seen a lot of code converting numpy arrays to strings and then passing that to the image.set_data functions.
Don't do this!
Just pass a data array in the proper format.



Hope this helps =)

Cheers,
Adam

Adam Griffiths

unread,
Oct 18, 2012, 11:55:24 AM10/18/12
to pyglet...@googlegroups.com

Wallace Davidson

unread,
Oct 18, 2012, 2:32:19 PM10/18/12
to pyglet...@googlegroups.com
Thanks that's really helpful :) I've been trying to get matices working for ages.

To view this discussion on the web visit https://groups.google.com/d/msg/pyglet-users/-/ChaQTArGS38J.
Reply all
Reply to author
Forward
0 new messages