gpt4 book ai didi

go - OpenGL 和 SDL2 无法打开窗口

转载 作者:IT王子 更新时间:2023-10-29 01:14:25 30 4
gpt4 key购买 nike

我正在尝试学习如何使用 OpenGL 和 SDL2,但是当我运行下面发布的简单程序时,窗口打开并立即关闭并显示以下消息:exit status 3221225477.

ma​​in.go

package main

import (
"fmt"

"github.com/go-gl/gl/v4.1-core/gl"
"github.com/veandco/go-sdl2/sdl"
)

var (
window *sdl.Window
context sdl.GLContext
)

func main() {
// Initialize sdl and create context
initialize()

// Initialize OpenGL pointers
gl.Init()

// Setup opengl attributes
setOpenGLAttributes()

// This makes our buffer swap syncronized with the monitor's vertical refresh
sdl.GLSetSwapInterval(1)

// Run and clean
run()
clean()
}

func initialize() {
sdl.Init(sdl.INIT_EVERYTHING)

window, err := sdl.CreateWindow("Test", sdl.WINDOWPOS_CENTERED, sdl.WINDOWPOS_CENTERED, 1280, 720, sdl.WINDOW_OPENGL)
if err != nil {
fmt.Println(err)
return
}

context, err = window.GLCreateContext()
if err != nil {
fmt.Println(err)
return
}
}

func setOpenGLAttributes() {
// SDL_GL_CONTEXT_CORE gives us only the newer version, deprecated functions are disabled
sdl.GLSetAttribute(sdl.GL_CONTEXT_PROFILE_MASK, sdl.GL_CONTEXT_PROFILE_CORE)

// 3.2 is part of the modern versions of OpenGL, but most video cards whould be able to run it
sdl.GLSetAttribute(sdl.GL_CONTEXT_MAJOR_VERSION, 3)
sdl.GLSetAttribute(sdl.GL_CONTEXT_MINOR_VERSION, 2)

// Turn on double buffering with a 24bit Z buffer.
sdl.GLSetAttribute(sdl.GL_DOUBLEBUFFER, 1)
}

func run() {
for {
for event := sdl.PollEvent(); event != nil; event = sdl.PollEvent() {
switch event.(type) {
case *sdl.QuitEvent:
return
}
}

gl.ClearColor(1, 8, 20, 1.0)
gl.Clear(gl.COLOR_BUFFER_BIT)
window.GLSwap()
}
}

func clean() {
// Delete our OpengL context
sdl.GLDeleteContext(context)

// Destroy our window
window.Destroy()

// Shutdown SDL 2
sdl.Quit()
}

我做错了什么?我正在学习本教程:http://headerphile.com/sdl2/opengl-part-1-sdl-opengl-awesome/看起来我没有错过任何将其转换为 Go 的内容。

编辑:所以我在设置 OpenGL 属性之前添加了 gl.Init()。我仍然得到相同的行为,但程​​序继续运行。该窗口是不可见的(在任务栏中看不到它),退出的唯一方法是在终端中按 CTRL+C。我是否遗漏了其他一些函数调用?

最佳答案

您可以在 ggez/ggez issue 141 中看到类似的崩溃(与 Go 无关,实际上是在 Rust 和 OpenGL 中)

重点是:首先检查您的驱动程序。提到了同样的问题:

I probably find the reason.
I updated my integrated graphics card driver, and everything is OK.
I do not know why, but now everything can work properly.

My device Info:

  • Intel(R) HD Graphics Family -> I updated this driver
  • AMD Radeon HD 8850M

关于go - OpenGL 和 SDL2 无法打开窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54047442/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com