當前位置: 首頁>>代碼示例>>Golang>>正文


Golang gl33.Sizei函數代碼示例

本文整理匯總了Golang中github.com/chsc/gogl/gl33.Sizei函數的典型用法代碼示例。如果您正苦於以下問題:Golang Sizei函數的具體用法?Golang Sizei怎麽用?Golang Sizei使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了Sizei函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: createShader

func createShader(name string, shaderType int) (gl.Uint, error) {
	data, err := fileRead(name)
	if err != nil {
		return 0, err
	}
	if len(data) == 0 {
		return 0, errors.New("No shader code.")
	}
	var shader gl.Uint
	switch shaderType {
	case VertexShaderType:
		shader = gl.CreateShader(gl.VERTEX_SHADER)
	case FragmentShaderType:
		shader = gl.CreateShader(gl.FRAGMENT_SHADER)
	default:
		return 0, errors.New("Unknown ShaderType.")
	}
	src := gl.GLStringArray(string(data))
	defer gl.GLStringArrayFree(src)
	gl.ShaderSource(shader, gl.Sizei(1), &src[0], nil)
	gl.CompileShader(shader)

	// Similar to print_log in the C code example
	var length gl.Int
	gl.GetShaderiv(shader, gl.INFO_LOG_LENGTH, &length)
	if length > 1 {
		glString := gl.GLStringAlloc(gl.Sizei(length))
		defer gl.GLStringFree(glString)
		gl.GetShaderInfoLog(shader, gl.Sizei(length), nil, glString)
		return 0, errors.New(fmt.Sprintf("Shader log: %s", gl.GoString(glString)))
	}
	return shader, nil
}
開發者ID:pdelbarba,項目名稱:gl3-examples,代碼行數:33,代碼來源:main.go

示例2: NewGLRenderer

func NewGLRenderer(view *View, title string) *GLRenderer {
	r := new(GLRenderer)
	r.View = view
	GL <- func() {
		if sdl.Init(sdl.INIT_VIDEO) < 0 {
			panic(sdl.GetError())
		}
		sdl.GL_SetAttribute(sdl.GL_DOUBLEBUFFER, 1)
		sdl.GL_SetAttribute(sdl.GL_SWAP_CONTROL, 1)
		r.Screen = sdl.SetVideoMode(view.Width, view.Height, 32, sdl.OPENGL)
		if r.Screen == nil {
			panic(sdl.GetError())
		}
		sdl.WM_SetCaption(title, title)
		err := gl33.Init()
		if err != nil {
			panic(err)
		}
		gl33.Enable(gl33.BLEND)
		gl33.Enable(gl33.CULL_FACE)
		gl33.Enable(gl33.DEPTH_TEST)
		gl33.ClearColor(1.0, 1.0, 1.0, 1.0)
		gl33.BlendFunc(gl33.SRC_ALPHA, gl33.ONE_MINUS_SRC_ALPHA)
		gl33.DepthFunc(gl33.LEQUAL)
		gl33.Viewport(0, 0, gl33.Sizei(view.Width), gl33.Sizei(view.Height))
	}
	r.PerspectiveMatrix = s3dm.PerspectiveMatrix(view.Fovy, view.Aspect, view.Near, view.Far)
	r.OrthographicMatrix = s3dm.OrthographicMatrix(float64(view.Width), float64(view.Height), 0, 1)
	return r
}
開發者ID:klkblake,項目名稱:sge,代碼行數:30,代碼來源:glrenderer.go

示例3: GetInfoLog

func (shader *Shader) GetInfoLog() string {
	length := shader.Get(gl33.INFO_LOG_LENGTH)
	log := gl33.GLStringAlloc(gl33.Sizei(length + 1))
	defer gl33.GLStringFree(log)
	gl33.GetShaderInfoLog(shader.Id, gl33.Sizei(length), nil, log)
	return gl33.GoString(log)
}
開發者ID:klkblake,項目名稱:sge,代碼行數:7,代碼來源:shader.go

示例4: setupAttrib

func setupAttrib(location gl33.Uint, type_ gl33.Enum, dimensions int, offset uintptr, vertexSize int) {
	gl33.EnableVertexAttribArray(location)
	if type_ == gl33.FLOAT || type_ == gl33.DOUBLE {
		gl33.VertexAttribPointer(location, gl33.Int(dimensions), type_, gl33.FALSE, gl33.Sizei(vertexSize), gl33.Pointer(offset))
	} else {
		gl33.VertexAttribIPointer(location, gl33.Int(dimensions), type_, gl33.Sizei(vertexSize), gl33.Pointer(offset))
	}
}
開發者ID:klkblake,項目名稱:sge,代碼行數:8,代碼來源:mesh.go

示例5: getError

func (p *Program) getError() error {
	var logLength gl.Int
	gl.GetProgramiv(p.id, gl.INFO_LOG_LENGTH, &logLength)
	log := gl.GLStringAlloc(gl.Sizei(logLength))
	defer gl.GLStringFree(log)
	gl.GetProgramInfoLog(p.id, gl.Sizei(logLength), nil, log)
	err := gl.GoString(log)
	return errors.New(err)
}
開發者ID:extemporalgenome,項目名稱:baukasten,代碼行數:9,代碼來源:program.go

示例6: getError

func (s *Shader) getError() error {
	var logLength gl.Int
	gl.GetShaderiv(s.id, gl.INFO_LOG_LENGTH, &logLength)
	log := gl.GLStringAlloc(gl.Sizei(logLength))
	defer gl.GLStringFree(log)
	gl.GetShaderInfoLog(s.id, gl.Sizei(logLength), nil, log)
	err := gl.GoString(log)
	return errors.New(err)
}
開發者ID:extemporalgenome,項目名稱:baukasten,代碼行數:9,代碼來源:shader.go

示例7: uploadSurface

func uploadSurface(target gl33.Enum, surface *sdl.Surface) {
	if target == gl33.TEXTURE_CUBE_MAP && surface.W != surface.H {
		panic("Non-square texture in cube map")
	}
	var internalFormat gl33.Int
	var format gl33.Enum
	if surface.Format.BitsPerPixel == 32 {
		internalFormat = gl33.RGBA8
		format = gl33.RGBA
	} else {
		internalFormat = gl33.RGB8
		format = gl33.RGB
	}
	gl33.TexImage2D(target, 0, internalFormat, gl33.Sizei(surface.W), gl33.Sizei(surface.H), 0, format, gl33.UNSIGNED_BYTE, gl33.Pointer(surface.Pixels))
}
開發者ID:klkblake,項目名稱:sge,代碼行數:15,代碼來源:texture.go

示例8: initResources

func initResources() {
	var compileOk gl.Int
	// Vertex Shader
	vs = gl.CreateShader(gl.VERTEX_SHADER)
	vsSrc := gl.GLStringArray(vsSource)
	defer gl.GLStringArrayFree(vsSrc)
	gl.ShaderSource(vs, gl.Sizei(len(vsSrc)), &vsSrc[0], nil)
	gl.CompileShader(vs)
	gl.GetShaderiv(vs, gl.COMPILE_STATUS, &compileOk)
	if compileOk == 0 {
		errNum := gl.GetError()
		fmt.Printf("Error in vertex shader: %d\n", errNum)
	}

	// Fragment Shader
	fs = gl.CreateShader(gl.FRAGMENT_SHADER)
	fsSrc := gl.GLStringArray(fsSource)
	defer gl.GLStringArrayFree(fsSrc)
	gl.ShaderSource(fs, gl.Sizei(1), &fsSrc[0], nil)
	gl.CompileShader(fs)
	gl.GetShaderiv(fs, gl.COMPILE_STATUS, &compileOk)
	if compileOk == 0 {
		errNum := gl.GetError()
		fmt.Printf("Error in fragment shader: %d\n", errNum)
	}

	// GLSL program
	program = gl.CreateProgram()
	gl.AttachShader(program, vs)
	gl.AttachShader(program, fs)
	gl.LinkProgram(program)
	gl.GetProgramiv(program, gl.LINK_STATUS, &compileOk)
	if compileOk == 0 {
		fmt.Printf("Error in program.\n")

	}

	// Get the attribute location from the GLSL program (here from the vertex shader)
	attributeName := gl.GLString("coord2d")
	defer gl.GLStringFree(attributeName)
	attributeTemp := gl.GetAttribLocation(program, attributeName)
	if attributeTemp == -1 {
		fmt.Printf("Could not bind attribute %s\n", gl.GoString(attributeName))
	}
	attributeCoord2d = gl.Uint(attributeTemp)
}
開發者ID:pdelbarba,項目名稱:gl3-examples,代碼行數:46,代碼來源:main.go

