Permalink
Browse files

More renaming, implement DisplayPost

  • Loading branch information...
1 parent 17d7f00 commit c134eb5ab39a4318f9f7941e44eeaa8dd84517f3 @cloudhead committed Oct 3, 2012
Showing with 86 additions and 47 deletions.
  1. +5 −5 README
  2. +0 −22 crayola.h
  3. +18 −0 default.go
  4. BIN examples/crayolaboy/images/{crayola.bmp → gogol.bmp}
  5. +18 −14 examples/crayolaboy/main.go
  6. +7 −3 crayola.c → gogol.c
  7. +14 −2 crayola.go → gogol.go
  8. +23 −0 gogol.h
  9. +1 −1 util.c
View
10 README
@@ -1,27 +1,27 @@
- CRAYOLA
+ GOGOL
a bitmap drawing & animation library for Go.
. synopsis
- crayola's purpose is to provide a simple interface
+ gogol's purpose is to provide a simple interface
for drawing bitmap graphics on the screen, as well
as handling mouse & keyboard events.
- crayola is especially well suited for building 2D
+ gogol is especially well suited for building 2D
games.
. installation
- go get github.com/cloudhead/crayola
+ go get github.com/cloudhead/gogol
. documentation
- go doc crayola
+ go doc gogol
. examples
View
@@ -1,22 +0,0 @@
-/*
- * crayola
- * crayola.h
- */
-void init (const char *title);
-void adjustHSL (float h, float s, float l);
-void adjustExp (float, float);
-
-/*
- * go callback functions, defined in crayola.go
- */
-extern void goDisplay (int now);
-extern void goReshape (int w, int h);
-extern void goKeyboard (unsigned char key, int x, int y);
-extern void goKeyboardUp(unsigned char key, int x, int y);
-extern void goSpecial (int key, int x, int y);
-extern void goSpecialUp (int key, int x, int y);
-extern void goMouse (int b, int s, int x, int y);
-extern void goMotion (int x, int y);
-extern void goEntry (int e);
-extern void goReady ();
-
View
@@ -0,0 +1,18 @@
+package gogol
+
+import "time"
+
+// DefaultHandler implements Handler
+type DefaultHandler struct {
+ WindowTitle string
+}
+
+func (d *DefaultHandler) Ready() {}
+func (d *DefaultHandler) Reshape(w, h int) {}
+func (d *DefaultHandler) Display(delta time.Duration) {}
+func (d *DefaultHandler) DisplayPost() {}
+func (d *DefaultHandler) Keyboard(key Key, isDown bool) {}
+func (d *DefaultHandler) Motion(x, y int) {}
+func (d *DefaultHandler) Mouse(b Mouse, isDown bool, x, y int) {}
+func (d *DefaultHandler) Entry(e bool) {}
+func (d *DefaultHandler) Title() string { return d.WindowTitle }
@@ -1,28 +1,30 @@
package main
import (
- "crayola"
- "crayola/image"
"flag"
+ "gogol"
+ "gogol/image"
"os"
"time"
)
var (
- title = flag.String("title", "crayola", "window title")
+ title = flag.String("title", "gogol", "window title")
)
// Speed of play
var speed float64 = 7
type Gogol struct {
- width int
- height int
- seq *image.Sequence
- title string
- scale float32
- isMouseLDown bool
- isMouseRDown bool
+ gogol.Handler
+
+ width int
+ height int
+ seq *image.Sequence
+ title string
+ scale float32
+ isMouseLDown bool
+ isMouseRDown bool
}
func (c *Gogol) Ready() {
@@ -92,15 +94,17 @@ func (c *Gogol) Mouse(b gogol.Mouse, isDown bool, x, y int) {
}
}
-func (c *Gogol) Entry(e bool) {}
-
func main() {
flag.Parse()
- img := gogol.NewImage("images/crayola.bmp")
+ img := gogol.NewImage("images/gogol.bmp")
sprite := img.Sprite(16, 16)
seq := sprite.Sequence(0, -1)
- handler := &Gogol{seq: seq, scale: 1}
+ handler := &Gogol{
+ Handler: &gogol.DefaultHandler{*title},
+ seq: seq,
+ scale: 1,
+ }
gogol.Init(handler)
}
View
@@ -1,13 +1,13 @@
/*
- * crayola
- * crayola.c
+ * gogol
+ * gogol.c
*/
#include <GL/gl.h>
#include <GL/glext.h>
#include <GL/glut.h>
#include <stdio.h>
-#include "crayola.h"
+#include "gogol.h"
/* Window width & height */
int w = 640, h = 640;
@@ -91,6 +91,10 @@ void display(void)
glUseProgram(0);
glBindFramebuffer(GL_FRAMEBUFFER, 0);
+ /* Switch to user-land, now that we've deactivated
+ * the shader program. */
+ goDisplayPost();
+
glutSwapBuffers();
}
View
@@ -19,14 +19,14 @@
package gogol
//
-// #include "crayola.h"
+// #include "gogol.h"
// #include <GL/glut.h>
// #cgo LDFLAGS: -lglut -lGL
//
import "C"
import (
- "crayola/image"
+ "gogol/image"
"time"
)
@@ -35,6 +35,7 @@ var (
lastTick = 0
)
+// Mouse can be either MouseL, MouseR or MouseR.
type Mouse int
const (
@@ -62,6 +63,12 @@ type Handler interface {
// operations.
Display(delta time.Duration)
+ // DisplayPost is called on every frame, after Display,
+ // and after any post-processing effects have been applied.
+ // This function is useful for drawing UI elements which
+ // shouldn't be affected by image filters.
+ DisplayPost()
+
// Keyboard is called whenever a key is pressed or released.
// The key is passed as an argument, as well as the state
// of t
@@ -175,6 +182,11 @@ func goDisplay(now C.int) {
lastTick = int(now)
}
+//export goDisplayPost
+func goDisplayPost(now C.int) {
+ handler.DisplayPost()
+}
+
//export goKeyboard
//
// goKeyboard is called when an ordinary key is pressed.
View
23 gogol.h
@@ -0,0 +1,23 @@
+/*
+ * gogol
+ * gogol.h
+ */
+void init (const char *title);
+void adjustHSL (float h, float s, float l);
+void adjustExp (float, float);
+
+/*
+ * go callback functions, defined in gogol.go
+ */
+extern void goDisplay (int now);
+extern void goDisplayPost();
+extern void goReshape (int w, int h);
+extern void goKeyboard (unsigned char key, int x, int y);
+extern void goKeyboardUp (unsigned char key, int x, int y);
+extern void goSpecial (int key, int x, int y);
+extern void goSpecialUp (int key, int x, int y);
+extern void goMouse (int b, int s, int x, int y);
+extern void goMotion (int x, int y);
+extern void goEntry (int e);
+extern void goReady ();
+
View
2 util.c
@@ -1,5 +1,5 @@
/*
- * crayola
+ * gogol
* util.c
*/
#include <GL/gl.h>

0 comments on commit c134eb5

Please sign in to comment.