Exemplo n.º 1
0
Arquivo: demo.go Projeto: rdterner/gl
func main() {
	err := glfw.Init()
	if err != nil {
		panic(err)
	}
	defer glfw.Terminate()

	w, err := glfw.CreateWindow(640, 480, "Testing 3+", nil, nil)
	if err != nil {
		panic(err)
	}

	w.MakeContextCurrent()
	glfw.SwapInterval(1)

	w.SetCharCallback(charCallBack)

	if err := gl.Init(); err != nil {
		panic(err)
	}

	r := makeResources()

	gl.ClearColor(.5, .5, .5, 0)
	fmt.Println("Press 'q' to quit")
	for !w.ShouldClose() {
		time.Sleep(10 * time.Millisecond)

		render(w, r)

		w.SwapBuffers()
		glfw.PollEvents()
	}
}
Exemplo n.º 2
0
Arquivo: gl.go Projeto: gmacd/rt
func (glr *GlRenderer) initSystem() {
	// Lock goroutine to main thread - required for GL
	runtime.LockOSThread()

	var err error
	if err = glfw.Init(); err != nil {
		panic(err)
	}

	glfw.WindowHint(glfw.Resizable, glfw.False)
	glfw.WindowHint(glfw.ContextVersionMajor, 3)
	glfw.WindowHint(glfw.ContextVersionMinor, 3)
	glfw.WindowHint(glfw.OpenGLProfile, glfw.OpenGLCoreProfile)
	glfw.WindowHint(glfw.OpenGLForwardCompatible, glfw.True)
	glr.window, err = glfw.CreateWindow(glr.width, glr.height, "rt", nil, nil)
	if err != nil {
		panic(err)
	}
	glr.window.MakeContextCurrent()

	if err = gl.Init(); err != nil {
		panic(err)
	}

	version := gl.GoStr(gl.GetString(gl.VERSION))
	fmt.Println("OpenGL version", version)
}
Exemplo n.º 3
0
func CreateRenderer(windowWidth, windowHeight int) *Renderer {

	if err := glfw.Init(); err != nil {
		log.Fatalln("failed to initialize glfw:", err)
	}
	// defer glfw.Terminate()

	glfw.WindowHint(glfw.Resizable, glfw.False)
	glfw.WindowHint(glfw.ContextVersionMajor, 4)
	glfw.WindowHint(glfw.ContextVersionMinor, 1)
	glfw.WindowHint(glfw.OpenGLProfile, glfw.OpenGLCoreProfile)
	glfw.WindowHint(glfw.OpenGLForwardCompatible, glfw.True)
	if windowWidth == 0 && windowHeight == 0 {
		windowWidth, windowHeight = glfw.GetPrimaryMonitor().GetPhysicalSize()
	}
	fmt.Println("Window Width -", windowWidth, "Window Height -", windowHeight)
	window, err := glfw.CreateWindow(windowWidth, windowHeight, "Karma", glfw.GetPrimaryMonitor(), nil)
	if err != nil {
		panic(err)
	}
	window.MakeContextCurrent()
	window.SetKeyCallback(testCallback)

	// Initialize Glow
	if err := gl.Init(); err != nil {
		panic(err)
	}

	version := gl.GoStr(gl.GetString(gl.VERSION))
	fmt.Println("OpenGL version", version)

	shaders := Shaders{}

	textureFlatUniforms := []string{"projection", "camera", "modelView", "tex"}
	textureFlatAttributes := []string{"vert", "vertTexCoord"}

	fmt.Println(textureFlatUniforms)
	fmt.Println(textureFlatAttributes)

	shader, err := createProgram("./assets/shaders/texture_flat.vs", "./assets/shaders/texture_flat.fs", textureFlatUniforms, textureFlatAttributes)
	if err != nil {
		panic(err)
	}
	shaders.textureFlat = shader

	meshes := []*Mesh{}

	previousTime := glfw.GetTime()

	return &Renderer{
		PreviousTime: previousTime,
		Window:       window,
		Shaders:      &shaders,
		Meshes:       meshes,
	}
}
Exemplo n.º 4
0
Arquivo: hello.go Projeto: rdterner/gl
func main() {
	err := glfw.Init()
	if err != nil {
		panic(err)
	}
	defer glfw.Terminate()

	glfw.WindowHint(glfw.Resizable, glfw.False)
	w, err := glfw.CreateWindow(400, 300, "Hello World", nil, nil)
	if err != nil {
		panic(err)
	}

	w.MakeContextCurrent()
	glfw.SwapInterval(1)

	w.SetCharCallback(charCallBack)

	if err := gl.Init(); err != nil {
		panic(err)
	}

	r := makeResources()

	gl.ClearColor(1, 1, 1, 0)
	fmt.Println("Press 'q' to quit")
	for !w.ShouldClose() {
		time.Sleep(10 * time.Millisecond)

		updateFadeFactor(r)
		render(w, r)

		w.SwapBuffers()
		glfw.PollEvents()
	}
}
Exemplo n.º 5
0
//
// Create Window
// This creates a window, initiates GL and sets the event listeners
//
// @return window (*glfw.Window) pointer to the window
//
func (glw *Glw) CreateWindow() *glfw.Window {
	// Init GLFW
	if err := glfw.Init(); err != nil {
		log.Fatalln("failed to initialize glfw:", err)
	}

	// Sets the OpenGL Version
	setOpenGlVersion()

	// Creates the Window
	win, err := glfw.CreateWindow(glw.Width, glw.Height, glw.Title, nil, nil)
	if err != nil {
		panic(err)
	}

	// Prints the OpenGL Versions at the end
	defer printOpenGlVersionInfo()

	// Sets this context as the current context
	win.MakeContextCurrent()

	// Initiates GL
	if err := gl.Init(); err != nil {
		panic(err)
	}

	// Enables Depth
	gl.Enable(gl.DEPTH_TEST)
	gl.DepthFunc(gl.LESS)

	win.SetInputMode(glfw.StickyKeysMode, 1)

	// Sets the Window to the Wrapper
	glw.SetWindow(win)
	return win
}