wip; pretty dirty

This commit is contained in:
Christopher Denter 2011-05-24 22:41:43 +02:00
parent 0699b85713
commit 73e79b624f
13 changed files with 117 additions and 50 deletions

View File

@ -8,11 +8,23 @@ with some adapation.
This might become a Kivy widget when experimentation will be done.
'''
print 'SETUP KIVY >>'
from kivy.logger import Logger
import logging
Logger.setLevel(logging.TRACE)
from kivy.config import Config
Config.remove_option('input', 'default')
Config.remove_option('input', 'mactouch')
Config.set('graphics', 'fullscreen', 'auto')
print 'SETUP KIVY << done'
from kivy.clock import Clock
from kivy.app import App
from kivy.uix.floatlayout import FloatLayout
from kivy.core.window import Window
#Window.clearcolor = None
from kivy.graphics import RenderContext
from kivy.properties import StringProperty
@ -37,15 +49,16 @@ uniform float time;
void main(void)
{
float x = gl_FragCoord.x;
float y = gl_FragCoord.y;
float mov0 = x+y+cos(sin(time)*2.)*100.+sin(x/100.)*1000.;
float mov1 = y / resolution.y / 0.2 + time;
float mov2 = x / resolution.x / 0.2;
float c1 = abs(sin(mov1+time)/2.+mov2/2.-mov1-mov2+time);
float c2 = abs(sin(c1+sin(mov0/1000.+time)+sin(y/40.+time)+sin((x+y)/100.)*3.));
float c3 = abs(sin(c2+cos(mov1+mov2+c2)+cos(mov2)+sin(x/1000.)));
gl_FragColor = vec4( c1,c2,c3,1.0);
// float x = gl_FragCoord.x;
// float y = gl_FragCoord.y;
// float mov0 = x+y+cos(sin(time)*2.)*100.+sin(x/100.)*1000.;
// float mov1 = y / resolution.y / 0.2 + time;
// float mov2 = x / resolution.x / 0.2;
// float c1 = abs(sin(mov1+time)/2.+mov2/2.-mov1-mov2+time);
// float c2 = abs(sin(c1+sin(mov0/1000.+time)+sin(y/40.+time)+sin((x+y)/100.)*3.));
// float c3 = abs(sin(c2+cos(mov1+mov2+c2)+cos(mov2)+sin(x/1000.)));
// gl_FragColor = vec4( c1,c2,c3,1.0);
gl_FragColor = vec4(1.0, 1.0, 0., 1.0);
}
'''
@ -64,7 +77,7 @@ class ShaderWidget(FloatLayout):
super(ShaderWidget, self).__init__(**kwargs)
# We'll update our glsl variables in a clock
Clock.schedule_interval(self.update_glsl, 1 / 60.)
Clock.schedule_interval(self.update_glsl, 1.)
def on_fs(self, instance, value):
# set the fragment shader to our source code
@ -80,6 +93,7 @@ class ShaderWidget(FloatLayout):
self.canvas['resolution'] = map(float, self.size)
# This is needed for the default vertex shader.
self.canvas['projection_mat'] = Window.render_context['projection_mat']
# print self.canvas['projection_mat']
class PlasmaApp(App):

View File

@ -268,10 +268,10 @@ class EventLoopBase(object):
self.dispatch_input()
window = self.window
if window and window.canvas.needs_redraw:
Clock.tick_draw()
window.dispatch('on_draw')
window.dispatch('on_flip')
#if window and window.canvas.needs_redraw:
Clock.tick_draw()
window.dispatch('on_draw')
window.dispatch('on_flip')
# don't loop if we don't have listeners !
if len(self.event_listeners) == 0:

View File

@ -27,13 +27,11 @@ class ImageLoaderOSXCoreImage(ImageLoaderBase):
'tga', 'tiff', 'wal', 'wmf', 'xbm', 'xpm', 'xv')
def load(self, filename):
print 'before'
ret = osxcoreimage.load_raw_image_data(filename)
if ret is None:
Logger.warning('Image: Unable to load image <%s>' % filename)
raise Exception('Unable to load image')
w, h, imgtype, data = ret
print 'after'
return ImageData(w, h, imgtype, data)
# register

