예제 #1
0
func (video *Video) initGL() {
	log.Print("Initing")
	video.fpsmanager = gfx.NewFramerate()
	video.fpsmanager.SetFramerate(60)

	gl.ClearColor(0.0, 0.0, 0.0, 1.0)
	gl.Enable(gl.CULL_FACE)
	gl.Enable(gl.DEPTH_TEST)

	log.Print("Creating program")
	video.prog = createProgram(vertShaderSrcDef, fragShaderSrcDef)
	log.Print("Attrib loc 1")
	posAttrib := attribLocation(video.prog, "vPosition")
	log.Print("Attrib loc 2")
	texCoordAttr := attribLocation(video.prog, "vTexCoord")
	log.Print("Uniform loc 1")
	paletteLoc := uniformLocation(video.prog, "palette")
	log.Print("Uniform loc 2")
	video.textureUni = uniformLocation(video.prog, "texture")

	log.Print("Gen Texture")
	video.texture = genTexture()
	gl.ActiveTexture(gl.TEXTURE0)
	gl.BindTexture(gl.TEXTURE_2D, video.texture)

	log.Print("TexParam")
	gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST)
	gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST)

	gl.UseProgram(video.prog)
	gl.EnableVertexAttribArray(posAttrib)
	gl.EnableVertexAttribArray(texCoordAttr)

	gl.Uniform3iv(paletteLoc, nes.SPaletteRgb)

	log.Print("VertBO")
	vertVBO := genBuffer()
	checkGLError()
	gl.BindBuffer(gl.ARRAY_BUFFER, vertVBO)
	verts := f32.Bytes(binary.LittleEndian, -1.0, 1.0, -1.0, -1.0, 1.0, -1.0, 1.0, -1.0, 1.0, 1.0, -1.0, 1.0)
	gl.BufferData(gl.ARRAY_BUFFER, verts, gl.STATIC_DRAW)

	textCoorBuf := genBuffer()
	checkGLError()
	gl.BindBuffer(gl.ARRAY_BUFFER, textCoorBuf)
	texVerts := f32.Bytes(binary.LittleEndian, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0)
	gl.BufferData(gl.ARRAY_BUFFER, texVerts, gl.STATIC_DRAW)

	gl.VertexAttribPointer(posAttrib, 2, gl.FLOAT, false, 0, 0)
	gl.VertexAttribPointer(texCoordAttr, 2, gl.FLOAT, false, 0, 0)
	log.Print("Started")
}
예제 #2
0
func (e *Engine) Start() {
	var err error

	e.shader.program, err = LoadProgram("shader.v.glsl", "shader.f.glsl")
	if err != nil {
		panic(fmt.Sprintln("LoadProgram failed:", err))
	}

	e.shader.models, err = wavefront.Read("spiritframe.obj")
	check(err)

	e.shader.projectionmatrix = gl.GetUniformLocation(e.shader.program, "u_projectionMatrix")
	e.shader.viewmatrix = gl.GetUniformLocation(e.shader.program, "u_viewMatrix")
	e.shader.modelmatrix = gl.GetUniformLocation(e.shader.program, "u_modelMatrix")
	e.shader.normalmatrix = gl.GetUniformLocation(e.shader.program, "u_normalMatrix")
	e.shader.lightdir = gl.GetUniformLocation(e.shader.program, "u_lightDirection")
	e.shader.lightmatrix = gl.GetUniformLocation(e.shader.program, "u_lightmatrix")

	e.shader.vertCoord = gl.GetAttribLocation(e.shader.program, "a_vertex")
	e.shader.normal = gl.GetAttribLocation(e.shader.program, "a_normal")
	e.shader.texcoord = gl.GetAttribLocation(e.shader.program, "a_texCoord")

	for _, model := range e.shader.models {
		for _, group := range model.Groups {
			//颜色
			color := group.Material.Ambient
			//顶点
			data := f32.Bytes(binary.LittleEndian, group.Vertexes...)
			vertexCount := len(group.Vertexes) / 3
			databuf := gl.CreateBuffer()
			gl.BindBuffer(gl.ARRAY_BUFFER, databuf)
			gl.BufferData(gl.ARRAY_BUFFER, data, gl.STATIC_DRAW)
			//UV坐标
			textcoords := f32.Bytes(binary.LittleEndian, group.Textcoords...)
			uvbuf := gl.CreateBuffer()
			gl.BindBuffer(gl.ARRAY_BUFFER, uvbuf)
			gl.BufferData(gl.ARRAY_BUFFER, textcoords, gl.STATIC_DRAW)
			//发现坐标
			normals := f32.Bytes(binary.LittleEndian, group.Normals...)
			normalbuf := gl.CreateBuffer()
			gl.BindBuffer(gl.ARRAY_BUFFER, normalbuf)
			gl.BufferData(gl.ARRAY_BUFFER, normals, gl.STATIC_DRAW)

			tex, _ := LoadTexture(group.Material.Texturefile)
			e.shape.Objs = append(e.shape.Objs, Obj{vcount: vertexCount, coord: databuf, color: color, uvcoord: uvbuf, tex: tex, normal: normalbuf})

		}

	}
}
예제 #3
0
func (e *Engine) Start() {
	var err error

	e.shader.program, err = LoadProgram("shader.v.glsl", "shader.f.glsl")
	if err != nil {
		panic(fmt.Sprintln("LoadProgram failed:", err))
	}

	e.shader.models, err = wavefront.Read("girl.obj")
	check(err)

	e.shader.vertCoord = gl.GetAttribLocation(e.shader.program, "vertCoord")
	e.shader.vertTexCoord = gl.GetAttribLocation(e.shader.program, "vertTexCoord")
	e.shader.projection = gl.GetUniformLocation(e.shader.program, "projection")
	e.shader.view = gl.GetUniformLocation(e.shader.program, "view")
	e.shader.modelx = gl.GetUniformLocation(e.shader.program, "modelx")
	e.shader.modely = gl.GetUniformLocation(e.shader.program, "modely")
	e.shader.color = gl.GetUniformLocation(e.shader.program, "color")
	e.shader.useuv = gl.GetUniformLocation(e.shader.program, "useuv")

	for _, model := range e.shader.models {
		for _, group := range model.Groups {
			//颜色
			color := group.Material.Ambient
			//顶点
			data := f32.Bytes(binary.LittleEndian, group.Vertexes...)
			vertexCount := len(group.Vertexes) / 3
			databuf := gl.CreateBuffer()
			gl.BindBuffer(gl.ARRAY_BUFFER, databuf)
			gl.BufferData(gl.ARRAY_BUFFER, data, gl.STATIC_DRAW)
			//UV坐标
			textcoords := f32.Bytes(binary.LittleEndian, group.Textcoords...)
			uvbuf := gl.CreateBuffer()
			gl.BindBuffer(gl.ARRAY_BUFFER, uvbuf)
			gl.BufferData(gl.ARRAY_BUFFER, textcoords, gl.STATIC_DRAW)
			//贴图文件
			var useuv bool
			tex, err := LoadTexture(group.Material.Texturefile)
			if err != nil {
				useuv = false
			} else {
				useuv = true
			}
			e.shape.Objs = append(e.shape.Objs, Obj{vcount: vertexCount, coord: databuf, color: color, useuv: useuv, uvcoord: uvbuf, tex: tex})

		}

	}
}
예제 #4
0
func (video *Video) drawFrame() {
	gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)
	gl.UseProgram(video.prog)
	gl.ActiveTexture(gl.TEXTURE0)
	gl.BindTexture(gl.TEXTURE_2D, video.texture)

	log.Print("Reading")
	frame := <-video.pixelBuffer
	buf := make([]float32, len(frame))
	log.Print("Read frame")

	for k, v := range frame {
		buf[k] = float32(v)
	}

	log.Print("Writing")
	if video.pixelBuffer != nil {
		gl.TexImage2D(gl.TEXTURE_2D, 0, 256, 256, gl.RGBA,
			gl.UNSIGNED_SHORT_4_4_4_4, f32.Bytes(binary.LittleEndian, buf...))
	}
	log.Print("Wrote")

	gl.DrawArrays(gl.TRIANGLES, 0, 6)
	video.fpsmanager.FramerateDelay()
}
예제 #5
0
func (e *Engine) Start() {
	var err error

	e.shader.program, err = LoadProgram("shader.v.glsl", "shader.f.glsl")
	if err != nil {
		panic(fmt.Sprintln("LoadProgram failed:", err))
	}

	e.shader.models, err = wavefront.Read("gopher.obj")
	check(err)

	e.shader.vertCoord = gl.GetAttribLocation(e.shader.program, "vertCoord")
	e.shader.projection = gl.GetUniformLocation(e.shader.program, "projection")
	e.shader.view = gl.GetUniformLocation(e.shader.program, "view")
	e.shader.modelx = gl.GetUniformLocation(e.shader.program, "modelx")
	e.shader.modely = gl.GetUniformLocation(e.shader.program, "modely")
	e.shader.color = gl.GetUniformLocation(e.shader.program, "color")

	for _, model := range e.shader.models {
		for _, group := range model.Groups {
			data := f32.Bytes(binary.LittleEndian, group.Vertexes...)
			color := group.Material.Ambient
			vertexCount := len(data)

			databuf := gl.CreateBuffer()
			e.shape.bufs = append(e.shape.bufs, Buf{vertexCount, databuf, color})

			gl.BindBuffer(gl.ARRAY_BUFFER, databuf)
			gl.BufferData(gl.ARRAY_BUFFER, data, gl.STATIC_DRAW)

		}

	}
}
예제 #6
0
파일: key.go 프로젝트: rakyll/GCSolutions
func (r *Key) chart() {
	keys := []float32{
		// position    // Tex cordinates
		// top
		r.x, r.y, r.z, 0, 0, // top left
		r.x + r.length, r.y, r.z, 1, 0, // top right
		r.x, r.y + r.width, r.z, 0, 1, // bottom left
		r.x + r.length, r.y + r.width, r.z, 1, 1, // bottom right

		//front
		r.x + r.length, r.y, r.z, 1, 0,
		r.x + r.length, r.y + r.width, r.z, 1, 1,
		r.x + r.length, r.y, r.z - r.height, 1, 0,
		r.x + r.length, r.y + r.width, r.z - r.height, 1, 1,

		//left
		r.x, r.y + r.width, r.z, 0, 1,
		r.x + r.length, r.y + r.width, r.z, 1, 1,
		r.x, r.y + r.width, r.z - r.height, 1, 0,
		r.x + r.length, r.y + r.width, r.z - r.height, 0, 0,

		//right
		r.x, r.y, r.z, 0, 0,
		r.x + r.length, r.y, r.z, 1, 0,
		r.x, r.y, r.z - r.height, 0, 1,
		r.x + r.length, r.y, r.z - r.height, 1, 1,
	}

	r.data = append(r.data, f32.Bytes(binary.LittleEndian, keys...)...)
}
예제 #7
0
파일: screen.go 프로젝트: monopole/volley
func makeTriangleData() []byte {
	halfBase, halfHeight := computeTriangleLengths()
	return f32.Bytes(binary.LittleEndian,
		-halfBase, -halfHeight, 0.0,
		0.0, halfHeight, 0.0,
		halfBase, -halfHeight, 0.0,
	)
}
예제 #8
0
파일: main.go 프로젝트: plumbum/go-samples
func circleTriangle() {

	x1, y1 := getXY(angle)
	x2, y2 := getXY(angle + math.Pi*2*1/3)
	x3, y3 := getXY(angle + math.Pi*2*2/3)

	triangleData = f32.Bytes(binary.LittleEndian,
		x1*0.4, y1*0.4, 0.0,
		x2*0.4, y2*0.4, 0.0,
		x3*0.4, y3*0.4, 0.0,
	)

	angle += math.Pi / 200
	if angle > math.Pi*2 {
		angle -= math.Pi * 2
	}
}
예제 #9
0
// makeWhiteKeyVector creates 1) the OpenGL coordinates for the key in portrait and landscape mode
// 2) the box of the actual key and 3) the greater outer outline of the key which includes the surrounding gap
func makeWhiteKeyVector(width float32, count int) ([]byte, util.Boundary, util.Boundary) {

	keyOutline := util.Boundary{BottomY: 0.0, TopY: TopOfKey}
	// Which white key are we on. Start at that offset.
	offset := (float32(count)) / NumberOfWhiteKeys * util.MaxGLSize
	// Width of window / NumberOfWhiteKeys = width of each white key = w_k
	widthOfOneKey := width / NumberOfWhiteKeys

	keyOuterBoundary := util.Boundary{BottomY: 0.0, TopY: TopOfKey, LeftX: offset,
		RightX: offset + widthOfOneKey/width*util.MaxGLSize}

	// want KeytoGapRatio% of the width of a key to be white (allow for black separation between keys) = p
	// Top left & bottom left (x = (offset + ((1-p) / 2) *w_k) / width * MaxGLSize)
	// Top right & bottom right (x = (offset + w_k-(w_k* (1-p) / 2)) / width * MaxGLsize)
	keyOutline.RightX = offset + (widthOfOneKey-(widthOfOneKey*(1-KeytoGapRatio)/2))/width*util.MaxGLSize
	keyOutline.LeftX = offset + (widthOfOneKey*(1-KeytoGapRatio)/2)/width*util.MaxGLSize
	return f32.Bytes(binary.LittleEndian, makeCoordsForBothOrientation(keyOutline)...),
		keyOutline, keyOuterBoundary
}
예제 #10
0
// makeBlackKeyVector creates 1) the OpenGL coordinates for the key in portrait and landscape mode
// 2) the box of the actual key and 3) the greater outer outline of the key which includes the surrounding gap
func makeBlackKeyVector(leftWhiteKey Key) ([]byte, util.Boundary, util.Boundary) {

	// First, let's get the width of the white key.
	widthOfWhiteKey := leftWhiteKey.GetOuterBoundary().RightX - leftWhiteKey.GetOuterBoundary().LeftX
	// Determine the width of the blackKey with whiteKeyToBlackKeyWidthRatio
	widthOfBlackKey := whiteKeyToBlackKeyWidthRatio * widthOfWhiteKey
	// Use the end of the white key as the center of the black key and add the offsets to the sides.
	keyOuterBoundary := util.Boundary{BottomY: TopOfKey - whiteKeyToBlackKeyLengthRatio*TopOfKey,
		TopY:   TopOfKey,
		LeftX:  leftWhiteKey.GetOuterBoundary().RightX - (widthOfBlackKey / 2),
		RightX: leftWhiteKey.GetOuterBoundary().RightX + (widthOfBlackKey / 2)}
	// Use the same gap the white key uses for the black key
	gap := leftWhiteKey.GetOutline().LeftX - leftWhiteKey.GetOuterBoundary().LeftX

	keyOutline := util.Boundary{TopY: TopOfKey, BottomY: keyOuterBoundary.BottomY + gap,
		LeftX: keyOuterBoundary.LeftX + gap, RightX: keyOuterBoundary.RightX - gap}
	return f32.Bytes(binary.LittleEndian, makeCoordsForBothOrientation(keyOutline)...),
		keyOutline, keyOuterBoundary
}
예제 #11
0
파일: glimage.go 프로젝트: rockxcn/mobile
	gl.EnableVertexAttribArray(glimage.pos)
	gl.VertexAttribPointer(glimage.pos, 2, gl.FLOAT, false, 0, 0)

	gl.BindBuffer(gl.ARRAY_BUFFER, glimage.quadUV)
	gl.EnableVertexAttribArray(glimage.inUV)
	gl.VertexAttribPointer(glimage.inUV, 2, gl.FLOAT, false, 0, 0)

	gl.DrawArrays(gl.TRIANGLE_STRIP, 0, 4)

	gl.DisableVertexAttribArray(glimage.pos)
	gl.DisableVertexAttribArray(glimage.inUV)
}

