-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit d6891a5
Showing
4 changed files
with
93 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.idea/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |