Here is an example for the SDL_VideoInfo that I made for someone else.
from ctypes import *
sdl = CDLL("sdl")
class SDL_VideoInfo(Structure):
_fields_ = [('bitfield', c_uint),
('video_mem', c_uint),
('_vfmt', c_void_p), # POINTER(SDL_PixelFormat)),
('_current_w', c_int),
('_current_h', c_int)]
sdl.SDL_GetVideoInfo.restype = POINTER(SDL_VideoInfo)
sdl.SDL_VideoInit(None, 0) #Video Hardware initialisieren
videoInfo = sdl.SDL_GetVideoInfo().contents #Pointer dereferenzieren
print (videoInfo._current_w)
print (videoInfo._current_h)
I tried to make an SDL_ListModes example for you. But it will always crash because I don’t know how to dereference the first pointer to a list.
from ctypes import *
sdl = CDLL("sdl")
class SDL_PixelFormat(Structure):
_fields_ = [('_palette', c_void_p), #POINTER(SDL_Palette)),
('BitsPerPixel', c_ubyte),
('BytesPerPixel', c_ubyte),
('Rloss', c_ubyte),
('Gloss', c_ubyte),
('Bloss', c_ubyte),
('Aloss', c_ubyte),
('Rshift', c_ubyte),
('Gshift', c_ubyte),
('Bshift', c_ubyte),
('Ashift', c_ubyte),
('Rmask', c_uint),
('Gmask', c_uint),
('Bmask', c_uint),
('Amask', c_uint),
('colorkey', c_uint),
('alpha', c_ubyte)]
def __copy__(self):
f = SDL_PixelFormat()
f._palette = self._palette
f.BitsPerPixel = self.BitsPerPixel
f.BytesPerPixel = self.BytesPerPixel
f.Rloss = self.Rloss
f.Gloss = self.Gloss
f.Bloss = self.Bloss
f.Aloss = self.Aloss
f.Rshift = self.Rshift
f.Gshift = self.Gshift
f.Bshift = self.Bshift
f.Ashift = self.Ashift
f.Rmask = self.Rmask
f.Gmask = self.Gmask
f.Bmask = self.Bmask
f.Amask = self.Amask
f.colorkey = self.colorkey
f.alpha = self.alpha
return f
class SDL_Rect(Structure):
_fields_ = [('x', c_short),
('y', c_short),
('w', c_ushort),
('h', c_ushort)]
def __init__(self, x=0, y=0, w=0, h=0):
self.x = x
self.y = y
self.w = w
self.h = h
def __repr__(self):
return 'SDL_Rect(x=%d, y=%d, w=%d, h=%d)' % \
(self.x, self.y, self.w, self.h)
def __copy__(self):
return SDL_Rect(self.x, self.y, self.w, self.h)
def __deepcopy__(self, memo):
return SDL_Rect(self.x, self.y, self.w, self.h)
#class SDL_ListModes(Structure):
# _fields_ = [('_list', POINTER(SDL_Rect))]
# def __getattr__(self, name):
# if name == 'list': # Dereferenziere list pointer.
# if self._vfmt:
# return self._list.contents
# return None
sdl.SDL_VideoInit(None, 0)
sdl.SDL_ListModes.restype = POINTER(POINTER(SDL_Rect))
sdl.SDL_ListModes.argtypes = [POINTER(SDL_PixelFormat), c_uint]
def SDL_ListModes(format, flags):
ar = sdl.SDL_ListModes(format, flags)#.contens
if not ar:
return []
if addressof(ar.contents) == -1:
return -1
i = 0
lst = []
while ar[i]:
lst.append(ar[i].contents)
i += 1
return lst
#for obj in ar:
#lst.append(obj.contents)
#return lst
#SDL_ListModes(None, 66)
print (SDL_ListModes(None, 66))