var quadXYCoords = f32.Bytes(binary.LittleEndian,
	-1, +1, // top left
	+1, +1, // top right
	-1, -1, // bottom left
	+1, -1, // bottom right
)

var quadUVCoords = f32.Bytes(binary.LittleEndian,
	0, 0, // top left
	1, 0, // top right
	0, 1, // bottom left
	1, 1, // bottom right
)

const vertexShader = `#version 100
uniform mat3 mvp;
uniform mat3 uvp;
attribute vec3 pos;
attribute vec2 inUV;
예제 #12
0
var cubeData = f32.Bytes(binary.LittleEndian, //三角
	0.5, 0.5, 0.5,
	0.5, 0.5, -0.5,

	0.5, 0.5, -0.5,
	0.5, -0.5, -0.5,

	0.5, -0.5, -0.5,
	0.5, -0.5, 0.5,

	0.5, -0.5, 0.5,
	0.5, 0.5, 0.5,

	-0.5, 0.5, 0.5,
	-0.5, 0.5, -0.5,

	-0.5, 0.5, -0.5,
	-0.5, -0.5, -0.5,

	-0.5, -0.5, -0.5,
	-0.5, -0.5, 0.5,

	-0.5, -0.5, 0.5,
	-0.5, 0.5, 0.5,

	0.5, 0.5, 0.5,
	-0.5, 0.5, 0.5,

	0.5, 0.5, -0.5,
	-0.5, 0.5, -0.5,

	0.5, -0.5, -0.5,
	-0.5, -0.5, -0.5,

	0.5, -0.5, 0.5,
	-0.5, -0.5, 0.5,
)
예제 #13
0
파일: gl.go 프로젝트: asimshankar/triangles
void main() {
	gl_FragColor = color;
}`

	coordsPerVertex         = 3
	vertexCount             = 3
	triangleSide    float32 = 0.4 // In OpenGL coordinates where the full screen in of size 2 [-1, 1]
	bannerWidth             = 0.1
)

