本文整理汇总了Golang中github.com/go-gl/gl/v2/1/gl.MatrixMode函数的典型用法代码示例。如果您正苦于以下问题:Golang MatrixMode函数的具体用法?Golang MatrixMode怎么用?Golang MatrixMode使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了MatrixMode函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: drawHud
func (ctx *DrawContext) drawHud(o *orrery.Orrery, frametime time.Duration) {
txt, size, err := ctx.createHudTexture(o, frametime)
if err != nil {
log.Fatalf(`can't create texture from text surface: %s`, err)
}
defer gl.DeleteTextures(1, &txt)
gl.MatrixMode(gl.PROJECTION)
gl.PushMatrix()
gl.LoadIdentity()
gl.Ortho(0.0, float64(ctx.width), float64(ctx.height), 0.0, -1.0, 1.0)
gl.MatrixMode(gl.MODELVIEW)
gl.LoadIdentity()
gl.Clear(gl.DEPTH_BUFFER_BIT)
gl.BindTexture(gl.TEXTURE_2D, txt)
gl.Enable(gl.TEXTURE_2D)
defer gl.Disable(gl.TEXTURE_2D)
gl.Color3f(1, 1, 1)
gl.Begin(gl.QUADS)
gl.TexCoord2f(0, 0)
gl.Vertex2f(0.0, 0.0)
gl.TexCoord2f(1, 0)
gl.Vertex2f(float32(size[0]), 0.0)
gl.TexCoord2f(1, 1)
gl.Vertex2f(float32(size[0]), float32(size[1]))
gl.TexCoord2f(0, 1)
gl.Vertex2f(0.0, float32(size[1]))
gl.End()
gl.PopMatrix()
}
示例2: initGraphics
func initGraphics() error {
if err := gl.Init(); err != nil {
return err
}
if err := glfw.Init(); err != nil {
return err
}
glfw.WindowHint(glfw.Resizable, glfw.False)
var err error
window, err = glfw.CreateWindow(64*scaleRatio, 32*scaleRatio, "CHIP-8 Emulator", nil, nil)
if err != nil {
return err
}
window.MakeContextCurrent()
gl.MatrixMode(gl.PROJECTION)
gl.LoadIdentity()
gl.Ortho(0, 64, 32, 0, 0, 1)
gl.MatrixMode(gl.MODELVIEW)
gl.LoadIdentity()
clear()
window.SwapBuffers()
return nil
}
示例3: recalcOrthoBorders
func (cam *camera) recalcOrthoBorders() {
const totalW = gameW + leftBorder + rightBorder
const totalH = gameH + topBorder + bottomBorder
const totalRatio = float64(totalW) / totalH
windowRatio := float64(cam.WindowWidth) / float64(cam.WindowHeight)
var horizontalBorder, verticalBorder float64
if windowRatio > totalRatio {
// window is wider than game => borders left and right
horizontalBorder = (windowRatio*totalH - totalW) / 2
} else {
// window is higher than game => borders on top and bottom
verticalBorder = (totalW/windowRatio - totalH) / 2
}
cam.Left = -leftBorder - horizontalBorder
cam.Right = gameW + rightBorder + horizontalBorder
cam.Top = -topBorder - verticalBorder
cam.Bottom = gameH + bottomBorder + verticalBorder
gl.MatrixMode(gl.PROJECTION)
gl.LoadIdentity()
gl.Ortho(cam.Left, cam.Right, cam.Bottom, cam.Top, -1, 1)
gl.MatrixMode(gl.MODELVIEW)
}
示例4: drawScene
func drawScene(w *glfw.Window) {
width, height := w.GetFramebufferSize()
ratio := float32(width) / float32(height)
var x1, x2, y1, y2 float32
if ratio > 1 {
x1, x2, y1, y2 = -ratio, ratio, -1, 1
} else {
x1, x2, y1, y2 = -1, 1, -1/ratio, 1/ratio
}
gl.Viewport(0, 0, int32(width), int32(height))
gl.Clear(gl.COLOR_BUFFER_BIT)
// Applies subsequent matrix operations to the projection matrix stack
gl.MatrixMode(gl.PROJECTION)
gl.LoadIdentity() // replace the current matrix with the identity matrix
gl.Ortho(float64(x1), float64(x2), float64(y1), float64(y2), 1, -1) // multiply the current matrix with an orthographic matrix
// Applies subsequent matrix operations to the modelview matrix stack
gl.MatrixMode(gl.MODELVIEW)
gl.LoadIdentity()
gl.LineWidth(1)
gl.Begin(gl.LINE) // delimit the vertices of a primitive or a group of like primitives
gl.Color3f(0, 0, 0) // set the current color
gl.Vertex3f(0, y1, 0)
gl.Vertex3f(0, y2, 0)
gl.Vertex3f(x1, 0, 0)
gl.Vertex3f(x2, 0, 0)
gl.End()
gl.Rotatef(float32(glfw.GetTime()*50), 0, 0, 1) // multiply the current matrix by a rotation matrix
s := float32(.95)
gl.Begin(gl.TRIANGLES)
gl.Color3f(1, 0, 0) // set the current color
gl.Vertex3f(0, s, 0) // specify a vertex
gl.Color3f(0, 1, 0)
gl.Vertex3f(s*.866, s*-0.5, 0)
gl.Color3f(0, 0, 1)
gl.Vertex3f(s*-.866, s*-0.5, 0)
gl.End()
gl.LineWidth(5)
gl.Begin(gl.LINE_LOOP)
for i := float64(0); i < 2*math.Pi; i += .05 {
r, g, b := hsb2rgb(float32(i/(2*math.Pi)), 1, 1)
gl.Color3f(r, g, b)
gl.Vertex3f(s*float32(math.Sin(i)), s*float32(math.Cos(i)), 0)
}
gl.End()
}
示例5: reshape
/* new window size or exposure */
func reshape(width int32, height int32) {
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, 600.0)
gl.MatrixMode(gl.MODELVIEW)
gl.LoadIdentity()
gl.Translatef(0.0, 0.0, -100)
}
示例6: onResize
// onResize sets up a simple 2d ortho context based on the window size
func onResize(window *glfw.Window, w, h int) {
w, h = window.GetSize() // query window to get screen pixels
width, height := window.GetFramebufferSize()
gl.Viewport(0, 0, int32(width), int32(height))
gl.MatrixMode(gl.PROJECTION)
gl.LoadIdentity()
gl.Ortho(0, float64(w), 0, float64(h), -1, 1)
gl.MatrixMode(gl.MODELVIEW)
gl.LoadIdentity()
gl.ClearColor(1, 1, 1, 1)
}
示例7: main
func main() {
runtime.LockOSThread()
if err := glfw.Init(); err != nil {
panic(err)
}
defer glfw.Terminate()
window, err := glfw.CreateWindow(800, 600, "fontstash example", nil, nil)
if err != nil {
panic(err)
}
window.MakeContextCurrent()
glfw.SwapInterval(1)
gl.Init()
data, err := ioutil.ReadFile(filepath.Join("..", "ClearSans-Regular.ttf"))
if err != nil {
panic(err)
}
gl.Enable(gl.TEXTURE_2D)
tmpBitmap := make([]byte, 512*512)
cdata, err, _, tmpBitmap := truetype.BakeFontBitmap(data, 0, 32, tmpBitmap, 512, 512, 32, 96)
var ftex uint32
gl.GenTextures(1, &ftex)
gl.BindTexture(gl.TEXTURE_2D, ftex)
gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR)
gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR)
gl.TexImage2D(gl.TEXTURE_2D, 0, gl.ALPHA, 512, 512, 0,
gl.ALPHA, gl.UNSIGNED_BYTE, unsafe.Pointer(&tmpBitmap[0]))
gl.ClearColor(0.3, 0.3, 0.32, 1.)
for !window.ShouldClose() {
gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)
gl.MatrixMode(gl.PROJECTION)
gl.LoadIdentity()
gl.Ortho(0, 800, 600, 0, 0, 1)
gl.MatrixMode(gl.MODELVIEW)
gl.LoadIdentity()
gl.Disable(gl.DEPTH_TEST)
gl.Color4ub(255, 255, 255, 255)
gl.Enable(gl.BLEND)
gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)
my_print(100, 100, "The quick brown fox jumps over the fence", ftex, cdata)
window.SwapBuffers()
glfw.PollEvents()
}
}
示例8: setupScene
func setupScene(width int, height int) {
gl.Disable(gl.DEPTH_TEST)
gl.Disable(gl.LIGHTING)
gl.ClearColor(0.5, 0.5, 0.5, 0.0)
gl.MatrixMode(gl.PROJECTION)
gl.LoadIdentity()
gl.Ortho(0, float64(width), 0, float64(height), -1, 1)
gl.MatrixMode(gl.MODELVIEW)
gl.LoadIdentity()
}
示例9: drawSlide
func drawSlide() {
gl.Clear(gl.COLOR_BUFFER_BIT)
gl.MatrixMode(gl.MODELVIEW)
gl.LoadIdentity()
gl.Translatef(0, 0, -3.0)
gl.Begin(gl.QUADS)
//top left
gl.TexCoord2f(0, 0)
gl.Vertex3f(-1, 1, 0)
//top right
gl.TexCoord2f(1, 0)
gl.Vertex3f(1, 1, 0)
//bottom right
gl.TexCoord2f(1, 1)
gl.Vertex3f(1, -1, 0)
//bottom left
gl.TexCoord2f(0, 1)
gl.Vertex3f(-1, -1, 0)
gl.End()
}
示例10: setupScene
func setupScene() {
gl.ClearColor(0, 0, 0, 0)
if texDel {
gl.DeleteTextures(1, tex1)
}
tex1 = newTexture(*slides[selCell].getImage(monWidth, monHeight))
gl.MatrixMode(gl.PROJECTION)
gl.LoadIdentity()
gl.Ortho(-1, 1, -1, 1, 1.0, 10.0)
gl.MatrixMode(gl.MODELVIEW)
gl.LoadIdentity()
texDel = true
}
示例11: main
func main() {
err := glfw.Init()
if err != nil {
panic(err)
}
defer glfw.Terminate()
fp, err := os.Open("example.tmx")
if err != nil {
panic(err)
}
m, err := tmx.NewMap(fp)
if err != nil {
panic(err)
}
var monitor *glfw.Monitor
window, err := glfw.CreateWindow(screenWidth, screenHeight, "Map Renderer", monitor, nil)
if err != nil {
panic(err)
}
window.MakeContextCurrent()
if err := gl.Init(); err != nil {
panic(err)
}
width, height := window.GetFramebufferSize()
gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)
gl.ClearColor(1.0, 1.0, 1.0, 1.0)
gl.Viewport(0, 0, int32(width), int32(height))
gl.MatrixMode(gl.PROJECTION)
gl.LoadIdentity()
gl.Ortho(0, float64(width), float64(height), 0, -1, 1)
gl.Enable(gl.BLEND)
gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)
canvas := newOpenGLCanvas(width, height, float32(width)/float32(screenWidth), float32(height)/float32(screenHeight))
renderer := tmx.NewRenderer(*m, canvas)
fps := 0
startTime := time.Now().UnixNano()
timer := tmx.CreateTimer()
timer.Start()
for !window.ShouldClose() {
elapsed := float64(timer.GetElapsedTime()) / (1000 * 1000)
renderer.Render(int64(math.Ceil(elapsed)))
fps++
if time.Now().UnixNano()-startTime > 1000*1000*1000 {
log.Println(fps)
startTime = time.Now().UnixNano()
fps = 0
}
window.SwapBuffers()
glfw.PollEvents()
timer.UpdateTime()
}
}
示例12: Update
func (c *Camera) Update() {
// This has to be called in the GL thread
vx := math.Cos(c.alpha)*10 + c.Pos.X
vy := math.Sin(c.alpha)*10 + c.Pos.Y
vz := math.Sin(c.theta)*10 + c.Pos.Z
c.lookAt(vector.V3{vx, vy, vz})
gl.MatrixMode(gl.PROJECTION)
gl.LoadIdentity()
gl.Frustum(-c.frustum.nearW, c.frustum.nearW, -c.frustum.nearH, c.frustum.nearH, c.frustum.zNear, c.frustum.zFar)
}
示例13: Reset
func (state *State) Reset(window *glfw.Window) {
gl.ClearColor(1, 1, 1, 1)
gl.Clear(gl.COLOR_BUFFER_BIT)
gl.MatrixMode(gl.MODELVIEW)
gl.LoadIdentity()
gl.Disable(gl.DEPTH)
gl.Enable(gl.FRAMEBUFFER_SRGB)
width, height := window.GetSize()
gl.Viewport(0, 0, int32(width), int32(height))
gl.Ortho(0, float64(width), float64(height), 0, 30, -30)
}
示例14: setupScene
func setupScene() {
gl.Enable(gl.DEPTH_TEST)
gl.Enable(gl.LIGHTING)
gl.ClearColor(0.5, 0.5, 0.5, 0.0)
gl.ClearDepth(1)
gl.DepthFunc(gl.LEQUAL)
ambient := []float32{0.5, 0.5, 0.5, 1}
diffuse := []float32{1, 1, 1, 1}
lightPosition := []float32{-5, 5, 10, 0}
gl.Lightfv(gl.LIGHT0, gl.AMBIENT, &ambient[0])
gl.Lightfv(gl.LIGHT0, gl.DIFFUSE, &diffuse[0])
gl.Lightfv(gl.LIGHT0, gl.POSITION, &lightPosition[0])
gl.Enable(gl.LIGHT0)
gl.MatrixMode(gl.PROJECTION)
gl.LoadIdentity()
gl.Frustum(-1, 1, -1, 1, 1.0, 10.0)
gl.MatrixMode(gl.MODELVIEW)
gl.LoadIdentity()
}
示例15: lookAt
func (c *Camera) lookAt(at vector.V3) {
up := vector.V3{0, 0, 1}
fw := at.Sub(c.Pos).Normalized()
side := fw.Cross(up).Normalized()
up = side.Cross(fw).Normalized()
m := [16]float64{
side.X, up.X, -fw.X, 0,
side.Y, up.Y, -fw.Y, 0,
side.Z, up.Z, -fw.Z, 0,
0, 0, 0, 1,
}
gl.MatrixMode(gl.MODELVIEW)
gl.LoadMatrixd(&m[0])
gl.Translated(-c.Pos.X, -c.Pos.Y, -c.Pos.Z)
// Update frustum
nc := c.Pos.Sub(fw.Scaled(-c.frustum.zNear))
fc := c.Pos.Sub(fw.Scaled(-c.frustum.zFar))
planes := []vector.Plane{
vector.Plane{fw, nc}, // NEARP
vector.Plane{fw.Scaled(-1), fc}, // FARP
}
nh, nw := c.frustum.nearH, c.frustum.nearW
// TOP
aux := nc.Add(up.Scaled(nh)).Sub(c.Pos).Normalized()
normal := aux.Cross(side)
planes = append(planes, vector.Plane{normal, nc.Add(up.Scaled(nh))})
// BOTTOM
aux = nc.Sub(up.Scaled(nh)).Sub(c.Pos).Normalized()
normal = side.Cross(aux)
planes = append(planes, vector.Plane{normal, nc.Sub(up.Scaled(nh))})
// LEFT
aux = nc.Sub(side.Scaled(nw)).Sub(c.Pos).Normalized()
normal = aux.Cross(up)
planes = append(planes, vector.Plane{normal, nc.Sub(side.Scaled(nw))})
// LEFT
aux = nc.Add(side.Scaled(nw)).Sub(c.Pos).Normalized()
normal = up.Cross(aux)
planes = append(planes, vector.Plane{normal, nc.Add(side.Scaled(nw))})
c.frustum.planes = planes
}