本文整理汇总了Golang中github.com/veandco/go-sdl2/sdl.Window.GetSize方法的典型用法代码示例。如果您正苦于以下问题:Golang Window.GetSize方法的具体用法?Golang Window.GetSize怎么用?Golang Window.GetSize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/veandco/go-sdl2/sdl.Window
的用法示例。
在下文中一共展示了Window.GetSize方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Render
func (this *WorldRenderer) Render(ww *gamestate.World, options *settings.BoolOptions, window *sdl.Window) {
camera := ww.Player.Camera
p0 := camera.Pos4f()
w, h := window.GetSize()
camera.MoveRelative(mgl.Vec4{-0.1, 0, 0, 0})
this.View = (ww.PortalTransform(p0, camera.Pos4f()).Mul4(camera.Model())).Inv()
viewport := Viewport{0, 0, w / 2, h}
viewport.Activate()
this.render(ww, options, viewport, 0, nil)
camera.MoveRelative(mgl.Vec4{+0.2, 0, 0, 0})
this.View = (ww.PortalTransform(p0, camera.Pos4f()).Mul4(camera.Model())).Inv()
viewport.X = w / 2
viewport.Activate()
this.render(ww, options, viewport, 0, nil)
gl.Viewport(0, 0, w, h)
gl.ActiveTexture(gl.TEXTURE0)
this.Framebuffer[0].RenderTexture.Bind(gl.TEXTURE_RECTANGLE)
this.ScreenQuadRenderer.Render(this.ScreenQuad, this.Proj, this.View, this.ClippingPlane_ws, nil)
if this.screenShot {
this.screenShot = false
helpers.SaveTexture(gl.TEXTURE_RECTANGLE, 0, "screenshot.png")
}
}
示例2: NewGameState
func NewGameState(window *sdl.Window, world *World) (gamestate *GameState) {
gl.ClearColor(0., 0., 0.4, 0.0)
gl.Enable(gl.DEPTH_TEST)
bar := tw.NewBar("TweakBar")
gamestate = &GameState{
Window: window,
Camera: nil,
Bar: bar,
World: world,
Fps: 0,
Options: settings.BoolOptions{},
}
opt := &gamestate.Options
opt.Load()
gamestate.Camera = gamestate.World.Player.GetCamera()
tw.Define(" GLOBAL help='This example shows how to integrate AntTweakBar with SDL2 and OpenGL.' ")
bar.AddVarRO("fps", tw.TYPE_FLOAT, unsafe.Pointer(&gamestate.Fps), "")
opt.CreateGui(bar)
for i, portal := range gamestate.World.KdTree {
ptr := &(portal.(*Portal).Orientation)
bar.AddVarRW(fmt.Sprintf("Rotation %d", i), tw.TYPE_QUAT4F, unsafe.Pointer(ptr), "")
}
//window.GetSize(w, h)
w, h := window.GetSize()
tw.WindowSize(w, h)
return
}
示例3: GetMouseDirection
func GetMouseDirection(window *sdl.Window, mx, my int) (dir_cs mgl.Vec4) {
if !sdl.GetRelativeMouseMode() {
W, H := window.GetSize()
x := (2*float32(mx) - float32(W)) / float32(H)
y := (float32(H) - 2*float32(my)) / float32(H)
dir_cs = mgl.Vec4{x, y, -1, 0}
} else {
dir_cs = mgl.Vec4{0, 0, -1, 0}
}
return
}
示例4: NewWorldRenderer
func NewWorldRenderer(window *sdl.Window, w *gamestate.World) *WorldRenderer {
width, height := window.GetSize()
return &WorldRenderer{
Proj: mgl.Perspective(90, float32(width)/float32(height), 0.3, 1000),
View: mgl.Ident4(),
ClippingPlane_ws: mgl.Vec4{1, 0, 0, -1000000},
Textures: NewTextures(w.HeightMap),
HeightMapRenderer: NewHeightMapRenderer(),
WaterRendererA: NewSurfaceWaterRenderer(),
WaterRendererB: NewDebugWaterRenderer(),
MeshRenderer: NewMeshRenderer(),
PortalRenderer: NewPortalRenderer(),
TreeRenderer: NewTreeRenderer(),
SkyboxRenderer: NewSkyboxRenderer(),
Skybox: &Skybox{},
ParticleSystem: particles.NewParticleSystem(w, 10000, mgl.Vec3{32, 32, 32}, 1, 250),
Framebuffer: [2]*FrameBuffer{NewFrameBuffer(window.GetSize()), NewFrameBuffer(window.GetSize())},
ScreenQuad: &ScreenQuad{},
ScreenQuadRenderer: NewScreenQuadRenderer(),
DebugRenderer: NewLineRenderer(),
MaxRecursion: 1,
}
}
示例5: Run
// win==nil requests a full-screen window
func Run(win WindowSpec) int {
// All SDL calls must come from same thread.
runtime.LockOSThread()
defer runtime.UnlockOSThread()
err := sdl.Init(sdl.INIT_EVERYTHING)
if err != nil {
panic(err)
}
defer sdl.Quit()
// Install audio callback
spec := &sdl.AudioSpec{
Freq: SampleRate,
Format: sdl.AUDIO_F32SYS,
Channels: 1,
Samples: 4096,
Callback: sdl.AudioCallback(C.getSoundSamplesAdaptor),
}
audioDevice, err := sdl.OpenAudioDevice("", false, spec, nil, 0)
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to open audio device: %v\n", err)
panic(err)
}
if audioDevice < 2 {
fmt.Fprintf(os.Stderr, "Audio device=%v < 2 contrary to SDL-2 documentation\n", audioDevice, err)
}
sdl.PauseAudioDevice(audioDevice, false)
// Create window
var window *sdl.Window
if win != nil {
// Partial screen
winWidth, winHeight := win.Size()
window, err = sdl.CreateWindow(win.Title(), sdl.WINDOWPOS_UNDEFINED, sdl.WINDOWPOS_UNDEFINED,
int(winWidth), int(winHeight), sdl.WINDOW_SHOWN)
} else {
// Full screen
if isMacOS {
// Contrary to https://wiki.libsdl.org/SDL_CreateWindow, on MacOS 10.11.1
// a call to sdl.CreateWindow in fullscreen mode *does* use the w and h parameters.
// So ask what the display size is.
var mode sdl.DisplayMode
err = sdl.GetDesktopDisplayMode(0, &mode)
if err != nil {
fmt.Fprintf(os.Stderr, "Cannot get desktop display mode")
panic(err)
}
window, err = sdl.CreateWindow("", sdl.WINDOWPOS_UNDEFINED, sdl.WINDOWPOS_UNDEFINED,
int(mode.W), int(mode.H), sdl.WINDOW_SHOWN|sdl.WINDOW_FULLSCREEN_DESKTOP)
} else {
window, err = sdl.CreateWindow("", sdl.WINDOWPOS_UNDEFINED, sdl.WINDOWPOS_UNDEFINED,
0, 0, sdl.WINDOW_SHOWN|sdl.WINDOW_FULLSCREEN_DESKTOP)
}
}
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to create window: %v\n", err)
panic(err)
}
defer window.Destroy()
// Create renderer
width, height := window.GetSize()
renderer, err := sdl.CreateRenderer(window, -1, sdl.RENDERER_ACCELERATED|sdl.RENDERER_PRESENTVSYNC)
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to create renderer: %v\n", err)
panic(err)
}
defer renderer.Destroy()
var nTex = 1
if isMacOS {
// Work around MacOS bug via double buffering
nTex = 2
}
// Create texture
tex := make([]*sdl.Texture, nTex)
for i := range tex {
tex[i], err = renderer.CreateTexture(sdl.PIXELFORMAT_ARGB8888, sdl.TEXTUREACCESS_STREAMING, width, height)
if err != nil {
fmt.Fprintf(os.Stderr, "renderer.CreateTexture: %v\n", err)
panic(err)
}
defer tex[i].Destroy()
}
for _, r := range renderClientList {
r.Init(int32(width), int32(height))
}
// Loop until quit
for i := 0; ; i ^= nTex - 1 {
for event := sdl.PollEvent(); event != nil; event = sdl.PollEvent() {
switch e := event.(type) {
case *sdl.QuitEvent:
return 0
case *sdl.MouseMotionEvent:
// Go equivalent of SDL_PRESSED seems to be missing, so compare with zero.
if e.State != 0 {
//.........这里部分代码省略.........