var (
	triangleHeight       = float32(math.Sqrt(3)) * triangleSide / 2
	triangleCenterHeight = triangleSide / (2 * float32(math.Sqrt(3)))
	triangleData         = f32.Bytes(binary.LittleEndian,
		-triangleSide/2, -triangleHeight/2, 0, // bottom left
		0, triangleHeight/2, 0, // top
		triangleSide/2, -triangleHeight/2, 0, // bottom right
	)
	topBannerData = f32.Bytes(binary.LittleEndian,
		-1, 1, 0,
		1, 1, 0,
		1, 1-bannerWidth, 0,
		-1, 1-bannerWidth, 0,
	)
	leftBannerData = f32.Bytes(binary.LittleEndian,
		-1, 1, 0,
		-1+bannerWidth, 1, 0,
		-1+bannerWidth, -1, 0,
		-1, -1, 0,
	)
)
예제 #14
0
파일: main.go 프로젝트: rakyll/GCSolutions
var triangleData = f32.Bytes(binary.LittleEndian,
	// front
	-1.0, -1.0, 1.0, 0.98, 0.972, 0.94, 1, 0, 0, 1,
	1.0, -1.0, 1.0, 0.98, 0.972, 0.94, 1, 0, 0, 1,
	1.0, 1.0, 1.0, 0.98, 0.972, 0.94, 1, 0, 0, 1,
	1.0, 1.0, 1.0, 0.98, 0.972, 0.94, 1, 0, 0, 1,
	-1.0, 1.0, 1.0, 0.98, 0.972, 0.94, 1, 0, 0, 1,
	-1.0, -1.0, 1.0, 0.98, 0.972, 0.94, 1, 0, 0, 1,
	// top
	-1.0, 1.0, 1.0, 0.98, 0.972, 0.94, 1, 0, 1, 0,
	1.0, 1.0, 1.0, 0.98, 0.972, 0.94, 1, 0, 1, 0,
	1.0, 1.0, -1.0, 0.98, 0.972, 0.94, 1, 0, 1, 0,
	1.0, 1.0, -1.0, 0.98, 0.972, 0.94, 1, 0, 1, 0,
	-1.0, 1.0, -1.0, 0.98, 0.972, 0.94, 1, 0, 1, 0,
	-1.0, 1.0, 1.0, 0.98, 0.972, 0.94, 1, 0, 1, 0,
	// back
	-1.0, -1.0, -1.0, 0.98, 0.972, 0.94, 1, 0, 0, -1,
	1.0, -1.0, -1.0, 0.98, 0.972, 0.94, 1, 0, 0, -1,
	1.0, 1.0, -1.0, 0.98, 0.972, 0.94, 1, 0, 0, -1,
	1.0, 1.0, -1.0, 0.98, 0.972, 0.94, 1, 0, 0, -1,
	-1.0, 1.0, -1.0, 0.98, 0.972, 0.94, 1, 0, 0, -1,
	-1.0, -1.0, -1.0, 0.98, 0.972, 0.94, 1, 0, 0, -1,
	// bottom
	-1.0, -1.0, -1.0, 0.98, 0.972, 0.94, 1, 0, -1, 0,
	1.0, -1.0, -1.0, 0.98, 0.972, 0.94, 1, 0, -1, 0,
	1.0, -1.0, 1.0, 0.98, 0.972, 0.94, 1, 0, -1, 0,
	1.0, -1.0, 1.0, 0.98, 0.972, 0.94, 1, 0, -1, 0,
	-1.0, -1.0, 1.0, 0.98, 0.972, 0.94, 1, 0, -1, 0,
	-1.0, -1.0, -1.0, 0.98, 0.972, 0.94, 1, 0, -1, 0,
	// left
	-1.0, -1.0, -1.0, 0.98, 0.972, 0.94, 1, 1, 0, 0,
	-1.0, -1.0, 1.0, 0.98, 0.972, 0.94, 1, 1, 0, 0,
	-1.0, 1.0, 1.0, 0.98, 0.972, 0.94, 1, 1, 0, 0,
	-1.0, 1.0, 1.0, 0.98, 0.972, 0.94, 1, 1, 0, 0,
	-1.0, 1.0, -1.0, 0.98, 0.972, 0.94, 1, 1, 0, 0,
	-1.0, -1.0, -1.0, 0.98, 0.972, 0.94, 1, 1, 0, 0,
	// right
	1.0, -1.0, 1.0, 0.98, 0.972, 0.94, 1, -1, 0, 0,
	1.0, -1.0, -1.0, 0.98, 0.972, 0.94, 1, -1, 0, 0,
	1.0, 1.0, -1.0, 0.98, 0.972, 0.94, 1, -1, 0, 0,
	1.0, 1.0, -1.0, 0.98, 0.972, 0.94, 1, -1, 0, 0,
	1.0, 1.0, 1.0, 0.98, 0.972, 0.94, 1, -1, 0, 0,
	1.0, -1.0, 1.0, 0.98, 0.972, 0.94, 1, -1, 0, 0,
)
예제 #15
0
	  type    指定数组中每个组件的数据类型。可用的符号常量有GL_BYTE, GL_UNSIGNED_BYTE, GL_SHORT,GL_UNSIGNED_SHORT, GL_FIXED, 和 GL_FLOAT,初始值为GL_FLOAT。
	  normalized  指定当被访问时,固定点数据值是否应该被归一化(GL_TRUE)或者直接转换为固定点值(GL_FALSE)。
	  stride  指定连续顶点属性之间的偏移量。如果为0,那么顶点属性会被理解为:它们是紧密排列在一起的。初始值为0。
	  pointer 指定第一个组件在数组的第一个顶点属性中的偏移量。该数组与GL_ARRAY_BUFFER绑定,储存于缓冲区中。初始值为0;
	*/
	gl.VertexAttribPointer(position, coordsPerVertex, gl.FLOAT, false, 0, 0) //更新position值
	gl.DrawArrays(gl.LINES, 0, vertexCount)
	gl.DisableVertexAttribArray(position)

	debug.DrawFPS(c)
}

