Пример #1
0
func initScene() (err error) {
	gl.Enable(gl.TEXTURE_2D)
	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)

	gl.Lightfv(gl.LIGHT0, gl.AMBIENT, ambient)
	gl.Lightfv(gl.LIGHT0, gl.DIFFUSE, diffuse)
	gl.Lightfv(gl.LIGHT0, gl.POSITION, lightpos)
	gl.Enable(gl.LIGHT0)

	gl.Viewport(0, 0, Width, Height)
	gl.MatrixMode(gl.PROJECTION)
	gl.LoadIdentity()
	gl.Frustum(-1, 1, -1, 1, 1.0, 10.0)
	gl.MatrixMode(gl.MODELVIEW)
	gl.LoadIdentity()

	goph, err := os.Open("../../data/gopher.png")
	if err != nil {
		panic(err)
	}
	defer goph.Close()

	texture, err = createTexture(goph)
	return
}
Пример #2
0
func render() {
	modelMatrix = trig.MatrixMult(trig.RotateY(math.Pi/360), modelMatrix)

	gl.Viewport(0, 0, 768, 768)
	gl.ClearColor(0.0, 0.0, 0, 0)
	gl.Enable(gl.DEPTH_TEST)

	raytraceProgram.Use()
	mInput.UniformMatrix4f(false, (*[16]float32)(modelMatrix))
	vInput.UniformMatrix4f(false, (*[16]float32)(viewMatrix))
	pInput.UniformMatrix4f(false, (*[16]float32)(projMatrix))
	glh.With(framebuffer, func() {
		framebuffer.UpdateTextures()

		gl.DrawBuffer(gl.COLOR_ATTACHMENT0)

		gl.Clear(gl.COLOR_BUFFER_BIT)
		gl.DepthFunc(gl.GREATER)
		gl.CullFace(gl.BACK)
		cube.Render(gl.TRIANGLES, raytraceProgram)

		gl.DrawBuffer(gl.COLOR_ATTACHMENT1)
		gl.Clear(gl.COLOR_BUFFER_BIT)
		gl.DepthFunc(gl.LESS)
		gl.CullFace(gl.FRONT)
		cube.Render(gl.TRIANGLES, raytraceProgram)
	})
}
Пример #3
0
func Reshape(w, h int) {
	gl.Viewport(0, 0, w, h)
	gl.MatrixMode(gl.PROJECTION)
	gl.LoadIdentity()
	gl.Ortho(0, 100, 0, 100, -1, 1)
	gl.MatrixMode(gl.MODELVIEW)
}
Пример #4
0
func (v *Video) Reshape(width int, height int) {
	x_offset := 0
	y_offset := 0

	r := ((float64)(height)) / ((float64)(width))

	if r > 0.9375 { // Height taller than ratio
		h := (int)(math.Floor((float64)(0.9375 * (float64)(width))))
		y_offset = (height - h) / 2
		height = h
	} else if r < 0.9375 { // Width wider
		var scrW, scrH float64
		if ppu.OverscanEnabled {
			scrW = 240.0
			scrH = 224.0
		} else {
			scrW = 256.0
			scrH = 240.0
		}

		w := (int)(math.Floor((float64)((scrH / scrW) * (float64)(height))))
		x_offset = (width - w) / 2
		width = w
	}

	gl.Viewport(x_offset, y_offset, width, height)
	gl.MatrixMode(gl.PROJECTION)
	gl.LoadIdentity()
	gl.Ortho(-1, 1, -1, 1, -1, 1)
	gl.MatrixMode(gl.MODELVIEW)
	gl.LoadIdentity()
	gl.Disable(gl.DEPTH_TEST)
}
Пример #5
0
func (v *Viewport) ResizeViewport(w, h int) {
	v.w = w
	v.h = h
	v.buildTrans()
	allegro.RunInThread(func() {
		gl.Viewport(0, 0, w, h)
	})
}
Пример #6
0
// Binds the framebuffer for drawing.
func (fb *Framebuffer) Bind() {
	fb.Buffer.Bind()
	gl.Viewport(0, 0, fb.Width, fb.Height)
	gl.Enable(gl.TEXTURE_2D)
	gl.Disable(gl.DEPTH_TEST)
	gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)
	gl.Enable(gl.BLEND)
}
Пример #7
0
func (s *System) Run(ctx *scene.Context) {
	s.init(ctx)
	defer s.finish()
	// TODO: take active camera node
	w := float32(s.Width)
	h := float32(s.Height)
	projM := mathgl.Ortho(0, w, h, 0, -30, 30)
	viewM := mathgl.Translate3D(0, 0, 0)
	worldM := mathgl.Translate3D(0, 0, 0)
	var rect struct {
		WVP     mathgl.Mat4f   `uniform:"WorldViewProjectionM"`
		Diffuse *gfx.Sampler2D `uniform:"Diffuse"`
		geomobj gfx.Geometry
		geom    gfx.GeometryLayout
	}
	rect.WVP = projM.Mul4(viewM).Mul4(worldM)
	s.cmds <- func() {
		quadbuffer := geometry.NewBuilder(s.shader.VertexFormat())
		quadbuffer.Clear()
		quadbuffer.P(0, 0, 0).UV(-1, -1).Cf(1, 1, 1, 1)
		quadbuffer.P(w/3, 0, 0).UV(-1, -1)
		quadbuffer.P(w/3, h/3, 0).UV(-1, -1)
		quadbuffer.P(0, h/3, 0).UV(-1, -1)
		quadbuffer.Indices(0, 1, 2, 2, 0, 3)
		rect.geomobj.Alloc(gfx.StaticDraw)
		err := rect.geomobj.CopyFrom(quadbuffer)
		if err != nil {
			panic(err)
		}
		s.shader.Use()
		rect.geom.Layout(&s.shader, &rect.geomobj)
		/*
			err = rect.geomobj.CopyFrom(quadbuffer)
			if err != nil {
				panic(err)
			}
		*/
		whiteImg := image.NewNRGBA(image.Rect(0, 0, 1, 1))
		whiteImg.Set(0, 0, color.White)
		white, err := gfx.Image(whiteImg)
		if err != nil {
			panic(err)
		}
		rect.Diffuse = white
	}

	for ctx.Step() {
		s.cmds <- func() {
			gl.Viewport(0, 0, s.Width, s.Height)
			gl.ClearColor(0, 0, 0, 1.0)
			gl.ClearDepth(1)
			gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)
		}
		s.meshes.update(s.cmds, &s.shader)
		s.draw()
		s.sync()
	}
}
Пример #8
0
func initGL() {
	gl.MatrixMode(gl.PROJECTION)
	gl.LoadIdentity()
	gl.Viewport(0, 0, 800, 600)
	gl.Ortho(0, 800, 600, 0, -1.0, 1.0)
	gl.MatrixMode(gl.MODELVIEW)
	gl.LoadIdentity()
	gl.ClearColor(0.1, 0.05, 0.0, 1.0)
}
Пример #9
0
Файл: 09.go Проект: nzlov/gogl
// new window size
func reshape(window *glfw.Window, width, height int) {

	gl.Viewport(0, 0, width, height)
	gl.MatrixMode(gl.PROJECTION)
	gl.LoadIdentity()
	gl.Frustum(-1.0, 1.0, -1.0, 1.0, 1, 20)
	gl.MatrixMode(gl.MODELVIEW)
	gl.LoadIdentity()
}
Пример #10
0
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)
}
Пример #11
0
Файл: 10.go Проект: nzlov/gogl
// new window size
func reshape(window *glfw.Window, width, height int) {

	gl.Viewport(0, 0, width, height)
	gl.MatrixMode(gl.PROJECTION)
	gl.LoadIdentity()
	glu.Perspective(45.0, float32(width)/float32(height), 0.1, 100.0)
	gl.MatrixMode(gl.MODELVIEW)
	gl.LoadIdentity()
}
Пример #12
0
func copiedInit() {
	gl.ClearColor(0, 0, 0, 0)
	gl.ShadeModel(gl.FLAT)
	gl.Enable(gl.CULL_FACE)
	gl.Viewport(320, 240, 640, 480)
	gl.MatrixMode(gl.PROJECTION)
	gl.LoadIdentity()
	gl.Frustum(-1, 1, -1, 1, 1.5, 20)
	gl.MatrixMode(gl.MODELVIEW)
}
Пример #13
0
// onResize handles window resize events.
func onResize(window *glfw.Window, w, h int) {
	if w < 1 {
		w = 1
	}

	if h < 1 {
		h = 1
	}

	gl.Viewport(0, 0, w, h)
}
Пример #14
0
// TODO Dynamically fetch size and render accordingly.
func onResize(w, h int) {
	gl.Viewport(0, 0, w, h)
	gl.MatrixMode(gl.PROJECTION)
	gl.LoadIdentity()
	gl.Ortho(0, float64(w), float64(h), 0, -1, 1)
	gl.ClearColor(0.255, 0.255, 0.255, 0)
	gl.Clear(gl.COLOR_BUFFER_BIT)
	gl.MatrixMode(gl.MODELVIEW)
	gl.LoadIdentity()
	// log.Printf("resized: %dx%d\n", w, h)
}
Пример #15
0
// 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, width, 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)
}
Пример #16
0
func reshape(w, h int) {
	// Write to both buffers, prevent flickering
	gl.DrawBuffer(gl.FRONT_AND_BACK)

	gl.MatrixMode(gl.PROJECTION)
	gl.LoadIdentity()
	gl.Viewport(0, 0, w, h)
	gl.Ortho(0, float64(w), float64(h), 0, -1.0, 1.0)
	gl.MatrixMode(gl.MODELVIEW)
	gl.LoadIdentity()
}
Пример #17
0
/*
下面的代码的作用是重新设置OpenGL场景的大小,而不管窗口的大小是否已经改变(假定您没有使用全屏模式)。
甚至您无法改变窗口的大小时(例如您在全屏模式下),它至少仍将运行一次--在程序开始时设置我们的透视图。
OpenGL场景的尺寸将被设置成它显示时所在窗口的大小。
*/
func onResize(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()                                        ///重置模型观察矩阵
}
Пример #18
0
func onResize(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()
}
Пример #19
0
Файл: 08.go Проект: nzlov/gogl
func onResize(w, h int) {
	if h == 0 {
		h = 1
	}

	gl.Viewport(0, 0, w, h)
	gl.MatrixMode(gl.PROJECTION)
	gl.LoadIdentity()
	gl.Frustum(-1.0, 1.0, -1.0, 1.0, 1, 20)
	gl.MatrixMode(gl.MODELVIEW)
	gl.LoadIdentity()
}
Пример #20
0
/* 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)
}
Пример #21
0
func setupGL(w, h int) {
	gl.Viewport(0, 0, w, h)
	gl.MatrixMode(gl.PROJECTION)
	gl.LoadIdentity()
	gl.Ortho(0, float64(w), float64(h), 0, 0, 1)

	gl.ShadeModel(gl.SMOOTH)
	gl.ClearColor(1, 1, 1, 0)
	gl.Enable(gl.BLEND)
	gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)
	gl.Disable(gl.DEPTH_TEST)
	gl.Hint(gl.LINE_SMOOTH_HINT|gl.LINE_SMOOTH_HINT, gl.NICEST)
}
Пример #22
0
func onResize(w, h int) {
	// Write to both buffers, prevent flickering
	gl.DrawBuffer(gl.FRONT_AND_BACK)

	gl.MatrixMode(gl.PROJECTION)
	gl.LoadIdentity()
	gl.Viewport(0, 0, w, h)
	gl.Ortho(0, float64(w), float64(h), 0, -1.0, 1.0)
	gl.ClearColor(1, 1, 1, 0)
	gl.Clear(gl.COLOR_BUFFER_BIT)
	gl.MatrixMode(gl.MODELVIEW)
	gl.LoadIdentity()
}
Пример #23
0
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. */
}
Пример #24
0
func reshapeWindow(window *glfw.Window, width, height int) {
	ratio := float64(width) / float64(height)
	gameWidth = ratio * fieldSize
	gameHeight = fieldSize
	gl.Viewport(0, 0, width, height)
	gl.MatrixMode(gl.PROJECTION)
	gl.LoadIdentity()

	gl.Ortho(0, gameWidth, 0, gameHeight, -1.0, 1.0)
	gl.MatrixMode(gl.MODELVIEW)
	if wireframe {
		gl.PolygonMode(gl.FRONT_AND_BACK, gl.LINE)
	}
}
Пример #25
0
func Reshape(width, height int) {
	gl.Viewport(0, 0, width, height)

	gl.MatrixMode(gl.PROJECTION)
	gl.LoadIdentity()
	gl.Ortho(-1, 1, -1, 1, -1, 1)
	//gl.Ortho(-2.1, 6.1, -2.25*2, 2.1*2, -1, 1) // Y debug

	gl.MatrixMode(gl.MODELVIEW)
	gl.LoadIdentity()

	gl.ClearColor(0, 0, 0, 1)
	gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)
}
Пример #26
0
// Render renders the given scene with the given camera to the window.
func (r *Renderer) Render(scene *Scene, camera *PerspectiveCamera) {
	gl.Viewport(0, 0, currentWindow.Width(), currentWindow.Height())
	// Seems to be causing a strange memory leak
	gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)

	for _, element := range scene.objects {
		handleElement(camera, element)
	}

	for _, text := range scene.texts {
		handleText(camera, text)
	}

	r.window.Swap()
}
Пример #27
0
Файл: 04.go Проект: nzlov/gogl
// new window size
func reshape(window *glfw.Window, width, height int) {
	h := float64(height) / float64(width)

	znear := 5.0
	zfar := 30.0
	xmax := znear * 0.5

	gl.Viewport(0, 0, width, height)
	gl.MatrixMode(gl.PROJECTION)
	gl.LoadIdentity()
	gl.Frustum(-xmax, xmax, -xmax*h, xmax*h, znear, zfar)
	gl.MatrixMode(gl.MODELVIEW)
	gl.LoadIdentity()
	gl.Translated(0.0, 0.0, -20.0)
}
Пример #28
0
// onResize handles window resize events.
func onResize(w, h int) {
	if w < 1 {
		w = 1
	}

	if h < 1 {
		h = 1
	}

	gl.Viewport(0, 0, w, h)
	gl.MatrixMode(gl.PROJECTION)
	gl.LoadIdentity()
	glu.Perspective(45.0, float64(w)/float64(h), 0.1, 2000.0)
	gl.MatrixMode(gl.MODELVIEW)
	gl.LoadIdentity()
}
Пример #29
0
// onResize handles window resize events.
func onResize(w, h int) {
	if w < 1 {
		w = 1
	}

	if h < 1 {
		h = 1
	}

	gl.Viewport(0, 0, w, h)
	gl.MatrixMode(gl.PROJECTION)
	gl.LoadIdentity()
	gl.Ortho(0, float64(w), float64(h), 0, 0, 1)
	gl.MatrixMode(gl.MODELVIEW)
	gl.LoadIdentity()
}
Пример #30
0
func onResize(w, h int) {
	if h <= 0 {
		h = 1
	}
	if w <= 0 {
		w = 1
	}

	Height = h
	Width = w

	gl.Viewport(0, 0, w, h)

	if GetScene() != nil && CurrentCamera() != nil {
		CurrentCamera().UpdateResolution()
	}
}