diff --git a/csdl/__init__.py b/csdl/__init__.py index 6527d80..c0196b0 100644 --- a/csdl/__init__.py +++ b/csdl/__init__.py @@ -112,6 +112,16 @@ class RendererInfo(ctypes.Structure): ('max_texture_height', ctypes.c_int) ) +_render_driver_list = [] +def get_render_drivers(): + if not _render_driver_list: + num = _SDL.SDL_GetNumRenderDrivers() + for i in xrange(num): + rinfo = RendererInfo() + errcheck(_SDL.SDL_GetRenderDriverInfo(i, ctypes.byref(rinfo))) + _render_driver_list.append(rinfo) + return _render_driver_list + class Renderer(object): def __init__(self, window, index=-1, flags=0): @@ -125,6 +135,17 @@ class Renderer(object): def set_draw_color(self, r, g, b, a=255): errcheck(_SDL.SDL_SetRenderDrawColor(self._renderer, r, g, b, a)) + @property + def draw_color(self): + r = ctypes.c_uint8() + g = ctypes.c_uint8() + b = ctypes.c_uint8() + a = ctypes.c_uint8() + errcheck(_SDL.SDL_GetRenderDrawColor(self._renderer, ctypes.byref(r), + ctypes.byref(g), ctypes.byref(b), + ctypes.byref(a))) + return (r,g,b,a) + def clear(self): errcheck(_SDL.SDL_RenderClear(self._renderer)) @@ -134,6 +155,11 @@ class Renderer(object): def draw_line(self, x1, y1, x2, y2): errcheck(_SDL.SDL_RenderDrawLine(self._renderer, x1, y1, x2, y2)) + def draw_lines(self, points): + T = Point*len(points) + _sdl_points = T(*[Point(*pt) for pt in points]) + errcheck(_SDL.SDL_RenderDrawLines(self._renderer, _sdl_points, + len(points))) _SDL.SDL_GetWindowTitle.restype = ctypes.c_char_p @@ -216,7 +242,7 @@ class Window(object): def minimize(self): _SDL.SDL_MinimizeWindow(self._handle) - def raise(self): + def raise_window(self): _SDL.SDL_RaiseWindow(self._handle) def restore(self): @@ -283,6 +309,12 @@ class Rect(ctypes.Structure): ('height', ctypes.c_int), ) +class Point(ctypes.Structure): + _fields_ = ( + ('x', ctypes.c_int), + ('y', ctypes.c_int), + ) + def get_display_bounds(display_index): rect = Rect() errcheck(_SDL.SDL_GetDisplayBounds(display_index, ctypes.byref(rect))) diff --git a/demo/random_triangles.py b/demo/random_triangles.py new file mode 100644 index 0000000..9c5fdfe --- /dev/null +++ b/demo/random_triangles.py @@ -0,0 +1,23 @@ +from csdl import init, Window, SDL_INIT_EVERYTHING +import random +import time + +def main(): + init(SDL_INIT_EVERYTHING) + window = Window('test', 100, 100, 512, 512, 0) + + while True: + window.renderer.set_draw_color(0,0,0,255) + window.renderer.clear() + window.renderer.set_draw_color(255,0,0,255) + for i in xrange(20): + window.renderer.set_draw_color(random.randint(0,255), + random.randint(0,255), + random.randint(0,255)) + p1 = (random.randint(0,512), random.randint(0, 512)) + p2 = (random.randint(0,512), random.randint(0, 512)) + p3 = (random.randint(0,512), random.randint(0, 512)) + window.renderer.draw_lines([p1, p2, p3, p1]) + window.renderer.present() + time.sleep(.001) +main() diff --git a/not_supported.txt b/not_supported.txt index 01286e9..a95ba34 100644 --- a/not_supported.txt +++ b/not_supported.txt @@ -13,3 +13,16 @@ http://wiki.libsdl.org/moin.cgi/CategoryVideo SDL_SetWindowFullscreen -- later SDL_VideoInit -- later SDL_VideoQuit -- later + SDL_GL_* -- later? + +CategoryRender + SDL_CreateSoftwareRenderer + SDL_CreateTexture, SDL_CreateTextureFromSurface, SDL_DestroyTexture, SDL_DirtyTexture + SDL_GetRenderDrawBlendMode + SDL_GetTextureAlphaMod + SDL_GetTextureBlendMode + SDL_GetTextureColorMode + SDL_LockTexture + SDL_QueryTexture + SDL_QueryTexturePixels + SDL_RenderCopy