Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpenGL widget #784

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Audrius Karabanovas <[email protected]>
Benny Siegert <[email protected]>
Cary Cherng <[email protected]>
Dmitry Bagdanov <[email protected]>
Ethan Reesor <[email protected]>
Ham Yeongtaek <[email protected]>
Hill <[email protected]>
iquanxin <[email protected]>
Expand Down
71 changes: 71 additions & 0 deletions declarative/opengl.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// Copyright 2021 The Walk Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// +build windows

package declarative

import (
"github.com/lxn/walk"
)

type OpenGL struct {
// Window

Accessibility Accessibility
Background Brush
ContextMenuItems []MenuItem
DoubleBuffering bool
Enabled Property
Font Font
MaxSize Size
MinSize Size
Name string
OnBoundsChanged walk.EventHandler
OnKeyDown walk.KeyEventHandler
OnKeyPress walk.KeyEventHandler
OnKeyUp walk.KeyEventHandler
OnMouseDown walk.MouseEventHandler
OnMouseMove walk.MouseEventHandler
OnMouseUp walk.MouseEventHandler
OnSizeChanged walk.EventHandler
Persistent bool
RightToLeftReading bool
ToolTipText Property
Visible Property

// Widget

Alignment Alignment2D
AlwaysConsumeSpace bool
Column int
ColumnSpan int
GraphicsEffects []walk.WidgetGraphicsEffect
Row int
RowSpan int
StretchFactor int

// OpenGL

AssignTo **walk.OpenGL
Setup walk.GLFunc
Paint walk.GLFunc
Teardown walk.GLFunc
Style int
PixelFormat []int32 // for wglCreateContextAttribsARB
Context []int32 // for wglCreateContextAttribsARB
}

func (gl OpenGL) Create(builder *Builder) error {
w, err := walk.NewOpenGL(builder.Parent(), uint32(gl.Style), gl.Setup, gl.Paint, gl.Teardown, gl.PixelFormat, gl.Context)
if err != nil {
return err
}

if gl.AssignTo != nil {
*gl.AssignTo = w
}

return builder.InitWidget(gl, w, func() error { return nil })
}
Binary file added examples/opengl/triangle/rsrc_windows_amd64.syso
Binary file not shown.
15 changes: 15 additions & 0 deletions examples/opengl/triangle/triangle.exe.manifest
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity version="1.0.0.0" processorArchitecture="*" name="SomeFunkyNameHere" type="win32"/>
<dependency>
<dependentAssembly>
<assemblyIdentity type="win32" name="Microsoft.Windows.Common-Controls" version="6.0.0.0" processorArchitecture="*" publicKeyToken="6595b64144ccf1df" language="*"/>
</dependentAssembly>
</dependency>
<application xmlns="urn:schemas-microsoft-com:asm.v3">
<windowsSettings>
<dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">PerMonitorV2, PerMonitor</dpiAwareness>
<dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">True</dpiAware>
</windowsSettings>
</application>
</assembly>
41 changes: 41 additions & 0 deletions examples/opengl/triangle/triangle.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright 2021 The Walk Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package main

import (
"github.com/go-gl/gl/all-core/gl"
"github.com/lxn/walk"
. "github.com/lxn/walk/declarative"
)

func main() {
MainWindow{
Title: "Walk OpenGL Example",
MinSize: Size{320, 240},
Layout: HBox{},
Children: []Widget{
OpenGL{
Setup: func(*walk.OpenGLContext) error {
return gl.Init()
},
Paint: func(glc *walk.OpenGLContext) error {
sz := glc.Widget().Size()
gl.Viewport(0, 0, int32(sz.Width), int32(sz.Height))
gl.Clear(gl.COLOR_BUFFER_BIT)
gl.Begin(gl.TRIANGLES)
gl.Color3f(1.0, 0.0, 0.0)
gl.Vertex2i(0, 1)
gl.Color3f(0.0, 1.0, 0.0)
gl.Vertex2i(-1, -1)
gl.Color3f(0.0, 0.0, 1.0)
gl.Vertex2i(1, -1)
gl.End()
gl.Flush()
return nil
},
},
},
}.Run()
}
Loading