Created
September 11, 2013 17:36
-
-
Save banthar/6527045 to your computer and use it in GitHub Desktop.
golang + OSMesa
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/gl.go b/gl.go | |
index 89581f3..8ba19cb 100644 | |
--- a/gl.go | |
+++ b/gl.go | |
@@ -4,13 +4,8 @@ | |
package gl | |
-// #cgo darwin LDFLAGS: -framework OpenGL -lGLEW | |
-// #cgo windows LDFLAGS: -lglew32 -lopengl32 | |
-// #cgo linux LDFLAGS: -lGLEW -lGL | |
-// #cgo freebsd CFLAGS: -I/usr/local/include | |
-// #cgo freebsd LDFLAGS: -L/usr/local/lib -lglfw | |
+// #cgo LDFLAGS: -lOSMesa | |
// #include "gl.h" | |
-// void SetGlewExperimental(GLboolean v) { glewExperimental = v; } | |
import "C" | |
import "unsafe" | |
import "reflect" | |
@@ -1156,6 +1151,5 @@ func Viewport(x int, y int, width int, height int) { | |
//} | |
func Init() GLenum { | |
- C.SetGlewExperimental(C.GLboolean(1)) | |
- return GLenum(C.glewInit()) | |
+ return 0; | |
} | |
diff --git a/gl.h b/gl.h | |
index 17e42c7..1b0d722 100644 | |
--- a/gl.h | |
+++ b/gl.h | |
@@ -1,5 +1,5 @@ | |
+#define GL_GLEXT_PROTOTYPES | |
+ | |
#include <stdlib.h> | |
-#include <GL/glew.h> | |
+#include <GL/osmesa.h> | |
-#undef GLEW_GET_FUN | |
-#define GLEW_GET_FUN(x) (*x) | |
\ No newline at end of file |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "os" | |
import "image" | |
import "image/png" | |
import "unsafe" | |
import "github.com/go-gl/gl" | |
import "github.com/go-gl/osmesa" | |
func draw() { | |
gl.Begin(gl.TRIANGLES) | |
gl.Vertex2f(0,0) | |
gl.Vertex2f(0,1) | |
gl.Vertex2f(1,1) | |
gl.End() | |
} | |
func main() { | |
var ctx = osmesa.CreateContext(osmesa.RGBA, nil) | |
defer osmesa.DestroyContext(ctx) | |
image := image.NewRGBA(image.Rect(0, 0, 640, 480)) | |
osmesa.MakeCurrent(ctx, unsafe.Pointer(&(image.Pix[0])), gl.UNSIGNED_BYTE, 640, 480) | |
gl.ClearColor(1.0, 0.5, 0.23, 1.0) | |
gl.Clear(gl.COLOR_BUFFER_BIT) | |
draw(); | |
gl.Flush(); | |
fd, err := os.Create("output.png") | |
if err != nil { | |
panic(err) | |
} | |
defer fd.Close() | |
png.Encode(fd, image) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment