Re: Tristan McDonald's Shader.py

66 views
Skip to first unread message

Nicky Mac

unread,
Apr 21, 2020, 8:31:25 AM4/21/20
to pyglet...@googlegroups.com
thanks Claudio,
I had already imported the ctypes but I still get:
src = (c_char_p * count)(*strings)
TypeError: bytes or integer address expected instead of str instance

and the next line of code looks awkward:
glShaderSource(shader, count, cast(pointer(src),
POINTER(POINTER(c_char))), None)

On 20/04/2020, claudio canepa <ccan...@gmail.com> wrote:
> From a comment in the page:
>
> There’s a missing import in the shader module.
>
> File “/shader.py”, line 40, in createShader
> src = (c_char_p * count)(*strings)
> NameError: global name ‘c_char_p’ is not defined
>
> Resolved by adding
>
> from ctypes import *
>
> On Mon, Apr 20, 2020 at 12:22 PM Nicky Mac <nmcel...@gmail.com> wrote:
>
>>
>>
>> On Monday, April 20, 2020 at 10:25:59 AM UTC+1, Nicky Mac wrote:
>>>
>>> the splendid glsl examples in pythonstuff.org require the use of
>>> Tristan
>>> McDonald's Shader.py
>>> obtainable from :
>>> https://swiftcoder.wordpress.com/2008/12/19/simple-glsl-wrapper-for-pyglet/
>>> <https://www.google.com/url?q=https%3A%2F%2Fswiftcoder.wordpress.com%2F2008%2F12%2F19%2Fsimple-glsl-wrapper-for-pyglet%2F&sa=D&sntz=1&usg=AFQjCNGJa5x89HiGqIUhjEeI7eKC6QZizA>
>>>
>>> but the code there is badly formatted and after unscrambling it I can't
>>> get it to run.
>>> Is there somewhere else I can acquire this code?
>>>
>>
>> Ok I've now found it, but when used errors:
>>
>> File "C:/Python/Python36/Dhruve and me/Pyglet\shader.py", line 40, in
>> createShader
>> src = (c_char_p * count)(*strings)
>> NameError: name 'c_char_p' is not defined
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "pyglet-users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to pyglet-users...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/pyglet-users/3c81c9be-9a13-4d10-8aae-32b34a0275ae%40googlegroups.com
>> <https://groups.google.com/d/msgid/pyglet-users/3c81c9be-9a13-4d10-8aae-32b34a0275ae%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>
> --
> You received this message because you are subscribed to the Google Groups
> "pyglet-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to pyglet-users...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/pyglet-users/CAP3BN9VAkymNHTqNBGxYWb-gob%3DGqgWLgZ%3DHQLp%3DKxFL5vUT%2Bg%40mail.gmail.com.
>


--
Nick "Mac" McElwaine

Greg Ewing

unread,
Apr 22, 2020, 1:02:38 AM4/22/20
to pyglet...@googlegroups.com
On 22/04/20 12:31 am, Nicky Mac wrote:
> src = (c_char_p * count)(*strings)
> TypeError: bytes or integer address expected instead of str instance

It looks like this was designed for Python 2. You may
need to encode the strings to bytes, e.g.

src_bytes = [s.encode() for s in strings]
src = (c_char_p * count)(*src_bytes)

--
Greg

Nicky Mac

unread,
Apr 22, 2020, 3:56:39 AM4/22/20
to pyglet...@googlegroups.com
Wow! That fixed it!  (I had already changed 'basestring' missing from Python 3  to 'str').
Huge thanks Greg.

Virus-free. www.avg.com

--
You received this message because you are subscribed to the Google Groups "pyglet-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pyglet-users...@googlegroups.com.


--
Nick "Mac" McElwaine
Reply all
Reply to author
Forward
0 new messages