Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
ifennna committed Apr 13, 2019
0 parents commit d6891a5
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.idea/
11 changes: 11 additions & 0 deletions lines/bresenham.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package lines

import "github.com/go-gl/gl/all-core/gl"

func DrawPixel(x float32, y float32) {
gl.PointSize(10)
gl.Begin(gl.POINTS)
gl.Color3f(1.0, 1.0, 1.0)
gl.Vertex2f(x, y)
gl.End()
}
37 changes: 37 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package main

import (
"github.com/go-gl/gl/all-core/gl"
"github.com/go-gl/glfw/v3.2/glfw"
"go-graphics/lines"
"runtime"
)

func init() {
runtime.LockOSThread()
}

func main() {
window := buildWindow()
defer glfw.Terminate()

program := initOpenGL()

for !window.ShouldClose() {
draw(window, program)
}

}

func draw(window *glfw.Window, program uint32) {
gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)
gl.UseProgram(program)

//gl.LoadIdentity()
//gl.Ortho(0, 0, 0, 0, 0, 0)

lines.DrawPixel(0, 0)

window.SwapBuffers() // swap rendering and drawing buffers
glfw.PollEvents() // poll input events
}
44 changes: 44 additions & 0 deletions window.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package main

import (
"fmt"
"github.com/go-gl/gl/all-core/gl"
"github.com/go-gl/glfw/v3.2/glfw"
"log"
)

func buildWindow() *glfw.Window {
if err := glfw.Init(); err != nil {
panic(fmt.Errorf("couldn't initialize glfw: %v", err))
}

setWindowHints()

window, err := glfw.CreateWindow(800, 600, "Graphics", nil, nil)
if err != nil {
panic(fmt.Errorf("could not create opengl renderer: %v", err))
}
window.MakeContextCurrent()

return window
}

func initOpenGL() uint32 {
if err := gl.Init(); err != nil {
panic(err)
}
version := gl.GoStr(gl.GetString(gl.VERSION))
log.Println("OpenGL version", version)

program := gl.CreateProgram()
gl.LinkProgram(program)
return program
}

func setWindowHints() {
glfw.WindowHint(glfw.ContextVersionMajor, 2)
glfw.WindowHint(glfw.ContextVersionMinor, 1)
glfw.WindowHint(glfw.Resizable, glfw.True)
//glfw.WindowHint(glfw.OpenGLProfile, glfw.OpenGLCoreProfile)
//glfw.WindowHint(glfw.OpenGLForwardCompatible, glfw.True)
}

0 comments on commit d6891a5

Please sign in to comment.