var lineData = f32.Bytes(binary.LittleEndian, //三角
	0.0, 0.5, 0.0, // top left
	-0.5, -0.5, 0.0, // bottom left
	-0.5, -0.5, 0.0, // bottom left
	0.5, -0.5, 0.0, // bottom right
	0.5, -0.5, 0.0, // bottom right
	0.0, 0.5, 0.0, // top left
)

const (
	coordsPerVertex = 3 //点坐标
)

//两类着色器编程使用GLSL(GL Shader Language,GL着色语言),它是OpenGL的一部分。与C或Java不同,GLSL必须在运行时编译,这意味着每次启动程序,所有的着色器将重新编译。
//顶点(vertex)着色器,它将作用于每个顶点上
//vec2即2个值,vec4即4个值
const vertexShader = `#version 100
uniform mat4 scan;
attribute vec4 position;
void main() {
예제 #16
0
	mu.Unlock()

	c := &http.Client{Transport: transport}
	_, err := c.Do(req)
	if err != nil {
		fmt.Println(err)
	}

	mu.Lock()
	req = nil
	mu.Unlock()
}

var rectData = f32.Bytes(binary.LittleEndian,
	0, 0,
	0, 0.2,
	0.2, 0,
	0.2, 0.2,
)

const vertexShader = `#version 100
uniform vec2 offset;

