Ejemplo n.º 1
0
func InitGL(width, height, msaa int, fullscreen bool) {
	C.SDL_Init(C.SDL_INIT_VIDEO)
	C.SDL_VideoInit( /*nil*/ C.SDL_GetVideoDriver(0))
	C.SDL_GL_SetAttribute(C.SDL_GL_CONTEXT_MAJOR_VERSION, 3)
	C.SDL_GL_SetAttribute(C.SDL_GL_CONTEXT_MINOR_VERSION, 2)

	if msaa != 0 {
		C.SDL_GL_SetAttribute(C.SDL_GL_MULTISAMPLEBUFFERS, 1)
		C.SDL_GL_SetAttribute(C.SDL_GL_MULTISAMPLESAMPLES, C.int(msaa))
	}

	C.SDL_GL_SetAttribute(C.SDL_GL_DEPTH_SIZE, 16)
	//win = C.SDL_CreateWindow(nil, C.SDL_WINDOWPOS_CENTERED, C.SDL_WINDOWPOS_CENTERED,C.int(width), C.int(height), C.SDL_WINDOW_OPENGL)
	if fullscreen {
		win = C.SDL_CreateWindow(nil, C.SDL_WINDOWPOS_CENTERED, C.SDL_WINDOWPOS_CENTERED, C.int(width), C.int(height), C.SDL_WINDOW_OPENGL|C.SDL_WINDOW_FULLSCREEN_DESKTOP)
	} else {
		win = C.SDL_CreateWindow(nil, C.SDL_WINDOWPOS_CENTERED, C.SDL_WINDOWPOS_CENTERED, C.int(width), C.int(height), C.SDL_WINDOW_OPENGL)
	}

	C.SDL_ShowWindow(win)
	wat := C.SDL_GL_CreateContext(win)
	fmt.Println(C.GoString(C.SDL_GetVideoDriver(0)))

	C.SDL_GL_MakeCurrent(win, wat)
	//C.SDL_GL_SetSwapInterval(1)

	C.glEnable(C.GL_DEPTH_TEST)
	C.glDepthFunc(C.GL_LEQUAL)

	C.glClearColor(0.3, 0.5, 1, 0)
	C.glClear(C.GL_COLOR_BUFFER_BIT | C.GL_DEPTH_BUFFER_BIT)
	printerr("failed to initialize openGL")

}
Ejemplo n.º 2
0
func BeginFrame(width, height int, devicePixelRatio float32) {
	w := C.GLsizei(float32(width) * devicePixelRatio)
	h := C.GLsizei(float32(height) * devicePixelRatio)
	C.glViewport(0, 0, w, h)
	C.glClearColor(0, 0, 0, 1)
	C.glClear(C.GL_COLOR_BUFFER_BIT | C.GL_DEPTH_BUFFER_BIT | C.GL_STENCIL_BUFFER_BIT)
	C.nvgBeginFrame(vg, C.int(width), C.int(height), C.float(devicePixelRatio))
}
Ejemplo n.º 3
0
Archivo: gl.go Proyecto: eaburns/gl
// ClearColor specifies clear values for the color buffers.
func ClearColor(col color.Color) {
	r, g, b, a := col.RGBA()
	C.glClearColor(
		C.GLclampf(r)/255.0,
		C.GLclampf(g)/255.0,
		C.GLclampf(b)/255.0,
		C.GLclampf(a)/255.0)
}
Ejemplo n.º 4
0
func ClearColor(
	red Clampf, green Clampf,
	blue Clampf, alpha Clampf) {
	C.glClearColor(
		C.GLclampf(red),
		C.GLclampf(green),
		C.GLclampf(blue),
		C.GLclampf(alpha))

}
Ejemplo n.º 5
0
func (game *game) initGL() {
	log.Printf("GL_VERSION: %v GL_RENDERER: %v GL_VENDOR %v\n",
		GetString(C.GL_VERSION), GetString(C.GL_RENDERER), GetString(C.GL_VENDOR))
	log.Printf("GL_EXTENSIONS: %v\n", GetString(C.GL_EXTENSIONS))
	C.glClearColor(0.0, 0.0, 0.0, 1.0)
	C.glEnable(C.GL_CULL_FACE)
	C.glEnable(C.GL_DEPTH_TEST)

	game.prog = createProgram(vertShaderSrcDef, fragShaderSrcDef)
	posAttrib := attribLocation(game.prog, "vPosition")
	game.offsetUni = uniformLocation(game.prog, "offset")
	game.colorUni = uniformLocation(game.prog, "color")
	C.glUseProgram(game.prog)
	C.glEnableVertexAttribArray(C.GLuint(posAttrib))

	vertVBO := GenBuffer()
	checkGLError()
	C.glBindBuffer(C.GL_ARRAY_BUFFER, vertVBO)
	verts := []float32{.0, 0.5, -0.5, -0.5, 0.5, -0.5}
	C.glBufferData(C.GL_ARRAY_BUFFER, C.GLsizeiptr(len(verts)*int(unsafe.Sizeof(verts[0]))), unsafe.Pointer(&verts[0]), C.GL_STATIC_DRAW)
	C.glVertexAttribPointer(C.GLuint(posAttrib), 2, C.GL_FLOAT, C.GL_FALSE, 0, unsafe.Pointer(uintptr(0)))
}
Ejemplo n.º 6
0
Archivo: gl.go Proyecto: extrame/gl
// ClearColor calls glClearColor
func ClearColor(r float64, g float64, b float64, a float64) {
	C.glClearColor(C.GLclampf(r), C.GLclampf(g), C.GLclampf(b), C.GLclampf(a))
}
Ejemplo n.º 7
0
func ClearColor(red, green, blue, alpha float32) {
	C.glClearColor(C.GLclampf(red), C.GLclampf(green), C.GLclampf(blue), C.GLclampf(alpha))
}
Ejemplo n.º 8
0
func ClearColor(red, green, blue, alpha float32) {
	C.glClearColor(C.GLfloat(red), C.GLfloat(green), C.GLfloat(blue), C.GLfloat(alpha))
}
Ejemplo n.º 9
0
func Test(win window.Window) {
	C.glClearColor(1.0, 0.0, 0.0, 0.0)
	C.glClear(C.GL_COLOR_BUFFER_BIT | C.GL_DEPTH_BUFFER_BIT | C.GL_STENCIL_BUFFER_BIT)
	win.SwapBuffers()
}
Ejemplo n.º 10
0
func ClearColor(red, green, blue, alpha float32) {
	C.glClearColor(
		(C.GLclampf)(red), (C.GLclampf)(green),
		(C.GLclampf)(blue), (C.GLclampf)(alpha))
}
Ejemplo n.º 11
0
Archivo: gl.go Proyecto: lye/gl
// ClearColor calls glClearColor
func ClearColor(r int, g int, b int, a int) {
	C.glClearColor(C.GLclampf(r), C.GLclampf(g), C.GLclampf(b), C.GLclampf(a))
}
Ejemplo n.º 12
0
func Cls(c col.Colour) {
	//
	r, g, b := col.Float(c) // 0.0, 0.0, 0.0
	C.glClearColor(C.GLclampf(r), C.GLclampf(g), C.GLclampf(b), C.GLclampf(0.0))
}