示例9: LoadTextureArray

func LoadTextureArray(filenames []string, minFilter int, magFilter int) *Texture {
	ch := make(chan *Texture)
	GL <- func() {
		tex := NewTextureArray()
		tex.SetFilters(minFilter, magFilter)
		tex.Bind(0)
		surfaces := make([]*sdl.Surface, len(filenames))
		for i, filename := range filenames {
			surfaces[i] = sdl.Load(filename)
			if surfaces[i] == nil {
				panic(sdl.GetError())
			}
			defer surfaces[i].Free()
		}
		tex.Width = int(surfaces[0].W)
		tex.Height = int(surfaces[0].H)
		var internalFormat gl33.Int
		var format gl33.Enum
		var size int
		if surfaces[0].Format.BitsPerPixel == 32 {
			internalFormat = gl33.RGBA8
			format = gl33.RGBA
			size = 4
		} else {
			internalFormat = gl33.RGB8
			format = gl33.RGB
			size = 3
		}
		pixels := make([]byte, tex.Width*tex.Height*len(surfaces)*size)
		for i, surface := range surfaces {
			p := uintptr(surface.Pixels)
			for j := 0; j < tex.Width*tex.Height*size; j++ {
				pixels[i*tex.Width*tex.Height*size+j] = *(*byte)(unsafe.Pointer(p + uintptr(j)))
			}
		}
		gl33.TexImage3D(gl33.TEXTURE_2D_ARRAY, 0, internalFormat, gl33.Sizei(tex.Width), gl33.Sizei(tex.Height), gl33.Sizei(len(surfaces)), 0, format, gl33.UNSIGNED_BYTE, gl33.Pointer(&pixels[0]))
		gl33.GenerateMipmap(gl33.TEXTURE_2D_ARRAY)
		ch <- tex
	}
	return <-ch
}
開發者ID:klkblake,項目名稱:sge,代碼行數:41,代碼來源:texture.go

示例10: LoadTexture

// LoadTexture buffers an image.Image into the graphic cards memory.
func LoadTexture(img image.Image) (*Texture, error) {
	w := img.Bounds().Dx()
	h := img.Bounds().Dy()
	rgba := image.NewRGBA(image.Rect(0, 0, w, h))
	for x := 0; x < w; x++ {
		for y := 0; y < h; y++ {
			rgba.Set(x, y, img.At(x, y))
		}
	}
	var textureId gl.Uint
	//gl.ActiveTexture(gl.TEXTURE0)
	gl.GenTextures(1, &textureId)
	gl.BindTexture(gl.TEXTURE_2D, textureId)
	//gl.TexParameterf(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR)
	gl.TexParameterf(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR)

	gl.TexImage2D(gl.TEXTURE_2D, 0, 4, gl.Sizei(rgba.Rect.Dx()), gl.Sizei(rgba.Rect.Dy()), 0, gl.RGBA, gl.UNSIGNED_BYTE, gl.Pointer(&rgba.Pix[0]))

	gl.BindTexture(gl.TEXTURE_2D, 0)
	return &Texture{id: textureId}, nil
}
開發者ID:extemporalgenome,項目名稱:baukasten,代碼行數:22,代碼來源:texture.go

