func reinitScreen(width, height int) { winWidth, winHeight = gl.Sizei(width), gl.Sizei(height) if sdlScreen != nil { sdlScreen.Free() } sdlScreen = sdl.SetVideoMode(width, height, 24, sdl.OPENGL|sdl.RESIZABLE) if sdlScreen == nil { panic("SDL video init error") } }
func glFillTextureFromImageFile(filePath string) { var file, err = os.Open(filePath) var img image.Image if err != nil { panic(err) } defer file.Close() if img, _, err = image.Decode(file); err != nil { panic(err) } w, h := img.Bounds().Dx(), img.Bounds().Dy() rgba := image.NewRGBA(image.Rect(0, 0, w, h)) for x := 0; x < w; x++ { for y := 0; y < h; y++ { rgba.Set(x, y, img.At(x, y)) } } gl.TexImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.Sizei(w), gl.Sizei(h), 0, gl.RGBA, gl.UNSIGNED_BYTE, gl.Pointer(&rgba.Pix[0])) }
func glGetInfoLog(shaderOrProgram gl.Uint, isShader bool) string { var l = gl.Sizei(256) var s = gl.GLStringAlloc(l) defer gl.GLStringFree(s) if isShader { gl.GetShaderInfoLog(shaderOrProgram, l, nil, s) } else { gl.GetProgramInfoLog(shaderOrProgram, l, nil, s) } return gl.GoString(s) }
func glSetShaderSource(shader gl.Uint, source string) { var src = gl.GLStringArray(source) defer gl.GLStringArrayFree(src) gl.ShaderSource(shader, gl.Sizei(len(src)), &src[0], nil) }