Hello!
I'd like to use Clutter as a GUI for another OpenGL engine, drawing
the 3D scene before clutter. I tried making raw GL calls (drawing a
triangle and a quad) using a custom actor in several pyclutter
examples. It somewhat works in super-oh.py (I've attached it, needs
redhand.png). In a nvidia gf 9400m it shows the triangle and quad with
dim red (sometimes the dimmed color is green or blue), except for 1
frame when you make click, and after you click all hands until you
press R. In a netbook with intel 945gma instead of the dimished color,
it shows black.
I'd like to know also if it's possible to not use glib mainloop and
manually call clutter redraw instead.
Best regarts,
--
Alberto
import sys
import clutter
import gtk
import math
import gobject
from clutter import cogl
from OpenGL.GL import *
from OpenGL.GLU import *
import glib
rtri = rquad = 0.0
def draw():
cogl.begin_gl()
glShadeModel(GL_SMOOTH)
glClearColor(0.0, 0.0, 0.0, 0.0)
glClearDepth(1.0)
glEnable(GL_DEPTH_TEST)
glDepthFunc(GL_LEQUAL)
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST)
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT)
glLoadIdentity()
glTranslatef(-1.5, 0.0, -6.0)
global rtri
glRotatef(rtri, 0.0, 1.0, 0.0)
glBegin(GL_TRIANGLES)
glColor3f(1.0, 0.0, 0.0)
glVertex3f(0.0, 1.0, 0.0)
glColor3f(0.0, 1.0, 0.0)
glVertex3f(-1.0, -1.0, 0)
glColor3f(0.0, 0.0, 1.0)
glVertex3f(1.0, -1.0, 0)
glEnd()
glLoadIdentity()
glTranslatef(1.5, 0.0, -6.0)
global rquad
glRotatef(rquad, 1.0, 0.0, 0.0)
glColor3f(0.5, 0.5, 1.0)
glBegin(GL_QUADS)
glVertex3f(-1.0, 1.0, 0)
glVertex3f(1.0, 1.0, 0)
glVertex3f(1.0, -1.0, 0)
glVertex3f(-1.0, -1.0, 0)
glEnd()
cogl.end_gl()
rtri += 0.6
rquad+= 0.6
class cosa(clutter.Actor):
__gtype_name__ = 'Triangle'
__gproperties__ = {
'color' : ( \
str, 'color', 'Color', None, gobject.PARAM_READWRITE \
),
}
__gsignals__ = {
'clicked' : ( \
gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, () \
),
}
def __init__ (self):
clutter.Actor.__init__(self)
def do_paint(self):
draw()
class SuperOh (clutter.Group) :
def __init__ (self, nhands=6):
clutter.Group.__init__(self)
self.n_hands = nhands
self.timeline = clutter.Timeline(5000)
self.timeline.set_loop(True)
self.timeline.connect('new-frame', self.on_new_frame)
def sine_wave (alpha):
return math.sin(alpha.get_timeline().get_progress() * math.pi)
self.alpha = clutter.Alpha(self.timeline)
self.alpha.set_func(sine_wave)
self.scalers = []
self.scalers.append(clutter.BehaviourScale(0.5, 0.5, 1.0, 1.0, self.alpha))
self.scalers.append(clutter.BehaviourScale(1.0, 1.0, 0.5, 0.5, self.alpha))
self.stage = clutter.Stage(default=True)
self.stage.set_size(1024, 768)
self.stage.connect('button-press-event', self.on_button_press)
self.stage.connect('key-press-event', self.on_key_press)
self.create_hands()
def _sine_alpha(self, alpha, foo):
print "self: %s, alpha: %s, foo: %s" % (self, alpha, foo)
timeline = alpha.get_timeline()
progress = timeline.get_progress()
return math.sin(progress * math.pi)
def create_hands(self):
try:
redhand = clutter.Texture(filename="redhand.png")
except Exception:
print "Unable to load redhand.png"
sys.exit(1)
(w, h) = redhand.get_size()
for i in range(self.n_hands):
if i == 0:
hand = redhand
else:
hand = clutter.Clone(redhand);
radius = self.get_radius()
x = self.stage.get_width() / 2 + radius * math.cos(i * math.pi / (self.n_hands / 2)) - w / 2
y = self.stage.get_height() / 2 + radius * math.sin (i * math.pi / (self.n_hands / 2)) - h / 2
hand.set_position (int(x), int(y))
hand.move_anchor_point_from_gravity(clutter.GRAVITY_CENTER)
if i % 2:
self.scalers[0].apply(hand)
else:
self.scalers[1].apply(hand)
hand.show()
self.add(hand);
def spin (self):
self.timeline.start()
def get_radius (self):
return (self.stage.get_width () + self.stage.get_height ()) / self.n_hands
def on_new_frame (self, tl, msecs):
progress = tl.get_progress()
self.set_rotation (clutter.Z_AXIS,
progress * 360,
self.stage.get_width() / 2,
self.stage.get_height () / 2,
0)
angle = progress * 360
for i in range(self.n_hands):
hand = self.get_nth_child(i)
hand.set_rotation(clutter.Z_AXIS,
angle * -6.0,
0, 0, 0)
def on_button_press (self, stage, event):
if event.button != 1:
return False
hand = stage.get_actor_at_pos(clutter.PICK_ALL,
int(event.x),
int(event.y))
if type(hand) is clutter.Texture or type(hand) is clutter.Clone:
hand.hide()
return True
def on_key_press (self, stage, event):
if event.keyval == clutter.keysyms.q:
clutter.main_quit()
return True
if event.keyval == clutter.keysyms.r:
for hand in self:
hand.show()
return True
return False
def main (args):
stage = clutter.Stage(default=True)
#stage.set_color('#ffffffff')
hands = SuperOh(8)
stage.add(hands)
hands.spin()
c = cosa()
c.set_size(stage.get_width(),stage.get_height())
c.set_position(0,0)
stage.add(c)
c.lower_bottom()
stage.show_all()
clutter.main()
return 0
if __name__ == '__main__':
sys.exit(main(sys.argv[1:]))
_______________________________________________
clutter-app-devel-list mailing list
[email protected]
http://lists.clutter-project.org/listinfo/clutter-app-devel-list