SDL 版本:2.0.12OpenGL 版本:3.3 INTEL-10.4.14我不得不通过请求核心配置文件将 OpenGL 版本强制为 3.3,否则我会得到的默认版本是 1.2在这个视频教程http://youtu.be/yxAPS2eyKmA Games with Go之后,我尝试了 OpenGL 示例代码,它只显示了一个黑色窗口。它应该呈现一个橙色三角形。我在INVALID_OPERATION倒数第二个声明之后gl.DrawArrays(gl.TRIANGLES, 0, 3)https://gist.github.com/ErnestoBorio/87b09bf3cc496657a83637fd4876e943 package main import ( "fmt" "strings" "github.com/go-gl/gl/v3.3-core/gl" "github.com/veandco/go-sdl2/sdl" ) func DontPanic(err error) { if err != nil { panic(err) } } var GLversion = [...]int {3, 3} func main() { DontPanic( sdl.Init(sdl.INIT_EVERYTHING)) defer sdl.Quit() DontPanic( sdl.GLSetAttribute(sdl.GL_CONTEXT_PROFILE_MASK, sdl.GL_CONTEXT_PROFILE_CORE)) DontPanic( sdl.GLSetAttribute(sdl.GL_CONTEXT_MAJOR_VERSION, GLversion[0])) DontPanic( sdl.GLSetAttribute(sdl.GL_CONTEXT_MINOR_VERSION, GLversion[1])) window, err := sdl.CreateWindow("OpenGL", 200, 200, 1280, 720, sdl.WINDOW_OPENGL) DontPanic(err) window.GLCreateContext() defer window.Destroy() GLversionStr := fmt.Sprintf("%d%d0", GLversion[0], GLversion[1]) gl.Init() version := gl.GoStr(gl.GetString(gl.VERSION)) fmt.Println("OpenGL Version", version) vertexShaderSrc := "#version "+ GLversionStr +" core \n"+ "layout (location = 0) in vec3 aPos;"+ "void main() {"+ "gl_Position = vec4(aPos.x, aPos.y, aPos.z, 1.0);"+ "}\x00" }
- 1 回答
- 0 关注
- 110 浏览
添加回答
举报
0/150
提交
取消