View File

@ -70,11 +70,13 @@ def load_raw_image_data(bytes _url):
# see iphone3d book
myImageSourceRef = CGImageSourceCreateWithURL(url, NULL)
if myImageSourceRef == NULL:
print 'myImageSourceRef is NULL'
return None
cdef CGImageRef myImageRef
myImageRef = CGImageSourceCreateImageAtIndex (myImageSourceRef, 0, NULL)
if myImageRef == NULL:
print 'myImageRef is NULL'
return None
cdef int width = CGImageGetWidth(myImageRef)
@ -96,6 +98,7 @@ def load_raw_image_data(bytes _url):
# XXX clean image object
print 'Image:', _url, width, height, imgtype
return (width, height, imgtype, r_data)
#

View File

@ -51,12 +51,13 @@ cdef extern from "SDL.h":
int SDL_QUIT
int SDL_WINDOWEVENT
int SDL_SYSWMEVENT
int SDL_KEYDOWN,
int SDL_KEYUP,
int SDL_KEYDOWN
int SDL_KEYUP
int SDL_MOUSEMOTION
int SDL_MOUSEBUTTONDOWN
int SDL_MOUSEBUTTONUP
int SDL_TEXTINPUT
int SDL_FINGERMOTION
# GL Attribute
int SDL_GL_DEPTH_SIZE
@ -67,7 +68,9 @@ cdef extern from "SDL.h":
int SDL_GL_STENCIL_SIZE
int SDL_GL_DOUBLEBUFFER
int SDL_GL_CONTEXT_MAJOR_VERSION
int SDL_GL_CONTEXT_MINOR_VERSION
int SDL_GL_RETAINED_BACKING
int SDL_GL_ACCELERATED_VISUAL
# Init flags
int SDL_INIT_VIDEO
@ -84,8 +87,11 @@ cdef extern from "SDL.h":
int SDL_WINDOW_BORDERLESS
int SDL_WINDOW_RESIZABLE
int SDL_WINDOW_FULLSCREEN
int SDL_WINDOW_INPUT_FOCUS
int SDL_WINDOW_INPUT_GRABBED
int SDL_WINDOW_MOUSE_FOCUS
# Window event
## Window event
int SDL_WINDOWEVENT_EXPOSED
int SDL_WINDOWEVENT_RESIZED
@ -99,6 +105,8 @@ cdef extern from "SDL.h":
int SDL_GetWindowDisplayMode(SDL_Window *, SDL_DisplayMode *)
int SDL_SetWindowDisplayMode(SDL_Window *, SDL_DisplayMode *)
void SDL_GL_SwapWindow(SDL_Window *)
void SDL_GL_SwapBuffers()
int SDL_GL_MakeCurrent(SDL_Window* window, SDL_GLContext context)
int SDL_GL_SetSwapInterval(int)
int SDL_Flip(SDL_Surface *)
@ -107,12 +115,16 @@ cdef extern from "SDL.h":
void SDL_GL_DeleteContext(SDL_GLContext)
int SDL_PollEvent(SDL_Event *)
void SDL_PumpEvents()
int SDL_EventState(unsigned int, int)
char *SDL_GetError()
cdef SDL_Window *win = NULL
cdef SDL_GLContext ctx = NULL
cdef SDL_Surface *surface = NULL
cdef int win_flags = 0
@ -120,10 +132,39 @@ def die():
raise RuntimeError(<bytes> SDL_GetError())
#def init_video():
# return SDL_Init(SDL_INIT_VIDEO)
#
#
#def create_window():
# global win
# win = SDL_CreateWindow(NULL, 0, 0, 320, 480, SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN)
# assert win != NULL
#
#
#def create_context():
# global ctx
# ctx = SDL_GL_CreateContext(win)
#
#
#def poll_events():
# cdef SDL_Event event
# while SDL_PollEvent(&event):
# print event.type,
#
#
#def swap():
# assert win != NULL
# SDL_GL_SwapWindow(win)
#
#def get_error():
# print <bytes> SDL_GetError()
def setup_window(width, height, use_fake, use_fullscreen):
global win, ctx, win_flags
win_flags = SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN | SDL_WINDOW_BORDERLESS
win_flags = SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN | SDL_WINDOW_BORDERLESS | SDL_WINDOW_RESIZABLE
'''
win_flags = SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE | SDL_WINDOW_SHOWN
if use_fake:
@ -136,7 +177,7 @@ def setup_window(width, height, use_fake, use_fullscreen):
die()
#SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1)
#SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16)
##SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16)
#SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 1)
#SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8)
#SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8)
@ -150,16 +191,24 @@ def setup_window(width, height, use_fake, use_fullscreen):
SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 0);
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 0);
SDL_GL_SetAttribute(SDL_GL_RETAINED_BACKING, 0);
#SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 1);
SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 1);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
win = SDL_CreateWindow(NULL, 0, 0, 768, 1024, win_flags)
win = SDL_CreateWindow(NULL, 0, 0, width, height, win_flags)
if not win:
die()
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
SDL_GL_SetSwapInterval(1);
ctx = SDL_GL_CreateContext(win)
assert ctx != NULL
SDL_GL_SetSwapInterval(1);
#surface = SDL_GetWindowSurface(win)
cdef SDL_DisplayMode mode
SDL_GetWindowDisplayMode(win, &mode)
return mode.w, mode.h
def resize_window(w, h):
@ -168,6 +217,8 @@ def resize_window(w, h):
mode.w = w
mode.h = h
SDL_SetWindowDisplayMode(win, &mode)
SDL_GetWindowDisplayMode(win, &mode)
print 'SDL resized window size to', mode.w, mode.h
def set_window_title(str title):
@ -181,8 +232,8 @@ def teardown_window():
def poll():
print 'polling'
cdef SDL_Event event
if SDL_PollEvent(&event) == 0:
return False
@ -214,11 +265,11 @@ def poll():
s = PyUnicode_FromString(<char *>event.text.text)
return ('textinput', s)
else:
print 'receive unknown sdl event', event.type
#print 'receive unknown sdl event', event.type
pass
def flip():
SDL_GL_SwapWindow(win)
#SDL_GL_SwapBuffers()

View File

@ -383,11 +383,13 @@ class WindowBase(EventDispatcher):
from kivy.graphics.transformation import Matrix
width, height = self.system_size
print "system size:", self.system_size
w2 = width / 2.
h2 = height / 2.
# prepare the viewport
glViewport(0, 0, width, height)
print "GL_VIEWPORT:", width, height
projection_mat = Matrix()
projection_mat.view_clip(0.0, width, 0.0, height, -1.0, 1.0, 0)
self.render_context['projection_mat'] = projection_mat

View File

@ -54,6 +54,7 @@ class WindowSDL(WindowBase):
elif self._pos is not None:
os.environ['SDL_VIDEO_WINDOW_POS'] = '%d,%d' % self._pos
pass
# never stay with a None pos, application using w.center will be fired.
self._pos = (0, 0)
@ -75,7 +76,7 @@ class WindowSDL(WindowBase):
# setup !
w, h = self._size
sdl.setup_window(w, h, use_fake, use_fullscreen)
self._size = sdl.setup_window(w, h, use_fake, use_fullscreen)
super(WindowSDL, self).create_window()
@ -93,18 +94,10 @@ class WindowSDL(WindowBase):
self.dispatch('on_close')
def set_title(self, title):
return
pygame.display.set_caption(title)
sdl.set_window_title(title)
def set_icon(self, filename):
return
try:
if not exists(filename):
return False
icon = pygame.image.load(filename)
pygame.display.set_icon(icon)
except:
Logger.exception('WinPygame: unable to set icon')
def screenshot(self, *largs, **kwargs):
return
@ -132,7 +125,6 @@ class WindowSDL(WindowBase):
super(WindowPygame, self).on_keyboard(key, scancode, unicode, modifier)
def flip(self):
print 'flipping'
sdl.flip()
super(WindowSDL, self).flip()
@ -146,7 +138,6 @@ class WindowSDL(WindowBase):
if event is None:
continue
print 'sdl receive', event
action, args = event[0], event[1:]
if action == 'quit':
EventLoop.quit = True
@ -227,6 +218,7 @@ class WindowSDL(WindowBase):
# don't known why, but pygame required a resize event
# for opengl, before mainloop... window reinit ?
self.dispatch('on_resize', *self.size)
print 'dispatched on_resize, size is', self.size
while not EventLoop.quit and EventLoop.status == 'started':
try:

View File

@ -10,6 +10,8 @@ varying vec2 tex_coord0;
uniform sampler2D texture0;
void main (void){
gl_FragColor = frag_color * texture2D(texture0, tex_coord0);
//gl_FragColor = frag_color * texture2D(texture0, tex_coord0);
//gl_FragColor = frag_color;
gl_FragColor = vec4(1.);
}

View File

@ -81,7 +81,8 @@ cdef class Instruction:
property needs_redraw:
def __get__(self):
return bool(self.flags & GI_NEEDS_UPDATE)
return True
#return bool(self.flags & GI_NEEDS_UPDATE)
cdef class InstructionGroup(Instruction):
@ -289,7 +290,7 @@ cdef class VertexInstruction(Instruction):
size: self.size
.. note::
The filename will be searched with the
:func:`kivy.resources.resource_find` function.
@ -340,7 +341,7 @@ cdef class VertexInstruction(Instruction):
cdef class Callback(Instruction):
'''.. versionadded:: 1.0.4
A Callback is an instruction that will be called when the drawing
operation is performed. When adding instructions to a canvas, you can do
this::
@ -545,7 +546,7 @@ cdef CanvasBase getActiveCanvas():
global ACTIVE_CANVAS
return ACTIVE_CANVAS
# Canvas Stack, for internal use so canvas can be bound
# Canvas Stack, for internal use so canvas can be bound
# inside other canvas, and restroed when other canvas is done
cdef list CANVAS_STACK = list()
@ -559,7 +560,7 @@ cdef popActiveCanvas():
ACTIVE_CANVAS = CANVAS_STACK.pop()
#TODO: same as canvas, move back to context.pyx..fix circular import
#TODO: same as canvas, move back to context.pyx..fix circular import
#on actual import from python problem
include "common.pxi"
from vertex cimport *

View File

@ -231,6 +231,7 @@ cdef class Shader:
return -1
Logger.info('Shader: %s compiled successfully' % ctype)
print <bytes> source
return shader
cdef str get_shader_log(self, shader):

View File

@ -482,7 +482,7 @@ cdef class BorderImage(Rectangle):
hs[0], vs[1], ths[0], tvs[1], #v11
hs[1], vs[1], ths[1], tvs[1], #v12
hs[2], vs[1], ths[2], tvs[1], #v13
hs[2], vs[2], ths[2], tvs[2], #v14
hs[2], vs[2], ths[2], tvs[2], #v14
hs[1], vs[2], ths[1], tvs[2]] #v15
cdef int *indices = [

View File

@ -17,6 +17,8 @@ import kivy
resource_paths = [
'.',
dirname(sys.argv[0]),
# XXX iOS Hack; do properly. not sure how yet
join(dirname(sys.argv[0]), 'YourApp'),
dirname(kivy.__file__)]

View File

@ -172,8 +172,9 @@ if True:
sdl_extra_link_args = []
if platform == 'darwin':
# Paths as per homebrew (modified formula to use hg checkout)
sdl_includes = ['/usr/local/Cellar/sdl/HEAD/include/SDL']
sdl_extra_link_args += ['-L', '/Users/dennda/dev/sdl-1.3/Xcode-iPhoneOS/SDL/build/SDLiPhoneOS.build/Debug-iphoneos/libSDL.build/Objects-normal/armv7']
sdl_includes = ['/Users/dennda/dev/sdl-1.3/include']
#sdl_extra_link_args += ['-L', '/Users/dennda/dev/sdl-1.3/Xcode-iPhoneOS/SDL/build/SDLiPhoneOS.build/Debug-iphoneos/libSDL.build/Objects-normal/armv7']
sdl_extra_link_args += ['-L', '/Users/dennda/dev/sdl-1.3/Xcode-iPhoneOS/SDL/build/Debug-iphoneos/']
sdl_extra_link_args += ['-framework', 'Foundation']
sdl_extra_link_args += ['-framework', 'UIKit']
sdl_extra_link_args += ['-framework', 'AudioToolbox']