Hello community, here is the log from the commit of package go-Go-OpenGL for openSUSE:Factory checked in at 2012-02-14 11:24:25 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/go-Go-OpenGL (Old) and /work/SRC/openSUSE:Factory/.go-Go-OpenGL.new (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "go-Go-OpenGL", Maintainer is "" Changes: -------- --- /work/SRC/openSUSE:Factory/go-Go-OpenGL/go-Go-OpenGL.changes 2011-12-15 16:06:14.000000000 +0100 +++ /work/SRC/openSUSE:Factory/.go-Go-OpenGL.new/go-Go-OpenGL.changes 2012-02-14 11:24:27.000000000 +0100 @@ -1,0 +2,5 @@ +Mon Feb 6 12:27:53 UTC 2012 - sasc...@suse.de + +- Move to goinstall + +------------------------------------------------------------------- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ go-Go-OpenGL.spec ++++++ --- /var/tmp/diff_new_pack.IK6PD1/_old 2012-02-14 11:24:28.000000000 +0100 +++ /var/tmp/diff_new_pack.IK6PD1/_new 2012-02-14 11:24:28.000000000 +0100 @@ -1,8 +1,8 @@ # # spec file for package go-Go-OpenGL # -# Copyright (c) 2011 SUSE LINUX Products GmbH, Nuernberg, Germany. -# Copyright (c), 2011, Sascha Peilicke <sasc...@gmx.de> +# Copyright (c) 2012 SUSE LINUX Products GmbH, Nuernberg, Germany. +# Copyright (c) 2011 Sascha Peilicke <sasc...@gmx.de> # # All modifications and additions to the file contributed by third parties # remain the property of their copyright owners, unless otherwise agreed @@ -15,6 +15,7 @@ # Please submit bugfixes or comments via http://bugs.opensuse.org/ # + Name: go-Go-OpenGL Version: 0.0.0+git20110617 Release: 0 @@ -26,6 +27,7 @@ Patch0: Go-OpenGL-fixes.patch BuildRoot: %{_tmppath}/%{name}-%{version}-build BuildRequires: glew-devel >= 1.5.8 +BuildRequires: go-Go-SDL-devel BuildRequires: go-devel %{go_provides} %{go_requires} @@ -41,15 +43,14 @@ %endif %build -%install -%{go_make_install} -%clean -rm -rf %{buildroot} +%install +rm -rf ./examples +%goinstall github.com/banthar/Go-OpenGL ... %files %defattr(-,root,root,-) -%doc README TODO examples +%doc README TODO %{go_sitearch}/* %changelog ++++++ Go-OpenGL-0.0.0+git20110617.tar.bz2 ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Go-OpenGL/Makefile new/Go-OpenGL/Makefile --- old/Go-OpenGL/Makefile 2011-06-17 11:02:07.000000000 +0200 +++ new/Go-OpenGL/Makefile 2012-02-02 15:40:48.000000000 +0100 @@ -6,7 +6,7 @@ .PHONY: all gl install examples clean -all: install examples +all: install gl: gomake -C gl diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Go-OpenGL/examples/Makefile new/Go-OpenGL/examples/Makefile --- old/Go-OpenGL/examples/Makefile 2011-06-17 11:02:07.000000000 +0200 +++ new/Go-OpenGL/examples/Makefile 2012-02-02 15:40:48.000000000 +0100 @@ -4,7 +4,7 @@ include $(GOROOT)/src/Make.inc -TARGETS=draw gomandel gogears +TARGETS=draw gomandel sdlgears glfwgears .PHONY: all clean diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Go-OpenGL/examples/draw.go new/Go-OpenGL/examples/draw.go --- old/Go-OpenGL/examples/draw.go 2011-06-17 11:02:07.000000000 +0200 +++ new/Go-OpenGL/examples/draw.go 2012-02-02 15:40:48.000000000 +0100 @@ -97,23 +97,19 @@ for running { - e := &sdl.Event{} - - for e.Poll() { - switch e.Type { - case sdl.QUIT: + for e := sdl.PollEvent(); e != nil; e = sdl.PollEvent() { + switch ev := e.(type) { + case *sdl.QuitEvent: running = false - case sdl.KEYDOWN: - ke := e.Keyboard() - if ke.Keysym.Sym == sdl.K_ESCAPE { - running = false - } - case sdl.MOUSEMOTION: - me := e.MouseMotion() - if me.State != 0 { - pen.lineTo(Point{int(me.X), int(me.Y)}) + case *sdl.KeyboardEvent: + if ev.Keysym.Sym == sdl.K_ESCAPE { + running = false + } + case *sdl.MouseMotionEvent: + if ev.State != 0 { + pen.lineTo(Point{int(ev.X), int(ev.Y)}) } else { - pen.moveTo(Point{int(me.X), int(me.Y)}) + pen.moveTo(Point{int(ev.X), int(ev.Y)}) } } } diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Go-OpenGL/examples/glfw/Makefile new/Go-OpenGL/examples/glfw/Makefile --- old/Go-OpenGL/examples/glfw/Makefile 1970-01-01 01:00:00.000000000 +0100 +++ new/Go-OpenGL/examples/glfw/Makefile 2012-02-02 15:40:48.000000000 +0100 @@ -0,0 +1,12 @@ + +include $(GOROOT)/src/Make.inc + +TARG:=glfw +CGOFILES:=glfw.go +CGO_LDFLAGS:=-lglfw + +include $(GOROOT)/src/Make.pkg + +main: install main.go + $(GC) main.go + $(LD) -o $@ main.$O diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Go-OpenGL/examples/glfw/glfw.go new/Go-OpenGL/examples/glfw/glfw.go --- old/Go-OpenGL/examples/glfw/glfw.go 1970-01-01 01:00:00.000000000 +0100 +++ new/Go-OpenGL/examples/glfw/glfw.go 2012-02-02 15:40:48.000000000 +0100 @@ -0,0 +1,31 @@ +package glfw + +// #include <GL/glfw.h> +import "C" + +const ( + KEY_SPECIAL = 256 + KEY_ESC = (KEY_SPECIAL + 1) + OPENED = 0x00020001 + WINDOW = 0x00010001 +) + +func Init() int { + return int(C.glfwInit()) +} + +func OpenWindow(width int, height int, redbits int, greenbits int, bluebits int, alphabits int, depthbits int, stencilbits int, mode int) int { + return int(C.glfwOpenWindow(C.int(width), C.int(height), C.int(redbits), C.int(greenbits), C.int(bluebits), C.int(alphabits), C.int(depthbits), C.int(stencilbits), C.int(mode))) +} + +func SwapBuffers() { + C.glfwSwapBuffers() +} + +func GetWindowParam(param int) int { + return int(C.glfwGetWindowParam(C.int(param))) +} + +func GetKey(param int) int { + return int(C.glfwGetKey(C.int(param))) +} diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Go-OpenGL/examples/glfw/main.go new/Go-OpenGL/examples/glfw/main.go --- old/Go-OpenGL/examples/glfw/main.go 1970-01-01 01:00:00.000000000 +0100 +++ new/Go-OpenGL/examples/glfw/main.go 2012-02-02 15:40:48.000000000 +0100 @@ -0,0 +1,46 @@ +/* +this example uses glfw instead of Go-SDL. To try it type: + + gomake + sudo gomake install + gomake main + ./main + +*/ + +package main + +import "glfw" +import "gl" + +func main() { + + ret := glfw.Init() + + print(ret) + + ret = glfw.OpenWindow(300, 300, 0, 0, 0, 0, 0, 0, glfw.WINDOW) + + print(ret) + + if gl.Init() != 0 { + panic("glew error") + } + + running := true + + for running { + + gl.Begin(gl.TRIANGLES) + gl.Vertex3f(0, 0, 0) + gl.Vertex3f(0, 1, 0) + gl.Vertex3f(1, 1, 0) + gl.End() + + glfw.SwapBuffers() + + running = glfw.GetKey(glfw.KEY_ESC) == 0 && glfw.GetWindowParam(glfw.OPENED) != 0 + + } + +} diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Go-OpenGL/examples/glfwgears.go new/Go-OpenGL/examples/glfwgears.go --- old/Go-OpenGL/examples/glfwgears.go 1970-01-01 01:00:00.000000000 +0100 +++ new/Go-OpenGL/examples/glfwgears.go 2012-02-02 15:40:48.000000000 +0100 @@ -0,0 +1,310 @@ +package main + +/* + * 3-D gear wheels. This program is in the public domain. + * + * Command line options: + * -info print GL implementation information + * + * + * Brian Paul + */ + +/* + + this is go version based on SDL version + + this version uses glfw: https://github.com/jteeuwen/glfw + +*/ + +import "github.com/jteeuwen/glfw" +import "gl" +import "math" +import "os" +import "fmt" +import "flag" + +var printInfo = flag.Bool("info", false, "print GL implementation information") + +var T0 float64 = 0 +var Frames uint32 = 0 + +/** + + Draw a gear wheel. You'll probably want to call this function when + building a display list since we do a lot of trig here. + + Input: inner_radius - radius of hole at center + outer_radius - radius at center of teeth + width - width of gear + teeth - number of teeth + tooth_depth - depth of tooth + + **/ + +func gear(inner_radius, outer_radius, width float64, teeth int, tooth_depth float64) { + var i int + var r0, r1, r2 float64 + var angle, da float64 + var u, v, len float64 + + r0 = inner_radius + r1 = outer_radius - tooth_depth/2.0 + r2 = outer_radius + tooth_depth/2.0 + + da = 2.0 * math.Pi / float64(teeth) / 4.0 + + gl.ShadeModel(gl.FLAT) + + gl.Normal3d(0.0, 0.0, 1.0) + + /* draw front face */ + gl.Begin(gl.QUAD_STRIP) + for i = 0; i <= teeth; i++ { + angle = float64(i) * 2.0 * math.Pi / float64(teeth) + gl.Vertex3d(r0*math.Cos(angle), r0*math.Sin(angle), width*0.5) + gl.Vertex3d(r1*math.Cos(angle), r1*math.Sin(angle), width*0.5) + if i < teeth { + gl.Vertex3d(r0*math.Cos(angle), r0*math.Sin(angle), width*0.5) + gl.Vertex3d(r1*math.Cos(angle+3*da), r1*math.Sin(angle+3*da), width*0.5) + } + } + gl.End() + + /* draw front sides of teeth */ + gl.Begin(gl.QUADS) + da = 2.0 * math.Pi / float64(teeth) / 4.0 + for i = 0; i < teeth; i++ { + angle = float64(i) * 2.0 * math.Pi / float64(teeth) + + gl.Vertex3d(r1*math.Cos(angle), r1*math.Sin(angle), width*0.5) + gl.Vertex3d(r2*math.Cos(angle+da), r2*math.Sin(angle+da), width*0.5) + gl.Vertex3d(r2*math.Cos(angle+2*da), r2*math.Sin(angle+2*da), width*0.5) + gl.Vertex3d(r1*math.Cos(angle+3*da), r1*math.Sin(angle+3*da), width*0.5) + } + gl.End() + + gl.Normal3d(0.0, 0.0, -1.0) + + /* draw back face */ + gl.Begin(gl.QUAD_STRIP) + for i = 0; i <= teeth; i++ { + angle = float64(i) * 2.0 * math.Pi / float64(teeth) + gl.Vertex3d(r1*math.Cos(angle), r1*math.Sin(angle), -width*0.5) + gl.Vertex3d(r0*math.Cos(angle), r0*math.Sin(angle), -width*0.5) + if i < teeth { + gl.Vertex3d(r1*math.Cos(angle+3*da), r1*math.Sin(angle+3*da), -width*0.5) + gl.Vertex3d(r0*math.Cos(angle), r0*math.Sin(angle), -width*0.5) + } + } + gl.End() + + /* draw back sides of teeth */ + gl.Begin(gl.QUADS) + da = 2.0 * math.Pi / float64(teeth) / 4.0 + for i = 0; i < teeth; i++ { + angle = float64(i) * 2.0 * math.Pi / float64(teeth) + + gl.Vertex3d(r1*math.Cos(angle+3*da), r1*math.Sin(angle+3*da), -width*0.5) + gl.Vertex3d(r2*math.Cos(angle+2*da), r2*math.Sin(angle+2*da), -width*0.5) + gl.Vertex3d(r2*math.Cos(angle+da), r2*math.Sin(angle+da), -width*0.5) + gl.Vertex3d(r1*math.Cos(angle), r1*math.Sin(angle), -width*0.5) + } + gl.End() + + /* draw outward faces of teeth */ + gl.Begin(gl.QUAD_STRIP) + for i = 0; i < teeth; i++ { + angle = float64(i) * 2.0 * math.Pi / float64(teeth) + + gl.Vertex3d(r1*math.Cos(angle), r1*math.Sin(angle), width*0.5) + gl.Vertex3d(r1*math.Cos(angle), r1*math.Sin(angle), -width*0.5) + u = r2*math.Cos(angle+da) - r1*math.Cos(angle) + v = r2*math.Sin(angle+da) - r1*math.Sin(angle) + len = math.Sqrt(u*u + v*v) + u /= len + v /= len + gl.Normal3d(v, -u, 0.0) + gl.Vertex3d(r2*math.Cos(angle+da), r2*math.Sin(angle+da), width*0.5) + gl.Vertex3d(r2*math.Cos(angle+da), r2*math.Sin(angle+da), -width*0.5) + gl.Normal3d(math.Cos(angle), math.Sin(angle), 0.0) + gl.Vertex3d(r2*math.Cos(angle+2*da), r2*math.Sin(angle+2*da), width*0.5) + gl.Vertex3d(r2*math.Cos(angle+2*da), r2*math.Sin(angle+2*da), -width*0.5) + u = r1*math.Cos(angle+3*da) - r2*math.Cos(angle+2*da) + v = r1*math.Sin(angle+3*da) - r2*math.Sin(angle+2*da) + gl.Normal3d(v, -u, 0.0) + gl.Vertex3d(r1*math.Cos(angle+3*da), r1*math.Sin(angle+3*da), width*0.5) + gl.Vertex3d(r1*math.Cos(angle+3*da), r1*math.Sin(angle+3*da), -width*0.5) + gl.Normal3d(math.Cos(angle), math.Sin(angle), 0.0) + } + + gl.Vertex3d(r1*math.Cos(0), r1*math.Sin(0), width*0.5) + gl.Vertex3d(r1*math.Cos(0), r1*math.Sin(0), -width*0.5) + + gl.End() + + gl.ShadeModel(gl.SMOOTH) + + /* draw inside radius cylinder */ + gl.Begin(gl.QUAD_STRIP) + for i = 0; i <= teeth; i++ { + angle = float64(i) * 2.0 * math.Pi / float64(teeth) + gl.Normal3d(-math.Cos(angle), -math.Sin(angle), 0.0) + gl.Vertex3d(r0*math.Cos(angle), r0*math.Sin(angle), -width*0.5) + gl.Vertex3d(r0*math.Cos(angle), r0*math.Sin(angle), width*0.5) + } + gl.End() + +} + +var view_rotx float64 = 20.0 +var view_roty float64 = 30.0 +var view_rotz float64 = 0.0 +var gear1, gear2, gear3 uint +var angle float64 = 0.0 + +func draw() { + + gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT) + + gl.PushMatrix() + gl.Rotated(view_rotx, 1.0, 0.0, 0.0) + gl.Rotated(view_roty, 0.0, 1.0, 0.0) + gl.Rotated(view_rotz, 0.0, 0.0, 1.0) + + gl.PushMatrix() + gl.Translated(-3.0, -2.0, 0.0) + gl.Rotated(angle, 0.0, 0.0, 1.0) + gl.CallList(gear1) + gl.PopMatrix() + + gl.PushMatrix() + gl.Translated(3.1, -2.0, 0.0) + gl.Rotated(-2.0*angle-9.0, 0.0, 0.0, 1.0) + gl.CallList(gear2) + gl.PopMatrix() + + gl.PushMatrix() + gl.Translated(-3.1, 4.2, 0.0) + gl.Rotated(-2.0*angle-25.0, 0.0, 0.0, 1.0) + gl.CallList(gear3) + gl.PopMatrix() + + gl.PopMatrix() + + glfw.SwapBuffers() + + Frames++ + { + t := glfw.Time() + if t-T0 >= 5 { + seconds := (t - T0) + fps := float64(Frames) / seconds + print(Frames, " frames in ", int(seconds), " seconds = ", int(fps), " FPS\n") + T0 = t + Frames = 0 + } + } +} + + +func idle() { + angle += 2.0 +} + +/* new window size or exposure */ +func reshape(width int, height int) { + + h := float64(height) / float64(width) + + gl.Viewport(0, 0, width, height) + gl.MatrixMode(gl.PROJECTION) + gl.LoadIdentity() + gl.Frustum(-1.0, 1.0, -h, h, 5.0, 60.0) + gl.MatrixMode(gl.MODELVIEW) + gl.LoadIdentity() + gl.Translatef(0.0, 0.0, -40.0) +} + +func init_() { + pos := []float32{5.0, 5.0, 10.0, 0.0} + red := []float32{0.8, 0.1, 0.0, 1.0} + green := []float32{0.0, 0.8, 0.2, 1.0} + blue := []float32{0.2, 0.2, 1.0, 1.0} + + gl.Lightfv(gl.LIGHT0, gl.POSITION, pos) + gl.Enable(gl.CULL_FACE) + gl.Enable(gl.LIGHTING) + gl.Enable(gl.LIGHT0) + gl.Enable(gl.DEPTH_TEST) + + /* make the gears */ + gear1 = gl.GenLists(1) + gl.NewList(gear1, gl.COMPILE) + gl.Materialfv(gl.FRONT, gl.AMBIENT_AND_DIFFUSE, red) + gear(1.0, 4.0, 1.0, 20, 0.7) + gl.EndList() + + gear2 = gl.GenLists(1) + gl.NewList(gear2, gl.COMPILE) + gl.Materialfv(gl.FRONT, gl.AMBIENT_AND_DIFFUSE, green) + gear(0.5, 2.0, 2.0, 10, 0.7) + gl.EndList() + + gear3 = gl.GenLists(1) + gl.NewList(gear3, gl.COMPILE) + gl.Materialfv(gl.FRONT, gl.AMBIENT_AND_DIFFUSE, blue) + gear(1.3, 2.0, 0.5, 10, 0.7) + gl.EndList() + + gl.Enable(gl.NORMALIZE) + + if *printInfo { + print("GL_RENDERER = ", gl.GetString(gl.RENDERER), "\n") + print("GL_VERSION = ", gl.GetString(gl.VERSION), "\n") + print("GL_VENDOR = ", gl.GetString(gl.VENDOR), "\n") + print("GL_EXTENSIONS = ", gl.GetString(gl.EXTENSIONS), "\n") + } + +} + +func main() { + + flag.Parse() + + var done bool + + var err os.Error + if err = glfw.Init(); err != nil { + fmt.Fprintf(os.Stderr, "[e] %v\n", err) + return + } + + defer glfw.Terminate() + + if err = glfw.OpenWindow(300, 300, 0, 0, 0, 0, 0, 0, glfw.Windowed); err != nil { + fmt.Fprintf(os.Stderr, "[e] %v\n", err) + return + } + + if gl.Init() != 0 { + panic("gl error") + } + + defer glfw.CloseWindow() + + glfw.SetWindowTitle("gears") + + glfw.SetWindowSizeCallback(reshape) + + init_() + reshape(300,300) + done = false + for !done { + idle(); + draw() + done = glfw.Key(glfw.KeyEsc) != 0 || glfw.WindowParam(glfw.Opened) == 0 + } + +} diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Go-OpenGL/examples/gomandel.go new/Go-OpenGL/examples/gomandel.go --- old/Go-OpenGL/examples/gomandel.go 2011-06-17 11:02:07.000000000 +0200 +++ new/Go-OpenGL/examples/gomandel.go 2012-02-02 15:40:48.000000000 +0100 @@ -439,29 +439,31 @@ rc.WaitFor(Small, &tex, &tc) running := true - e := new(sdl.Event) for running { - for e.Poll() { - switch e.Type { - case sdl.QUIT: + for e := sdl.PollEvent(); e != nil; e = sdl.PollEvent() { + switch e.(type) { + case *sdl.QuitEvent: running = false - case sdl.MOUSEBUTTONDOWN: - dndDragging = true - sdl.GetMouseState(&dndStart.X, &dndStart.Y) - dndEnd = dndStart - case sdl.MOUSEBUTTONUP: - dndDragging = false - sdl.GetMouseState(&dndEnd.X, &dndEnd.Y) - if e.MouseButton().Button == 3 { - rect = initialRect + case *sdl.MouseButtonEvent: + mbe := e.(*sdl.MouseButtonEvent) + if(mbe.Type == sdl.MOUSEBUTTONDOWN) { + dndDragging = true + sdl.GetMouseState(&dndStart.X, &dndStart.Y) + dndEnd = dndStart } else { - rect = rectFromSelection(dndStart, dndEnd, 512, 512, rect) - tc = texCoordsFromSelection(dndStart, dndEnd, 512, 512, tc) - } + dndDragging = false + sdl.GetMouseState(&dndEnd.X, &dndEnd.Y) + if mbe.Which == 3 { + rect = initialRect + } else { + rect = rectFromSelection(dndStart, dndEnd, 512, 512, rect) + tc = texCoordsFromSelection(dndStart, dndEnd, 512, 512, tc) + } - // make request - rc.MakeRequest(512, 512, rect) - case sdl.MOUSEMOTION: + // make request + rc.MakeRequest(512, 512, rect) + } + case *sdl.MouseMotionEvent: if dndDragging { sdl.GetMouseState(&dndEnd.X, &dndEnd.Y) } diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Go-OpenGL/examples/sdlgears.go new/Go-OpenGL/examples/sdlgears.go --- old/Go-OpenGL/examples/sdlgears.go 1970-01-01 01:00:00.000000000 +0100 +++ new/Go-OpenGL/examples/sdlgears.go 2012-02-02 15:40:48.000000000 +0100 @@ -0,0 +1,346 @@ +package main + +/* + * 3-D gear wheels. This program is in the public domain. + * + * Command line options: + * -info print GL implementation information + * + * + * Brian Paul + */ + +/* + + this is go version based on SDL version + + this version uses Go-SDL: https://github.com/banthar/Go-SDL + +*/ + +import "sdl" +import "gl" +import "math" +import "flag" + +var printInfo = flag.Bool("info", false, "print GL implementation information") + +var T0 uint32 = 0 +var Frames uint32 = 0 + +/** + + Draw a gear wheel. You'll probably want to call this function when + building a display list since we do a lot of trig here. + + Input: inner_radius - radius of hole at center + outer_radius - radius at center of teeth + width - width of gear + teeth - number of teeth + tooth_depth - depth of tooth + + **/ + +func gear(inner_radius, outer_radius, width float64, teeth int, tooth_depth float64) { + var i int + var r0, r1, r2 float64 + var angle, da float64 + var u, v, len float64 + + r0 = inner_radius + r1 = outer_radius - tooth_depth/2.0 + r2 = outer_radius + tooth_depth/2.0 + + da = 2.0 * math.Pi / float64(teeth) / 4.0 + + gl.ShadeModel(gl.FLAT) + + gl.Normal3d(0.0, 0.0, 1.0) + + /* draw front face */ + gl.Begin(gl.QUAD_STRIP) + for i = 0; i <= teeth; i++ { + angle = float64(i) * 2.0 * math.Pi / float64(teeth) + gl.Vertex3d(r0*math.Cos(angle), r0*math.Sin(angle), width*0.5) + gl.Vertex3d(r1*math.Cos(angle), r1*math.Sin(angle), width*0.5) + if i < teeth { + gl.Vertex3d(r0*math.Cos(angle), r0*math.Sin(angle), width*0.5) + gl.Vertex3d(r1*math.Cos(angle+3*da), r1*math.Sin(angle+3*da), width*0.5) + } + } + gl.End() + + /* draw front sides of teeth */ + gl.Begin(gl.QUADS) + da = 2.0 * math.Pi / float64(teeth) / 4.0 + for i = 0; i < teeth; i++ { + angle = float64(i) * 2.0 * math.Pi / float64(teeth) + + gl.Vertex3d(r1*math.Cos(angle), r1*math.Sin(angle), width*0.5) + gl.Vertex3d(r2*math.Cos(angle+da), r2*math.Sin(angle+da), width*0.5) + gl.Vertex3d(r2*math.Cos(angle+2*da), r2*math.Sin(angle+2*da), width*0.5) + gl.Vertex3d(r1*math.Cos(angle+3*da), r1*math.Sin(angle+3*da), width*0.5) + } + gl.End() + + gl.Normal3d(0.0, 0.0, -1.0) + + /* draw back face */ + gl.Begin(gl.QUAD_STRIP) + for i = 0; i <= teeth; i++ { + angle = float64(i) * 2.0 * math.Pi / float64(teeth) + gl.Vertex3d(r1*math.Cos(angle), r1*math.Sin(angle), -width*0.5) + gl.Vertex3d(r0*math.Cos(angle), r0*math.Sin(angle), -width*0.5) + if i < teeth { + gl.Vertex3d(r1*math.Cos(angle+3*da), r1*math.Sin(angle+3*da), -width*0.5) + gl.Vertex3d(r0*math.Cos(angle), r0*math.Sin(angle), -width*0.5) + } + } + gl.End() + + /* draw back sides of teeth */ + gl.Begin(gl.QUADS) + da = 2.0 * math.Pi / float64(teeth) / 4.0 + for i = 0; i < teeth; i++ { + angle = float64(i) * 2.0 * math.Pi / float64(teeth) + + gl.Vertex3d(r1*math.Cos(angle+3*da), r1*math.Sin(angle+3*da), -width*0.5) + gl.Vertex3d(r2*math.Cos(angle+2*da), r2*math.Sin(angle+2*da), -width*0.5) + gl.Vertex3d(r2*math.Cos(angle+da), r2*math.Sin(angle+da), -width*0.5) + gl.Vertex3d(r1*math.Cos(angle), r1*math.Sin(angle), -width*0.5) + } + gl.End() + + /* draw outward faces of teeth */ + gl.Begin(gl.QUAD_STRIP) + for i = 0; i < teeth; i++ { + angle = float64(i) * 2.0 * math.Pi / float64(teeth) + + gl.Vertex3d(r1*math.Cos(angle), r1*math.Sin(angle), width*0.5) + gl.Vertex3d(r1*math.Cos(angle), r1*math.Sin(angle), -width*0.5) + u = r2*math.Cos(angle+da) - r1*math.Cos(angle) + v = r2*math.Sin(angle+da) - r1*math.Sin(angle) + len = math.Sqrt(u*u + v*v) + u /= len + v /= len + gl.Normal3d(v, -u, 0.0) + gl.Vertex3d(r2*math.Cos(angle+da), r2*math.Sin(angle+da), width*0.5) + gl.Vertex3d(r2*math.Cos(angle+da), r2*math.Sin(angle+da), -width*0.5) + gl.Normal3d(math.Cos(angle), math.Sin(angle), 0.0) + gl.Vertex3d(r2*math.Cos(angle+2*da), r2*math.Sin(angle+2*da), width*0.5) + gl.Vertex3d(r2*math.Cos(angle+2*da), r2*math.Sin(angle+2*da), -width*0.5) + u = r1*math.Cos(angle+3*da) - r2*math.Cos(angle+2*da) + v = r1*math.Sin(angle+3*da) - r2*math.Sin(angle+2*da) + gl.Normal3d(v, -u, 0.0) + gl.Vertex3d(r1*math.Cos(angle+3*da), r1*math.Sin(angle+3*da), width*0.5) + gl.Vertex3d(r1*math.Cos(angle+3*da), r1*math.Sin(angle+3*da), -width*0.5) + gl.Normal3d(math.Cos(angle), math.Sin(angle), 0.0) + } + + gl.Vertex3d(r1*math.Cos(0), r1*math.Sin(0), width*0.5) + gl.Vertex3d(r1*math.Cos(0), r1*math.Sin(0), -width*0.5) + + gl.End() + + gl.ShadeModel(gl.SMOOTH) + + /* draw inside radius cylinder */ + gl.Begin(gl.QUAD_STRIP) + for i = 0; i <= teeth; i++ { + angle = float64(i) * 2.0 * math.Pi / float64(teeth) + gl.Normal3d(-math.Cos(angle), -math.Sin(angle), 0.0) + gl.Vertex3d(r0*math.Cos(angle), r0*math.Sin(angle), -width*0.5) + gl.Vertex3d(r0*math.Cos(angle), r0*math.Sin(angle), width*0.5) + } + gl.End() + +} + +var view_rotx float64 = 20.0 +var view_roty float64 = 30.0 +var view_rotz float64 = 0.0 +var gear1, gear2, gear3 uint +var angle float64 = 0.0 + +func draw() { + + gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT) + + gl.PushMatrix() + gl.Rotated(view_rotx, 1.0, 0.0, 0.0) + gl.Rotated(view_roty, 0.0, 1.0, 0.0) + gl.Rotated(view_rotz, 0.0, 0.0, 1.0) + + gl.PushMatrix() + gl.Translated(-3.0, -2.0, 0.0) + gl.Rotated(angle, 0.0, 0.0, 1.0) + gl.CallList(gear1) + gl.PopMatrix() + + gl.PushMatrix() + gl.Translated(3.1, -2.0, 0.0) + gl.Rotated(-2.0*angle-9.0, 0.0, 0.0, 1.0) + gl.CallList(gear2) + gl.PopMatrix() + + gl.PushMatrix() + gl.Translated(-3.1, 4.2, 0.0) + gl.Rotated(-2.0*angle-25.0, 0.0, 0.0, 1.0) + gl.CallList(gear3) + gl.PopMatrix() + + gl.PopMatrix() + + sdl.GL_SwapBuffers() + + Frames++ + { + t := sdl.GetTicks() + if t-T0 >= 5000 { + seconds := (t - T0) / 1000.0 + fps := Frames / seconds + print(Frames, " frames in ", seconds, " seconds = ", fps, " FPS\n") + T0 = t + Frames = 0 + } + } +} + + +func idle() { + angle += 2.0 +} + +/* new window size or exposure */ +func reshape(width int, height int) { + + h := float64(height) / float64(width) + + gl.Viewport(0, 0, width, height) + gl.MatrixMode(gl.PROJECTION) + gl.LoadIdentity() + gl.Frustum(-1.0, 1.0, -h, h, 5.0, 60.0) + gl.MatrixMode(gl.MODELVIEW) + gl.LoadIdentity() + gl.Translatef(0.0, 0.0, -40.0) +} + +func init_() { + pos := []float32{5.0, 5.0, 10.0, 0.0} + red := []float32{0.8, 0.1, 0.0, 1.0} + green := []float32{0.0, 0.8, 0.2, 1.0} + blue := []float32{0.2, 0.2, 1.0, 1.0} + + gl.Lightfv(gl.LIGHT0, gl.POSITION, pos) + gl.Enable(gl.CULL_FACE) + gl.Enable(gl.LIGHTING) + gl.Enable(gl.LIGHT0) + gl.Enable(gl.DEPTH_TEST) + + /* make the gears */ + gear1 = gl.GenLists(1) + gl.NewList(gear1, gl.COMPILE) + gl.Materialfv(gl.FRONT, gl.AMBIENT_AND_DIFFUSE, red) + gear(1.0, 4.0, 1.0, 20, 0.7) + gl.EndList() + + gear2 = gl.GenLists(1) + gl.NewList(gear2, gl.COMPILE) + gl.Materialfv(gl.FRONT, gl.AMBIENT_AND_DIFFUSE, green) + gear(0.5, 2.0, 2.0, 10, 0.7) + gl.EndList() + + gear3 = gl.GenLists(1) + gl.NewList(gear3, gl.COMPILE) + gl.Materialfv(gl.FRONT, gl.AMBIENT_AND_DIFFUSE, blue) + gear(1.3, 2.0, 0.5, 10, 0.7) + gl.EndList() + + gl.Enable(gl.NORMALIZE) + + if *printInfo { + print("GL_RENDERER = ", gl.GetString(gl.RENDERER), "\n") + print("GL_VERSION = ", gl.GetString(gl.VERSION), "\n") + print("GL_VENDOR = ", gl.GetString(gl.VENDOR), "\n") + print("GL_EXTENSIONS = ", gl.GetString(gl.EXTENSIONS), "\n") + } + +} + +func main() { + + flag.Parse() + + var done bool + var keys []uint8 + + sdl.Init(sdl.INIT_VIDEO) + + var screen = sdl.SetVideoMode(300, 300, 16, sdl.OPENGL|sdl.RESIZABLE) + + if screen == nil { + sdl.Quit() + panic("Couldn't set 300x300 GL video mode: " + sdl.GetError() + "\n") + } + + if gl.Init() != 0 { + panic("gl error") + } + + sdl.WM_SetCaption("Gears", "gears") + + init_() + reshape(int(screen.W), int(screen.H)) + done = false + for !done { + + idle() + for e := sdl.PollEvent(); e != nil; e = sdl.PollEvent() { + switch e.(type) { + case *sdl.ResizeEvent: + re := e.(*sdl.ResizeEvent) + screen = sdl.SetVideoMode(int(re.W), int(re.H), 16, + sdl.OPENGL|sdl.RESIZABLE) + if screen != nil { + reshape(int(screen.W), int(screen.H)) + } else { + panic("we couldn't set the new video mode??") + } + break + + case *sdl.QuitEvent: + done = true + break + } + } + keys = sdl.GetKeyState() + + if keys[sdl.K_ESCAPE] != 0 { + done = true + } + if keys[sdl.K_UP] != 0 { + view_rotx += 5.0 + } + if keys[sdl.K_DOWN] != 0 { + view_rotx -= 5.0 + } + if keys[sdl.K_LEFT] != 0 { + view_roty += 5.0 + } + if keys[sdl.K_RIGHT] != 0 { + view_roty -= 5.0 + } + if keys[sdl.K_z] != 0 { + if (sdl.GetModState() & sdl.KMOD_RSHIFT) != 0 { + view_rotz -= 5.0 + } else { + view_rotz += 5.0 + } + } + + draw() + } + sdl.Quit() + return + +} diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Go-OpenGL/gl/Makefile new/Go-OpenGL/gl/Makefile --- old/Go-OpenGL/gl/Makefile 2011-06-17 11:02:07.000000000 +0200 +++ new/Go-OpenGL/gl/Makefile 2012-02-02 15:40:48.000000000 +0100 @@ -10,12 +10,6 @@ CGOFILES:=gl.go -ifeq ($(GOOS),darwin) -CGO_LDFLAGS:=-framework OpenGL -lGLEW -lGL -else -CGO_LDFLAGS:=-lGLEW -lGL -endif - CLEANFILES+=gl include $(GOROOT)/src/Make.pkg diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Go-OpenGL/gl/gl.go new/Go-OpenGL/gl/gl.go --- old/Go-OpenGL/gl/gl.go 2011-06-17 11:02:07.000000000 +0200 +++ new/Go-OpenGL/gl/gl.go 2012-02-02 15:40:48.000000000 +0100 @@ -1,5 +1,9 @@ package gl +// #cgo darwin LDFLAGS: -framework OpenGL -lGLEW -lGL +// #cgo windows LDFLAGS: -lglew32 -lopengl32 +// #cgo linux LDFLAGS: -lGLEW -lGL +// // #include <stdlib.h> // // #ifdef __APPLE__ @@ -10,7 +14,6 @@ // // #undef GLEW_GET_FUN // #define GLEW_GET_FUN(x) (*x) -// import "C" import "unsafe" import "reflect" @@ -89,6 +92,8 @@ t = INT case reflect.Float32: t = FLOAT + case reflect.Float64: + t = DOUBLE default: panic("unknown type: " + reflect.TypeOf(v).String()) } @@ -100,14 +105,17 @@ type Object C.GLuint -func (buffer Object) IsBuffer() bool { return C.glIsBuffer(C.GLuint(buffer)) != 0 } +func (object Object) IsBuffer() bool { return C.glIsBuffer(C.GLuint(object)) != 0 } +func (object Object) IsProgram() bool { return C.glIsProgram(C.GLuint(object)) != 0 } -func (program Object) IsProgram() bool { return C.glIsProgram(C.GLuint(program)) != 0 } +func (object Object) IsShader() bool { return C.glIsShader(C.GLuint(object)) != 0 } -func (shader Object) IsShader() bool { return C.glIsShader(C.GLuint(shader)) != 0 } +func (object Object) IsTexture() bool { return C.glIsTexture(C.GLuint(object)) != 0 } -func (texture Object) IsTexture() bool { return C.glIsTexture(C.GLuint(texture)) != 0 } +func (object Object) IsTransformFeedback() bool { return C.glIsTransformFeedback(C.GLuint(object)) != 0 } + +func (object Object) IsVertexArray() bool { return C.glIsVertexArray(C.GLuint(object)) != 0 } // Shader @@ -187,6 +195,23 @@ C.glDetachShader(C.GLuint(program), C.GLuint(shader)) } +func (program Program) TransformFeedbackVaryings (names []string, buffer_mode GLenum) { + if len(names) == 0 { + C.glTransformFeedbackVaryings(C.GLuint(program), 0, (**C.GLchar)(nil), C.GLenum(buffer_mode)) + } else { + gl_names := make([]*C.GLchar, len(names)) + + for i := range(names) { + gl_names[i] = glString(names[i]) + } + + C.glTransformFeedbackVaryings(C.GLuint(program), C.GLsizei(len(gl_names)), &gl_names[0], C.GLenum(buffer_mode)) + + for _, s := range(gl_names) { + freeString(s) + } + } +} func (program Program) Link() { C.glLinkProgram(C.GLuint(program)) } @@ -235,16 +260,16 @@ return UniformLocation(C.glGetUniformLocation(C.GLuint(program), cname)) } -func (program Program) GetAttribLocation(name string) VertexAttrib { +func (program Program) GetAttribLocation(name string) AttribLocation { cname := glString(name) defer freeString(cname) - return VertexAttrib(C.glGetAttribLocation(C.GLuint(program), cname)) + return AttribLocation(C.glGetAttribLocation(C.GLuint(program), cname)) } -func (program Program) BindAttribLocation(index uint, name string) { +func (program Program) BindAttribLocation(index AttribLocation, name string) { cname := glString(name) defer freeString(cname) @@ -285,6 +310,11 @@ C.glBindTexture(C.GLenum(target), C.GLuint(texture)) } +// Unbind this texture +func (texture Texture) Unbind(target GLenum) { + C.glBindTexture(C.GLenum(target), 0) +} + //void glTexImage1D (GLenum target, int level, int internalformat, int width, int border, GLenum format, GLenum type, const GLvoid *pixels) func TexImage1D(target GLenum, level int, internalformat int, width int, border int, format GLenum, pixels interface{}) { t, p := GetGLenumType(pixels) @@ -292,9 +322,16 @@ } //void glTexImage2D (GLenum target, int level, int internalformat, int width, int height, int border, GLenum format, GLenum type, const GLvoid *pixels) -func TexImage2D(target GLenum, level int, internalformat int, width int, height int, border int, format GLenum, pixels interface{}) { - t, p := GetGLenumType(pixels) - C.glTexImage2D(C.GLenum(target), C.GLint(level), C.GLint(internalformat), C.GLsizei(width), C.GLsizei(height), C.GLint(border), C.GLenum(format), C.GLenum(t), p) +func TexImage2D(target GLenum, level int, internalformat int, width int, height int, border int, format, typ GLenum, pixels interface{}) { + if pixels == nil { + C.glTexImage2D(C.GLenum(target), C.GLint(level), C.GLint(internalformat), + C.GLsizei(width), C.GLsizei(height), C.GLint(border), C.GLenum(format), C.GLenum(typ), nil) + return + } + + _, p := GetGLenumType(pixels) + C.glTexImage2D(C.GLenum(target), C.GLint(level), C.GLint(internalformat), + C.GLsizei(width), C.GLsizei(height), C.GLint(border), C.GLenum(format), C.GLenum(typ), p) } //void glPixelMapfv (GLenum map, int mapsize, const float *values) @@ -504,6 +541,16 @@ C.glBindBuffer(C.GLenum(target), C.GLuint(buffer)) } +// Bind this buffer as index of target +func (buffer Buffer) BindBufferBase(target GLenum, index uint) { + C.glBindBufferBase(C.GLenum(target), C.GLuint(index), C.GLuint(buffer)) +} + +// Bind this buffer range as index of target +func (buffer Buffer) BindBufferRange(target GLenum, index uint, offset int, size uint) { + C.glBindBufferRange(C.GLenum(target), C.GLuint(index), C.GLuint(buffer), C.GLintptr(offset), C.GLsizeiptr(size)) +} + // Creates and initializes a buffer object's data store func BufferData(target GLenum, size int, data interface{}, usage GLenum) { _, p := GetGLenumType(data) @@ -542,51 +589,135 @@ C.glGetBufferParameteriv(C.GLenum(target), C.GLenum(pname), (*C.GLint)(¶ms[0])) } -// VertexAttrib +// Transform Feedback Objects + +type TransformFeedback Object + +// Create a single transform feedback object +func GenTransformFeedback() TransformFeedback { + var t C.GLuint + C.glGenTransformFeedbacks(1, &t) + return TransformFeedback(t) +} + +// Fill slice with new transform feedbacks +func GenTransformFeedbacks(feedbacks []TransformFeedback) { + C.glGenBuffers(C.GLsizei(len(feedbacks)), (*C.GLuint)(&feedbacks[0])) +} + +// Delete a transform feedback object +func (feedback TransformFeedback) Delete() { + C.glDeleteTransformFeedbacks(1, (*C.GLuint)(&feedback)) +} + +// Draw the results of the last Begin/End cycle from this transform feedback using primitive type 'mode' +func (feedback TransformFeedback) Draw(mode GLenum) { + C.glDrawTransformFeedback(C.GLenum(mode), C.GLuint(feedback)) +} + +// Delete all transform feedbacks in a slice +func DeleteTransformFeedbacks(feedbacks []TransformFeedback) { + C.glDeleteTransformFeedbacks(C.GLsizei(len(feedbacks)), (*C.GLuint)(&feedbacks[0])) +} -type VertexAttrib int +// Bind this transform feedback as target +func (feedback TransformFeedback) Bind(target GLenum) { + C.glBindTransformFeedback(C.GLenum(target), C.GLuint(feedback)) +} -func VertexAttrib1f(indx uint, x float32) { +// Begin transform feedback with primitive type 'mode' +func BeginTransformFeedback(mode GLenum) { + C.glBeginTransformFeedback(C.GLenum(mode)) +} + +// Pause transform feedback +func PauseTransformFeedback() { + C.glPauseTransformFeedback() +} + +// End transform feedback +func EndTransformFeedback() { + C.glEndTransformFeedback() +} + +// AttribLocation + +type AttribLocation int + +func (indx AttribLocation) Attrib1f(x float32) { C.glVertexAttrib1f(C.GLuint(indx), C.GLfloat(x)) } -func VertexAttrib1fv(indx uint, values []float32) { +func (indx AttribLocation) Attrib1fv(values []float32) { //no range check C.glVertexAttrib1fv(C.GLuint(indx), (*C.GLfloat)(unsafe.Pointer(&values[0]))) } -func VertexAttrib2f(indx uint, x float32, y float32) { +func (indx AttribLocation) Attrib2f(x float32, y float32) { C.glVertexAttrib2f(C.GLuint(indx), C.GLfloat(x), C.GLfloat(y)) } -func VertexAttrib2fv(indx uint, values []float32) { +func (indx AttribLocation) Attrib2fv(values []float32) { //no range check C.glVertexAttrib2fv(C.GLuint(indx), (*C.GLfloat)(unsafe.Pointer(&values[0]))) } -func VertexAttrib3f(indx uint, x float32, y float32, z float32) { +func (indx AttribLocation) Attrib3f(x float32, y float32, z float32) { C.glVertexAttrib3f(C.GLuint(indx), C.GLfloat(x), C.GLfloat(y), C.GLfloat(z)) } -func VertexAttrib3fv(indx uint, values []float32) { +func (indx AttribLocation) Attrib3fv(values []float32) { //no range check C.glVertexAttrib3fv(C.GLuint(indx), (*C.GLfloat)(unsafe.Pointer(&values[0]))) } -func VertexAttrib4f(indx uint, x float32, y float32, z float32, w float32) { +func (indx AttribLocation) Attrib4f(x float32, y float32, z float32, w float32) { C.glVertexAttrib4f(C.GLuint(indx), C.GLfloat(x), C.GLfloat(y), C.GLfloat(z), C.GLfloat(w)) } -func VertexAttrib4fv(indx uint, values []float32) { +func (indx AttribLocation) Attrib4fv(values []float32) { //no range check C.glVertexAttrib4fv(C.GLuint(indx), (*C.GLfloat)(unsafe.Pointer(&values[0]))) } -func VertexAttribPointer(indx VertexAttrib, size uint, normalized bool, stride int, pointer interface{}) { +func (indx AttribLocation) AttribPointer(size uint, normalized bool, stride int, pointer interface{}) { t, p := GetGLenumType(pointer) C.glVertexAttribPointer(C.GLuint(indx), C.GLint(size), C.GLenum(t), glBool(normalized), C.GLsizei(stride), p) } +func (indx AttribLocation) EnableArray() { + C.glEnableVertexAttribArray(C.GLuint(indx)) +} + +func (indx AttribLocation) DisableArray() { + C.glDisableVertexAttribArray(C.GLuint(indx)) +} + + +// Vertex Arrays +type VertexArray Object + +func GenVertexArray () VertexArray { + var a C.GLuint + C.glGenVertexArrays(1, &a) + return VertexArray(a) +} + +func GenVertexArrays (arrays []VertexArray) { + C.glGenVertexArrays(C.GLsizei(len(arrays)), (*C.GLuint)(&arrays[0])) +} + +func (array VertexArray) Delete () { + C.glDeleteVertexArrays(1, (*C.GLuint)(&array)) +} + +func DeleteVertexArrays (arrays []VertexArray) { + C.glDeleteVertexArrays(C.GLsizei(len(arrays)), (*C.GLuint)(&arrays[0])) +} + +func (array VertexArray) Bind () { + C.glBindVertexArray(C.GLuint(array)) +} // UniformLocation //TODO @@ -694,14 +825,6 @@ C.glBlendFuncSeparate(C.GLenum(srcRGB), C.GLenum(dstRGB), C.GLenum(srcAlpha), C.GLenum(dstAlpha)) } -func DisableVertexAttribArray(index VertexAttrib) { - C.glDisableVertexAttribArray(C.GLuint(index)) -} - -func EnableVertexAttribArray(index VertexAttrib) { - C.glEnableVertexAttribArray(C.GLuint(index)) -} - func SampleCoverage(value GLclampf, invert bool) { C.glSampleCoverage(C.GLclampf(value), glBool(invert)) } @@ -1040,9 +1163,9 @@ } //void glDrawPixels (GLsizei width, int height, GLenum format, GLenum type, const GLvoid *pixels) -func DrawPixels(width int, height int, format GLenum, pixels interface{}) { - t, p := GetGLenumType(pixels) - C.glDrawPixels(C.GLsizei(width), C.GLsizei(height), C.GLenum(format), C.GLenum(t), p) +func DrawPixels(width int, height int, format, typ GLenum, pixels interface{}) { + _, p := GetGLenumType(pixels) + C.glDrawPixels(C.GLsizei(width), C.GLsizei(height), C.GLenum(format), C.GLenum(typ), p) } //void glEdgeFlag (bool flag) @@ -1889,8 +2012,8 @@ } //void glSelectBuffer (GLsizei size, uint *buffer) -func SelectBuffer(size int, buffer *uint32) { - C.glSelectBuffer(C.GLsizei(size), (*C.GLuint)(buffer)) +func SelectBuffer(buffer []uint32) { + C.glSelectBuffer(C.GLsizei(len(buffer)), (*C.GLuint)(&buffer[0])) } //void glShadeModel (GLenum mode) @@ -2237,8 +2360,13 @@ } // void glBindRenderbuffer(GLenum target, GLuint renderbuffer); -func (rb Renderbuffer) Bind(target GLenum) { - C.glBindRenderbuffer(C.GLenum(target), C.GLuint(rb)) +func (rb Renderbuffer) Bind() { + C.glBindRenderbuffer(C.GLenum(RENDERBUFFER), C.GLuint(rb)) +} + +// Unbind this texture +func (rb Renderbuffer) Unbind() { + C.glBindRenderbuffer(C.GLenum(RENDERBUFFER), 0) } // void glDeleteRenderbuffers(GLsizei n, GLuint* renderbuffers); @@ -2270,8 +2398,12 @@ type Framebuffer Object // void glBindFramebuffer(GLenum target, GLuint framebuffer); -func (fb Framebuffer) Bind(target GLenum) { - C.glBindFramebuffer(C.GLenum(target), C.GLuint(fb)) +func (fb Framebuffer) Bind() { + C.glBindFramebuffer(C.GLenum(FRAMEBUFFER), C.GLuint(fb)) +} + +func (fb Framebuffer) Unbind() { + C.glBindFramebuffer(C.GLenum(FRAMEBUFFER), 0) } // void glBlitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter); @@ -2285,7 +2417,7 @@ } // void glDeleteFramebuffers(GLsizei n, GLuint* framebuffers); -func (fb Framebuffer) DeleteFramebuffer() { +func (fb Framebuffer) Delete() { C.glDeleteFramebuffers(1, (*C.GLuint)(&fb)) } diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Go-OpenGL/gl/gl_defs.c new/Go-OpenGL/gl/gl_defs.c --- old/Go-OpenGL/gl/gl_defs.c 2011-06-17 11:02:07.000000000 +0200 +++ new/Go-OpenGL/gl/gl_defs.c 2012-02-02 15:40:48.000000000 +0100 @@ -1203,6 +1203,7 @@ $TEXTURE = GL_TEXTURE, $TIMEOUT_EXPIRED = GL_TIMEOUT_EXPIRED, $TIMEOUT_IGNORED = GL_TIMEOUT_IGNORED, + $TRANSFORM_FEEDBACK = GL_TRANSFORM_FEEDBACK, $TRANSFORM_BIT = GL_TRANSFORM_BIT, $TRANSFORM_FEEDBACK_BUFFER_BINDING = GL_TRANSFORM_FEEDBACK_BUFFER_BINDING, $TRANSFORM_FEEDBACK_BUFFER_MODE = GL_TRANSFORM_FEEDBACK_BUFFER_MODE, diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Go-OpenGL/gl/gl_defs.go new/Go-OpenGL/gl/gl_defs.go --- old/Go-OpenGL/gl/gl_defs.go 2011-06-17 11:02:07.000000000 +0200 +++ new/Go-OpenGL/gl/gl_defs.go 2012-02-02 15:40:48.000000000 +0100 @@ -1,4 +1,4 @@ -// godefs -g gl gl_defs.c +// c:\Users\Joshwa\Documents\MinGW\go\bin\godefs.exe -g gl gl_defs.c // MACHINE GENERATED - DO NOT EDIT. @@ -116,7 +116,7 @@ CLAMP = 0x2900 CLEAR = 0x1500 CLIENT_ACTIVE_TEXTURE = 0x84e1 - CLIENT_ALL_ATTRIB_BITS = 0xffffffff + CLIENT_ALL_ATTRIB_BITS = -0x1 CLIENT_ATTRIB_STACK_DEPTH = 0xbb1 CLIENT_PIXEL_STORE_BIT = 0x1 CLIENT_VERTEX_ARRAY_BIT = 0x2 @@ -480,7 +480,7 @@ INT = 0x1404 INVALID_ENUM = 0x500 INVALID_FRAMEBUFFER_OPERATION = 0x506 - INVALID_INDEX = 0xffffffff + INVALID_INDEX = -0x1 INVALID_OPERATION = 0x502 INVALID_VALUE = 0x501 INVERTED_SCREEN_W_REND = 0x8491 @@ -1203,6 +1203,7 @@ TEXTURE = 0x1702 TIMEOUT_EXPIRED = 0x911b TIMEOUT_IGNORED = -0x1 + TRANSFORM_FEEDBACK = 0x8e22 TRANSFORM_BIT = 0x1000 TRANSFORM_FEEDBACK_BUFFER_BINDING = 0x8c8f TRANSFORM_FEEDBACK_BUFFER_MODE = 0x8c7f diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Go-OpenGL/glu/Makefile new/Go-OpenGL/glu/Makefile --- old/Go-OpenGL/glu/Makefile 2011-06-17 11:02:07.000000000 +0200 +++ new/Go-OpenGL/glu/Makefile 2012-02-02 15:40:48.000000000 +0100 @@ -8,12 +8,6 @@ CGOFILES:=glu.go -ifeq ($(GOOS),darwin) -CGO_LDFLAGS:=-framework OpenGL -else -CGO_LDFLAGS:=-lGLU -endif - GC="${O}g" -I ../gl/_obj include $(GOROOT)/src/Make.pkg diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Go-OpenGL/glu/glu.go new/Go-OpenGL/glu/glu.go --- old/Go-OpenGL/glu/glu.go 2011-06-17 11:02:07.000000000 +0200 +++ new/Go-OpenGL/glu/glu.go 2012-02-02 15:47:59.000000000 +0100 @@ -1,14 +1,16 @@ package glu +// #cgo darwin LDFLAGS: -framework OpenGL +// #cgo windows LDFLAGS: -lglu32 +// #cgo linux LDFLAGS: -lGLU +// // #ifdef __APPLE__ // # include <OpenGL/glu.h> // #else // # include <GL/glu.h> // #endif -// -// import "C" -import "gl" +import "github.com/banthar/Go-OpenGL/gl" func Build2DMipmaps(target gl.GLenum, internalFormat int, width, height int, format gl.GLenum, data interface{}) int { t, p := gl.GetGLenumType(data) @@ -45,3 +47,43 @@ C.GLdouble(upZ), ) } + +// Project object coordinates to screen coordinates. +func Project(objx, objy, objz float64, model, proj []float64, view []int32) (x, y, z float64) { + var wx, wy, wz C.GLdouble + C.gluProject( + C.GLdouble(objx), C.GLdouble(objy), C.GLdouble(objz), (*C.GLdouble)(&model[0]), + (*C.GLdouble)(&proj[0]), (*C.GLint)(&view[0]), &wx, &wy, &wz, + ) + return float64(wx), float64(wy), float64(wz) +} + +// Project screen coordinates to object coordinates. +func Unproject(wx, wy, wz float64, model, proj []float64, view []int32) (objx, objy, objz float64) { + var ox, oy, oz C.GLdouble + C.gluUnProject( + C.GLdouble(wx), C.GLdouble(wy), C.GLdouble(wz), (*C.GLdouble)(&model[0]), + (*C.GLdouble)(&proj[0]), (*C.GLint)(&view[0]), &ox, &oy, &oz, + ) + return float64(ox), float64(oy), float64(oz) +} + +// Project screen coordinates to object coordinates. +func Unproject4(wx, wy, wz, clipw float64, model, proj []float64, view []int32, near, far float64) (objx, objy, objz, objw float64) { + var ox, oy, oz, ow C.GLdouble + C.gluUnProject4( + C.GLdouble(wx), C.GLdouble(wy), C.GLdouble(wz), C.GLdouble(clipw), + (*C.GLdouble)(&model[0]), (*C.GLdouble)(&proj[0]), (*C.GLint)(&view[0]), + C.GLdouble(near), C.GLdouble(far), &ox, &oy, &oz, &ow, + ) + return float64(ox), float64(oy), float64(oz), float64(ow) +} + +func PickMatrix(x, y, delx, dely float64, viewport []int32) { + C.gluPickMatrix(C.GLdouble(x), C.GLdouble(y), C.GLdouble(delx), + C.GLdouble(dely), (*C.GLint)(&viewport[0])) +} + +func Ortho2D(left, right, bottom, top float64) { + C.gluOrtho2D(C.GLdouble(left), C.GLdouble(right), C.GLdouble(bottom), C.GLdouble(top)) +} -- To unsubscribe, e-mail: opensuse-commit+unsubscr...@opensuse.org For additional commands, e-mail: opensuse-commit+h...@opensuse.org