本文整理汇总了Golang中gl.Viewport函数的典型用法代码示例。如果您正苦于以下问题:Golang Viewport函数的具体用法?Golang Viewport怎么用?Golang Viewport使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Viewport函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: resizeWindow
// reset our viewport after a window resize
func resizeWindow(width, height int) {
// protect against a divide by zero
if height == 0 {
height = 1
}
// Setup our viewport
gl.Viewport(0, 0, width, height)
// change to the projection matrix and set our viewing volume.
gl.MatrixMode(gl.PROJECTION)
gl.LoadIdentity()
// aspect ratio
aspect := gl.GLdouble(width / height)
// Set our perspective.
// This code is equivalent to using gluPerspective as in the original tutorial.
var fov, near, far gl.GLdouble
fov = 45.0
near = 0.1
far = 100.0
top := gl.GLdouble(math.Tan(float64(fov*math.Pi/360.0))) * near
bottom := -top
left := aspect * bottom
right := aspect * top
gl.Frustum(float64(left), float64(right), float64(bottom), float64(top), float64(near), float64(far))
// Make sure we're changing the model view and not the projection
gl.MatrixMode(gl.MODELVIEW)
// Reset the view
gl.LoadIdentity()
}
开发者ID:PragmaticCypher,项目名称:opengl-go-tutorials,代码行数:35,代码来源:lesson01.go
示例2: main
func main() {
sdl.Init(sdl.INIT_VIDEO)
var screen = sdl.SetVideoMode(640, 480, 32, sdl.OPENGL)
if screen == nil {
panic("sdl error")
}
if gl.Init() != 0 {
panic("glew error")
}
pen := Pen{}
gl.MatrixMode(gl.PROJECTION)
gl.Viewport(0, 0, gl.GLsizei(screen.W), gl.GLsizei(screen.H))
gl.LoadIdentity()
gl.Ortho(0, gl.GLdouble(screen.W), gl.GLdouble(screen.H), 0, -1.0, 1.0)
gl.ClearColor(1, 1, 1, 0)
gl.Clear(gl.COLOR_BUFFER_BIT)
var running = true
for running {
e := &sdl.Event{}
for e.Poll() {
switch e.Type {
case sdl.QUIT:
running = false
break
case sdl.KEYDOWN:
running = false
break
case sdl.MOUSEMOTION:
me := e.MouseMotion()
if me.State != 0 {
pen.lineTo(Point{int(me.X), int(me.Y)})
} else {
pen.moveTo(Point{int(me.X), int(me.Y)})
}
break
}
}
sdl.GL_SwapBuffers()
sdl.Delay(25)
}
sdl.Quit()
}
开发者ID:krakensden,项目名称:Go-OpenGL,代码行数:57,代码来源:draw.go
示例3: reshape
func reshape(w, h int) {
gl.Viewport(0, 0, gl.GLsizei(w), gl.GLsizei(h))
gl.MatrixMode(gl.PROJECTION)
gl.LoadIdentity()
gl.Ortho(0, gl.GLdouble(w), 0, gl.GLdouble(h), -1, 1)
gl.Scalef(1, -1, 1)
gl.Translatef(0, gl.GLfloat(-h), 0)
gl.MatrixMode(gl.MODELVIEW)
}
开发者ID:brownman,项目名称:Go-GLUT,代码行数:9,代码来源:fontdemo.go
示例4: reshape
func reshape(w, h int) {
gl.Viewport(0, 0, w, h)
gl.MatrixMode(gl.PROJECTION)
gl.LoadIdentity()
gl.Ortho(0, float64(w), 0, float64(h), -1, 1)
gl.Scalef(1, -1, 1)
gl.Translatef(0, float32(-h), 0)
gl.MatrixMode(gl.MODELVIEW)
}
开发者ID:awpr,项目名称:Go-GLUT,代码行数:9,代码来源:fontdemo.go
示例5: reshape
/* new window size or exposure */
func reshape(width int, height int) {
h := float64(height) / float64(width)
gl.Viewport(0, 0, width, height)
gl.MatrixMode(gl.PROJECTION)
gl.LoadIdentity()
gl.Frustum(-1.0, 1.0, -h, h, 5.0, 60.0)
gl.MatrixMode(gl.MODELVIEW)
gl.LoadIdentity()
gl.Translatef(0.0, 0.0, -40.0)
}
开发者ID:DeedleFake,项目名称:Go-OpenGL,代码行数:13,代码来源:gogears.go
示例6: main
func main() {
sdl.Init(sdl.INIT_VIDEO)
var screen = sdl.SetVideoMode(640, 480, 32, sdl.OPENGL)
if screen == nil {
panic("sdl error")
}
if gl.Init() != 0 {
panic("gl error")
}
pen := Pen{}
gl.MatrixMode(gl.PROJECTION)
gl.Viewport(0, 0, int(screen.W), int(screen.H))
gl.LoadIdentity()
gl.Ortho(0, float64(screen.W), float64(screen.H), 0, -1.0, 1.0)
gl.ClearColor(1, 1, 1, 0)
gl.Clear(gl.COLOR_BUFFER_BIT)
var running = true
for running {
for e := sdl.PollEvent(); e != nil; e = sdl.PollEvent() {
switch ev := e.(type) {
case *sdl.QuitEvent:
running = false
case *sdl.KeyboardEvent:
if ev.Keysym.Sym == sdl.K_ESCAPE {
running = false
}
case *sdl.MouseMotionEvent:
if ev.State != 0 {
pen.lineTo(Point{int(ev.X), int(ev.Y)})
} else {
pen.moveTo(Point{int(ev.X), int(ev.Y)})
}
}
}
sdl.GL_SwapBuffers()
sdl.Delay(25)
}
sdl.Quit()
}
开发者ID:losinggeneration,项目名称:opengl,代码行数:53,代码来源:draw.go
示例7: reshape
func reshape(w, h int) {
if h == 0 {
h = 1
}
gl.Viewport(0, 0, w, h)
gl.MatrixMode(gl.PROJECTION)
gl.LoadIdentity()
glu.Perspective(45.0, float64(w)/float64(h), 0.1, 100.0)
gl.MatrixMode(gl.MODELVIEW)
gl.LoadIdentity()
resetZoom()
}
开发者ID:nightkidfifa,项目名称:poly2tri.golang,代码行数:12,代码来源:main.go
示例8: reshape
func reshape(w, h int) {
/* Because Gil specified "screen coordinates" (presumably with an
upper-left origin), this short bit of code sets up the coordinate
system to correspond to actual window coodrinates. This code
wouldn't be required if you chose a (more typical in 3D) abstract
coordinate system. */
gl.Viewport(0, 0, w, h) /* Establish viewing area to cover entire window. */
gl.MatrixMode(gl.PROJECTION) /* Start modifying the projection matrix. */
gl.LoadIdentity() /* Reset project matrix. */
gl.Ortho(0, float64(w), 0, float64(h), -1, 1) /* Map abstract coords directly to window coords. */
gl.Scalef(1, -1, 1) /* Invert Y axis so increasing Y goes down. */
gl.Translatef(0, float32(-h), 0) /* Shift origin up to upper-left corner. */
}
开发者ID:awpr,项目名称:Go-GLUT,代码行数:14,代码来源:simple.go
示例9: reshape
func reshape(w, h int) {
/* Because Gil specified "screen coordinates" (presumably with an
upper-left origin), this short bit of code sets up the coordinate
system to correspond to actual window coodrinates. This code
wouldn't be required if you chose a (more typical in 3D) abstract
coordinate system. */
gl.ClearColor(1, 1, 1, 1)
//fmt.Println(gl.GetString(gl.EXTENSIONS))
gl.Viewport(0, 0, w, h) /* Establish viewing area to cover entire window. */
gl.MatrixMode(gl.PROJECTION) /* Start modifying the projection matrix. */
gl.LoadIdentity() /* Reset project matrix. */
gl.Ortho(0, float64(w), 0, float64(h), -1, 1) /* Map abstract coords directly to window coords. */
gl.Scalef(1, -1, 1) /* Invert Y axis so increasing Y goes down. */
gl.Translatef(0, float32(-h), 0) /* Shift origin up to upper-left corner. */
gl.Enable(gl.BLEND)
gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)
gl.Disable(gl.DEPTH_TEST)
width, height = w, h
}
开发者ID:xushiwei,项目名称:draw2d,代码行数:19,代码来源:draw2dgl.go
示例10: Setup
func (self *Camera) Setup() {
d := self.Distance
Angle := self.Angle
Angle360 := Angle.Scale(1 / math.Pi * 180)
TargetPos := self.Target.Pos
gl.MatrixMode(gl.PROJECTION)
gl.LoadIdentity()
gl.Viewport(0, 0, 800, 600)
gl.Frustum(-1, 1, -1, 1, 4, 1000)
gl.MatrixMode(gl.MODELVIEW)
gl.LoadIdentity()
gl.Translatef(0, 0, -d)
gl.Rotatef(Angle360.Y, 1, 0, 0)
gl.Rotatef(Angle360.X, 0, 1, 0)
gl.Translatef(-TargetPos.X, -TargetPos.Y, -TargetPos.Z)
}
开发者ID:rolfrm,项目名称:boxworld,代码行数:19,代码来源:graphics.go
示例11: ResizeWindow
func ResizeWindow(w int32, h int32) {
// resizeWindow
gl.MatrixMode(gl.PROJECTION)
gl.Viewport(0, 0, gl.GLsizei(w), gl.GLsizei(h))
gl.LoadIdentity()
// glu.Perspective( 45.0, ratio, 0.1, 100.0)
aspect := gl.GLdouble(w) / gl.GLdouble(h)
zNear := gl.GLdouble(0.1)
zFar := gl.GLdouble(100.0)
gl.Frustum(-NearHeight*aspect,
NearHeight*aspect,
-NearHeight,
NearHeight, zNear, zFar)
gl.MatrixMode(gl.MODELVIEW)
gl.LoadIdentity()
WinW = int(w)
WinH = int(h)
}
开发者ID:jcd,项目名称:go-gamelib,代码行数:24,代码来源:video.go
示例12: main
func main() {
runtime.LockOSThread()
flag.Parse()
buildPalette()
sdl.Init(sdl.INIT_VIDEO)
defer sdl.Quit()
sdl.GL_SetAttribute(sdl.GL_SWAP_CONTROL, 1)
if sdl.SetVideoMode(512, 512, 32, sdl.OPENGL) == nil {
panic("sdl error")
}
if gl.Init() != 0 {
panic("gl error")
}
sdl.WM_SetCaption("Gomandel", "Gomandel")
gl.Enable(gl.TEXTURE_2D)
gl.Viewport(0, 0, 512, 512)
gl.MatrixMode(gl.PROJECTION)
gl.LoadIdentity()
gl.Ortho(0, 512, 512, 0, -1, 1)
gl.ClearColor(0, 0, 0, 0)
//-----------------------------------------------------------------------------
var dndDragging bool = false
var dndStart Point
var dndEnd Point
var tex gl.Texture
var tc TexCoords
var lastProgress int
initialRect := Rect{-1.5, -1.5, 3, 3}
rect := initialRect
rc := new(MandelbrotRequest)
rc.MakeRequest(512, 512, rect)
rc.WaitFor(Small, &tex, &tc)
running := true
e := new(sdl.Event)
for running {
for e.Poll() {
switch e.Type {
case sdl.QUIT:
running = false
case sdl.MOUSEBUTTONDOWN:
dndDragging = true
sdl.GetMouseState(&dndStart.X, &dndStart.Y)
dndEnd = dndStart
case sdl.MOUSEBUTTONUP:
dndDragging = false
sdl.GetMouseState(&dndEnd.X, &dndEnd.Y)
if e.MouseButton().Button == 3 {
rect = initialRect
} else {
rect = rectFromSelection(dndStart, dndEnd, 512, 512, rect)
tc = texCoordsFromSelection(dndStart, dndEnd, 512, 512, tc)
}
// make request
rc.MakeRequest(512, 512, rect)
case sdl.MOUSEMOTION:
if dndDragging {
sdl.GetMouseState(&dndEnd.X, &dndEnd.Y)
}
}
}
// if we're waiting for a result, check if it's ready
p := rc.Update(&tex, &tc)
if p != -1 {
lastProgress = p
}
gl.Clear(gl.COLOR_BUFFER_BIT)
tex.Bind(gl.TEXTURE_2D)
drawQuad(0, 0, 512, 512, tc.TX, tc.TY, tc.TX2, tc.TY2)
gl.BindTexture(gl.TEXTURE_2D, 0)
if dndDragging {
drawSelection(dndStart, dndEnd)
}
drawProgress(512, 512, lastProgress, rc.Pending)
sdl.GL_SwapBuffers()
}
}
开发者ID:saschpe,项目名称:Go-OpenGL,代码行数:88,代码来源:gomandel.go
示例13: main
func main() {
runtime.LockOSThread()
flag.Parse()
sdl.Init(sdl.INIT_VIDEO)
defer sdl.Quit()
sdl.GL_SetAttribute(sdl.GL_SWAP_CONTROL, 1)
if sdl.SetVideoMode(640, 480, 32, sdl.OPENGL) == nil {
panic("sdl error")
}
sdl.WM_SetCaption("Gotris", "Gotris")
sdl.EnableKeyRepeat(250, 45)
gl.Enable(gl.TEXTURE_2D)
gl.Enable(gl.BLEND)
gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)
gl.Viewport(0, 0, 640, 480)
gl.MatrixMode(gl.PROJECTION)
gl.LoadIdentity()
gl.Ortho(0, 640, 480, 0, -1, 1)
gl.ClearColor(0, 0, 0, 0)
//-----------------------------------------------------------------------------
font, err := LoadFontFromFile("dejavu.font")
if err != nil {
panic(err)
}
rand.Seed(int64(sdl.GetTicks()))
gs := NewGameSession(*initLevel, font)
lastTime := sdl.GetTicks()
running := true
for running {
for ev := sdl.PollEvent(); ev != nil; ev = sdl.PollEvent() {
switch e := ev.(type) {
case *sdl.QuitEvent:
running = false
case *sdl.KeyboardEvent:
if e.Type == sdl.KEYDOWN {
running = gs.HandleKey(e.Keysym.Sym)
}
}
}
now := sdl.GetTicks()
delta := now - lastTime
lastTime = now
gs.Update(delta)
gl.Clear(gl.COLOR_BUFFER_BIT)
font.Draw(5, 5, fmt.Sprintf("Level: %d | Score: %d", gs.Level, gs.Score))
gs.Draw()
gl.Color3ub(255, 255, 255)
sdl.GL_SwapBuffers()
}
}
开发者ID:sonald,项目名称:gotris,代码行数:63,代码来源:gotris.go
示例14: SetViewport
func (gd *openGLGraphicsDevice) SetViewport(x, y, w, h int) {
gl.Viewport(x, y, w, h)
}
开发者ID:chsc,项目名称:g3,代码行数:3,代码来源:ogl_graphics.go
示例15: onResize
func onResize(w, h int) {
ScreenWidth = w
ScreenHeight = h
gl.Viewport(0, 0, ScreenWidth, ScreenHeight)
}
开发者ID:pdelbarba,项目名称:gl3-examples,代码行数:5,代码来源:main.go
注:本文中的gl.Viewport函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论