attribute vec4 position;
void main() {
  // offset comes in with x/y values between 0 and 1.
  // position bounds are -1 to 1.
  vec4 offset4 = vec4(2.0*offset.x-1.0, 1.0-2.0*offset.y, 0, 0);
  gl_Position = position + offset4;
}`

const fragmentShader = `#version 100
예제 #17
0
	gl.VertexAttribPointer(position, coordsPerVertex, gl.FLOAT, false, 0, 0) //更新position值
	//gl.DisableVertexAttribArray(position)

	gl.BindBuffer(gl.ARRAY_BUFFER, colorbuf)

	gl.EnableVertexAttribArray(color)
	gl.VertexAttribPointer(color, colorsPerVertex, gl.FLOAT, false, 0, 0) //更新color值
	gl.DrawArrays(gl.TRIANGLES, 0, vertexCount)
	//gl.DisableVertexAttribArray(color)

	debug.DrawFPS(c)
}

var triangleData = f32.Bytes(binary.LittleEndian, //三角
	0.0, 0.5, 0.0, // top left
	-0.5, -0.5, 0.0, // bottom left
	0.5, -0.5, 0.0, // bottom right
)

var colorData = f32.Bytes(binary.LittleEndian, //过渡色
	1.0, 0.0, 0.0, 1, // red
	0.0, 1.0, 0.0, 1, // green
	0.0, 0.0, 1.0, 1, // blue
)

