Exemple #1
0
// initGL initializes GLFW and OpenGL.
func initGL() error {
	err := glfw.Init()
	if err != nil {
		return err
	}

	err = glfw.OpenWindow(640, 480, 8, 8, 8, 8, 0, 0, glfw.Windowed)
	if err != nil {
		glfw.Terminate()
		return err
	}

	glfw.SetWindowTitle("go-gl/gltext: Bitmap font example")
	glfw.SetSwapInterval(1)
	glfw.SetWindowSizeCallback(onResize)
	glfw.SetKeyCallback(onKey)

	errno := gl.Init()
	if errno != gl.NO_ERROR {
		str, err := glu.ErrorString(errno)
		if err != nil {
			return fmt.Errorf("Unknown openGL error: %d", errno)
		}
		return fmt.Errorf(str)
	}

	gl.Disable(gl.DEPTH_TEST)
	gl.Disable(gl.LIGHTING)
	gl.ClearColor(0.2, 0.2, 0.23, 0.0)
	return nil
}
func (self *OpenGLRenderer) checkErrors() {
	e := gl.GetError()
	for e != gl.NO_ERROR {
		errString, err := glu.ErrorString(e)
		if err != nil {
			log.Println("Invalid error code found", err)
		} else {
			log.Printf("GLError %v => %s", e, errString)
		}

		e = gl.GetError()
	}
}
Exemple #3
0
// Used as "defer OpenGLSentinel()()" checks the gl error code on call and exit
func OpenGLSentinel() func() {
	check := func() {
		e := gl.GetError()
		if e != gl.NO_ERROR {
			s, err := glu.ErrorString(e)
			if err != nil {
				log.Panic("Invalid error code: ", err)
			}
			log.Panic("Encountered GLError: ", e, " = ", s)
		}
	}
	check()
	return check
}
Exemple #4
0
// CheckGLError returns an opengl error if one exists.
func CheckGLError() error {
	errno := gl.GetError()

	if errno == gl.NO_ERROR {
		return nil
	}

	str, err := glu.ErrorString(errno)
	if err != nil {
		return fmt.Errorf("Unknown GL error: %d", errno)
	}

	return fmt.Errorf(str)
}
Exemple #5
0
func checkGlError(expeced ...gl.GLenum) error {
	gle := gl.GetError()
	if gle != gl.NO_ERROR {
		str, err := glu.ErrorString(gle)
		if err != nil {
			str = err.Error()
		}
		for _, v := range expeced {
			if v == gle {
				return Error(fmt.Sprintf("[gl][expected] %v: %v", gle, str))
			}
		}
		return Error(fmt.Sprintf("[gl][unexpected] %v: %v", gle, str))
	}
	return nil
}
Exemple #6
0
func loadShader(shaderType gl.GLenum, source string) gl.Shader {
	shader := gl.CreateShader(shaderType)
	if err := gl.GetError(); err != gl.NO_ERROR {
		str, _ := glu.ErrorString(err)
		panic(fmt.Errorf("gl error: %v", str))
	}

	shader.Source(source)
	shader.Compile()

	if shader.Get(gl.COMPILE_STATUS) != gl.TRUE {
		log := shader.GetInfoLog()
		panic(fmt.Errorf("Failed to compile shader: %v, shader: %v", log, source))
	}

	return shader
}
Exemple #7
0
// initGL initializes GLFW and OpenGL.
func initGL() (*glfw.Window, error) {
	if !glfw.Init() {
		log.Panic("glfw Error:")
	}

	var err error
	window, err = glfw.CreateWindow(768, 768, "My Own Shadertoy", nil, nil)
	if err != nil {
		glfw.Terminate()
		return nil, err
	}

	window.MakeContextCurrent()

	window.SetSizeCallback(onResize)

	window.SetKeyCallback(onKey)
	window.SetMouseButtonCallback(onMouse)
	window.SetCursorPositionCallback(onCursor)

	errno := gl.Init()
	if errno != gl.NO_ERROR {
		str, err := glu.ErrorString(errno)
		if err != nil {
			return nil, fmt.Errorf("Unknown openGL error: %d", errno)
		}
		return nil, fmt.Errorf(str)
	}

	gl.Enable(gl.TEXTURE_1D)
	gl.Enable(gl.TEXTURE_2D)
	gl.Enable(gl.TEXTURE_3D)

	fmt.Printf("gl.RENDERER   = %s\n", gl.GetString(gl.RENDERER))
	fmt.Printf("gl.VERSION    = %s\n", gl.GetString(gl.VERSION))
	fmt.Printf("gl.VENDOR     = %s\n", gl.GetString(gl.VENDOR))
	fmt.Printf("gl.EXTENSIONS = %s\n", gl.GetString(gl.EXTENSIONS))

	return window, nil
}