8000 Drag and drop models · raedatoui/learn-opengl-golang@d83b49b · GitHub
[go: up one dir, main page]

Skip to content

Commit d83b49b

Browse files
author
Raed Atoui
committed
Drag and drop models
1 parent 9d5b181 commit d83b49b

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

sections/base.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ type Slide interface {
3030
HandleKeyboard(k glfw.Key, s int, a glfw.Action, m glfw.ModifierKey, keys map[glfw.Key]bool)
3131
HandleMousePosition(xpos, ypos float64)
3232
HandleScroll(xoff, yoff float64)
33+
HandleFiles(names []string)
3334
DrawText() bool
3435
}
3536

@@ -86,6 +87,10 @@ func (s *BaseSlide) HandleScroll(xoff, yoff float64) {
8687

8788
}
8889

90+
func (s *BaseSlide) HandleFiles(names []string) {
91+
92+
}
93+
8994
type BaseSketch struct {
9095
BaseSlide
9196
}

sections/modelloading/1.model_loading.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import (
66
"github.com/go-gl/mathgl/mgl32"
77
"github.com/raedatoui/glutils"
88
"github.com/raedatoui/learn-opengl-golang/sections"
9+
"path"
10+
"fmt"
911
)
1012

1113
type ModelLoading struct {
@@ -103,6 +105,15 @@ func (ml *ModelLoading) HandleScroll(xoff, yoff float64) {
103105
ml.camera.ProcessMouseScroll(yoff)
104106
}
105107

108+
func (ml *ModelLoading) HandleFiles(names []string) {
109+
f := path.Base(names[0])
110+
dir := path.Dir(names[0]) + "/"
111+
fmt.Println(f, dir)
112+
ml.model.Dispose()
113+
ml.model, _ = glutils.NewModel(dir, f, false)
114+
//gl.PolygonMode(gl.FRONT_AND_BACK, gl.LINE)
115+
}
116+
106117
func (ml *ModelLoading) Close() {
107118
ml.model.Dispose()
108119
gl.UseProgram(0)

tutorial.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,12 @@ func resizeCallback(w *glfw.Window, width int, height int) {
130130
gl.Viewport(0, 0, int32(width), int32(height))
131131
}
132132

133+
func fileDropCallback(w *glfw.Window, names []string) {
134+
if currentSlide != nil {
135+
currentSlide.HandleFiles(names)
136+
}
137+
}
138+
133139
func setup() (*glfw.Window, error) {
134140
glfw.WindowHint(glfw.Resizable, glfw.True)
135141
glfw.WindowHint(glfw.ContextVersionMajor, 4)
@@ -156,6 +162,8 @@ func setup() (*glfw.Window, error) {
156162
window.SetCursorPosCallback(mouseCallback)
157163
window.SetScrollCallback(scrollCallback)
158164

165+
// File Drag n Drop
166+
window.SetDropCallback(fileDropCallback)
159167
version := gl.GoStr(gl.GetString(gl.VERSION))
160168
glsl := gl.GoStr(gl.GetString(gl.SHADING_LANGUAGE_VERSION))
161169
fmt.Println("OpenGL version", version, glsl)

0 commit comments

Comments
 (0)
0