const (
	coordsPerVertex = 3 //坐标属性个数 x y z
	vertexCount     = 3 //点数
	colorsPerVertex = 4 //颜色属性个数 r g b a
)
예제 #18
0
파일: main.go 프로젝트: bmatsuo/rex
	glctx.Uniform2f(offset, touchX/float32(sz.WidthPx), touchY/float32(sz.HeightPx))

	glctx.BindBuffer(gl.ARRAY_BUFFER, buf)
	glctx.EnableVertexAttribArray(position)
	glctx.VertexAttribPointer(position, coordsPerVertex, gl.FLOAT, false, 0, 0)
	glctx.DrawArrays(gl.TRIANGLES, 0, vertexCount)
	glctx.DisableVertexAttribArray(position)

	statusPainter.Draw(sz, actionBarPad, statusFaceOpt)
	fps.Draw(sz)
}

var triangleData = f32.Bytes(binary.LittleEndian,
	0.0, 0.4, 0.0, // top left
	0.0, 0.0, 0.0, // bottom left
	0.4, 0.0, 0.0, // bottom right
)

const (
	coordsPerVertex = 3
	vertexCount     = 3
)

const vertexShader = `#version 100
uniform vec2 offset;

attribute vec4 position;
void main() {
	// offset comes in with x/y values between 0 and 1.
	// position bounds are -1 to 1.
예제 #19
0
package main

import (
	"encoding/binary"
	"golang.org/x/mobile/exp/f32"
)

var dswastikaData = f32.Bytes(binary.LittleEndian,
	0.0, -0.5, 0.0, 0.0, 0.5, 0.0,
	-0.5, -0.5, 0.0, 0.0, -0.5, 0.0,
	0.0, 0.5, 0.0, 0.5, 0.5, 0.0,

	-0.5, 0.5, 0.0, -0.5, 0.0, 0.0,
	-0.5, 0.0, 0.0, 0.5, 0.0, 0.0,
	0.5, 0.0, 0.0, 0.5, -0.5, 0.0,
)

var swastikaData = f32.Bytes(binary.LittleEndian,
	-0.4, -0.2, 0.0, 0.0, 0.4, 0.0,
	-0.4, -0.2, 0.0, 0.4, -0.2, 0.0,
	0.0, 0.4, 0.0, 0.4, -0.2, 0.0,

	-0.4, 0.2, 0.0, 0.4, 0.2, 0.0,
	-0.4, 0.2, 0.0, 0.0, -0.4, 0.0,
	0.0, -0.4, 0.0, 0.4, 0.2, 0.0,
)

var quadData = f32.Bytes(binary.LittleEndian,
	-0.3, -0.3, 0.0,
	0.3, -0.3, 0.0,
	0.3, 0.3, 0.0,
예제 #20
0
var cubeData = f32.Bytes(binary.LittleEndian,
	-1.0, -1.0, -1.0,
	1.0, -1.0, -1.0,
	-1.0, -1.0, 1.0,
	1.0, -1.0, -1.0,
	1.0, -1.0, 1.0,
	-1.0, -1.0, 1.0,

	-1.0, 1.0, -1.0,
	-1.0, 1.0, 1.0,
	1.0, 1.0, -1.0,
	1.0, 1.0, -1.0,
	-1.0, 1.0, 1.0,
	1.0, 1.0, 1.0,

	-1.0, -1.0, 1.0,
	1.0, -1.0, 1.0,
	-1.0, 1.0, 1.0,
	1.0, -1.0, 1.0,
	1.0, 1.0, 1.0,
	-1.0, 1.0, 1.0,

	-1.0, -1.0, -1.0,
	-1.0, 1.0, -1.0,
	1.0, -1.0, -1.0,
	1.0, -1.0, -1.0,
	-1.0, 1.0, -1.0,
	1.0, 1.0, -1.0,

	-1.0, -1.0, 1.0,
	-1.0, 1.0, -1.0,
	-1.0, -1.0, -1.0,
	-1.0, -1.0, 1.0,
	-1.0, 1.0, 1.0,
	-1.0, 1.0, -1.0,

	1.0, -1.0, 1.0,
	1.0, -1.0, -1.0,
	1.0, 1.0, -1.0,
	1.0, -1.0, 1.0,
	1.0, 1.0, -1.0,
	1.0, 1.0, 1.0,
)