draw_lines, random_triangle demo
This commit is contained in:
parent
f9c500f4c6
commit
fc3c379a09
@ -112,6 +112,16 @@ class RendererInfo(ctypes.Structure):
|
|||||||
('max_texture_height', ctypes.c_int)
|
('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):
|
class Renderer(object):
|
||||||
|
|
||||||
def __init__(self, window, index=-1, flags=0):
|
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):
|
def set_draw_color(self, r, g, b, a=255):
|
||||||
errcheck(_SDL.SDL_SetRenderDrawColor(self._renderer, r, g, b, a))
|
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):
|
def clear(self):
|
||||||
errcheck(_SDL.SDL_RenderClear(self._renderer))
|
errcheck(_SDL.SDL_RenderClear(self._renderer))
|
||||||
|
|
||||||
@ -134,6 +155,11 @@ class Renderer(object):
|
|||||||
def draw_line(self, x1, y1, x2, y2):
|
def draw_line(self, x1, y1, x2, y2):
|
||||||
errcheck(_SDL.SDL_RenderDrawLine(self._renderer, 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
|
_SDL.SDL_GetWindowTitle.restype = ctypes.c_char_p
|
||||||
@ -216,7 +242,7 @@ class Window(object):
|
|||||||
def minimize(self):
|
def minimize(self):
|
||||||
_SDL.SDL_MinimizeWindow(self._handle)
|
_SDL.SDL_MinimizeWindow(self._handle)
|
||||||
|
|
||||||
def raise(self):
|
def raise_window(self):
|
||||||
_SDL.SDL_RaiseWindow(self._handle)
|
_SDL.SDL_RaiseWindow(self._handle)
|
||||||
|
|
||||||
def restore(self):
|
def restore(self):
|
||||||
@ -283,6 +309,12 @@ class Rect(ctypes.Structure):
|
|||||||
('height', ctypes.c_int),
|
('height', ctypes.c_int),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
class Point(ctypes.Structure):
|
||||||
|
_fields_ = (
|
||||||
|
('x', ctypes.c_int),
|
||||||
|
('y', ctypes.c_int),
|
||||||
|
)
|
||||||
|
|
||||||
def get_display_bounds(display_index):
|
def get_display_bounds(display_index):
|
||||||
rect = Rect()
|
rect = Rect()
|
||||||
errcheck(_SDL.SDL_GetDisplayBounds(display_index, ctypes.byref(rect)))
|
errcheck(_SDL.SDL_GetDisplayBounds(display_index, ctypes.byref(rect)))
|
||||||
|
23
demo/random_triangles.py
Normal file
23
demo/random_triangles.py
Normal file
@ -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()
|
@ -13,3 +13,16 @@ http://wiki.libsdl.org/moin.cgi/CategoryVideo
|
|||||||
SDL_SetWindowFullscreen -- later
|
SDL_SetWindowFullscreen -- later
|
||||||
SDL_VideoInit -- later
|
SDL_VideoInit -- later
|
||||||
SDL_VideoQuit -- 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
|
||||||
|
Loading…
Reference in New Issue
Block a user