示例11: drawgl

func drawgl() {
	gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)

	uniYaw = yrot * (math.Pi / 180.0)
	yrot = yrot - 1.0
	uniPitch = zrot * (math.Pi / 180.0)
	zrot = zrot - 0.5
	uniRoll = xrot * (math.Pi / 180.0)
	xrot = xrot - 0.2

	gl.Uniform4f(UniScale, gl.Float(uniRoll), gl.Float(uniYaw), gl.Float(uniPitch), gl.Float(uniscale))
	gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)
	gl.DrawArrays(gl.TRIANGLES, gl.Int(0), gl.Sizei(len(triangle_vertices)*4))

	time.Sleep(50 * time.Millisecond)

}
開發者ID:emlai,項目名稱:go-sdl2,代碼行數:17,代碼來源:opengl3.go

示例12: LoadShader

func LoadShader(data string, shaderType ShaderType) (*Shader, error) {
	var id gl.Uint
	switch shaderType {
	case VertexShader:
		id = gl.CreateShader(gl.VERTEX_SHADER)
	case FragmentShader:
		id = gl.CreateShader(gl.FRAGMENT_SHADER)
	default:
		return nil, ErrUnknownShader
	}
	shader := &Shader{id: id}
	src := gl.GLStringArray(data)
	length := gl.Int(-1)
	gl.ShaderSource(shader.id, gl.Sizei(1), &src[0], &length)
	gl.GLStringArrayFree(src)
	return shader, nil
}
開發者ID:extemporalgenome,項目名稱:baukasten,代碼行數:17,代碼來源:shader.go

示例13: drawPrimitives

func drawPrimitives(color color.Color, mode gl.Enum, vecs ...geometry.Vector2) {
	vertices := make([]float32, len(vecs)*2)
	r, g, b, a := glcolor.ConvertColorF(color)
	var colors []float32
	for i := range vecs {
		vertices[i*2] = vecs[i].X
		vertices[i*2+1] = vecs[i].Y
		colors = append(colors, r, g, b, a)
	}
	DefaultPrimitivesShaderProgram.Use()
	primitivesUniformMatrix.UniformMatrix4fv(1, false, DefaultCamera.Transposed())
	primitivesAttributeCoord.Enable()
	primitivesAttributeCoord.AttribPointer(2, gl.FLOAT, false, 0, gl.Pointer(&vertices[0]))

	primitivesAttributeColor.Enable()
	primitivesAttributeColor.AttribPointer(4, gl.FLOAT, false, 0, gl.Pointer(&colors[0]))

	gl.DrawArrays(mode, 0, gl.Sizei(len(vecs)))

	primitivesAttributeColor.Disable()
	primitivesAttributeCoord.Disable()
}
開發者ID:extemporalgenome,項目名稱:baukasten,代碼行數:22,代碼來源:primitives.go

示例14: Sizei

func (mf *Mat4f) Sizei() (sizeof gl.Sizei) {
	sizeof = gl.Sizei(unsafe.Sizeof(*mf))
	return sizeof
}
開發者ID:0xfaded,項目名稱:glmat,代碼行數:4,代碼來源:glsizei.go

示例15: Render

func (mesh *Mesh) Render() {
	gl33.BindVertexArray(mesh.vao)
	gl33.DrawElements(gl33.TRIANGLES, gl33.Sizei(len(mesh.Indicies)), gl33.UNSIGNED_INT, gl33.Pointer(uintptr(0)))
}
開發者ID:klkblake,項目名稱:sge,代碼行數:4,代碼來源:mesh.go


注:本文中的github.com/chsc/gogl/gl33.Sizei函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。