Created
June 22, 2015 16:02
-
-
Save hajimehoshi/bd7a70e5511950dd2972 to your computer and use it in GitHub Desktop.
OpenGL: Fail on Windows
This file contains 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 ( | |
"fmt" | |
"log" | |
"runtime" | |
"github.com/go-gl/gl/v2.1/gl" | |
"github.com/go-gl/glfw/v3.1/glfw" | |
) | |
func init() { | |
runtime.LockOSThread() | |
} | |
func main() { | |
if err := glfw.Init(); err != nil { | |
log.Fatalln("failed to initialize glfw:", err) | |
} | |
defer glfw.Terminate() | |
glfw.WindowHint(glfw.ContextVersionMajor, 2) | |
glfw.WindowHint(glfw.ContextVersionMinor, 1) | |
window, err := glfw.CreateWindow(100, 100, "Foo", nil, nil) | |
if err != nil { | |
panic(err) | |
} | |
window.MakeContextCurrent() | |
if err := gl.Init(); err != nil { | |
panic(err) | |
} | |
var t uint32 | |
gl.GenTextures(1, &t) | |
gl.PixelStorei(gl.UNPACK_ALIGNMENT, 4) | |
gl.BindTexture(gl.TEXTURE_2D, t) | |
gl.TexImage2D(gl.TEXTURE_2D, 0, gl.RGBA, int32(100), int32(100), 0, gl.RGBA, gl.UNSIGNED_BYTE, gl.Ptr(nil)) | |
var f uint32 | |
gl.GenFramebuffers(1, &f) | |
gl.BindFramebuffer(gl.FRAMEBUFFER, f) | |
gl.FramebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, uint32(t), 0) | |
if gl.CheckFramebufferStatus(gl.FRAMEBUFFER) != gl.FRAMEBUFFER_COMPLETE { | |
panic("creating framebuffer failed") | |
} | |
if e := gl.GetError(); e != gl.NO_ERROR { | |
panic(fmt.Sprintf("before resizing: %d", e)) | |
} | |
gl.BindFramebuffer(gl.FRAMEBUFFER, 0) | |
window.SetSize(120, 120) | |
if e := gl.GetError(); e != gl.NO_ERROR { | |
// Crashed here! | |
panic(fmt.Sprintf("after resizing: %d", e)) | |
} | |
for !window.ShouldClose() { | |
gl.BindFramebuffer(gl.FRAMEBUFFER, f) | |
window.SwapBuffers() | |
glfw.PollEvents() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment