Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- VERTEX_SHADER = shaders.compileShader('''
- uniform float xpos;
- uniform float ypos;
- attribute vec3 position;
- attribute vec2 texcoords;
- attribute int texid;
- varying vec2 texcoords_u;
- varying int texid_u;
- void main() {
- gl_Position = gl_ModelViewProjectionMatrix * vec4(position,1.0) + vec4(
- xpos, ypos, 0.0, 0.0
- );
- //gl_TexCoord[0] = texcoords;
- //??
- texcoords_u = texcoords;
- texid_u = texid;
- }''', GL_VERTEX_SHADER)
- FRAGMENT_SHADER = shaders.compileShader('''
- varying vec2 texcoords_u;
- varying int texid_u;
- uniform sampler2D thetexture;//s[2]
- void main() {
- gl_FragColor = texture2D(thetexture, texcoords_u);
- //textures[texid_u]
- }''', GL_FRAGMENT_SHADER)
- position = glGetAttribLocation(
- shader, 'position'
- )
- texcoords = glGetAttribLocation(
- shader, 'texcoords'
- )
- texid = glGetAttribLocation(
- shader, 'texid'
- )
- avbo = vbo.VBO(
- numpy.array( [ #x, y, z ; texx, texy, texid -- pretty sure texture coords are -1 to 1...
- [ 0, 1, 0, 0, 1, 0 ],#top
- [ -1,-1, 0, -1,-1, 0 ],#botleft
- [ 1,-1, 0, 1,-1, 0 ],#botright
- [ 2,-1, 0, -1,-1, 1 ],#botleft
- [ 4,-1, 0, 1,-1, 1 ],#botright
- [ 4, 1, 0, 1,1, 1 ],#topright
- [ 2,-1, 0, -1,-1, 1 ],#botleft
- [ 4, 1, 0, 1,1, 1 ],#topright
- [ 2, 1, 0, -1,1, 1 ],#topleft
- ], 'f')
- )#a triangle and a square
- UNIFORM_LOCATIONS = { #set up some linkages!
- 'xpos': glGetUniformLocation( shader, 'xpos' ),
- 'ypos': glGetUniformLocation( shader, 'ypos' ),
- 'thetexture': glGetUniformLocation( shader, 'thetexture' ),
- }
- '''And then in the run:'''
- shaders.glUseProgram(shader)#bind the shader
- glUniform1f(UNIFORM_LOCATIONS['xpos'],xpos)
- glUniform1f(UNIFORM_LOCATIONS['ypos'],ypos)
- glUniform1i(UNIFORM_LOCATIONS['thetexture'],texture)
- try:
- avbo.bind()#bind the vertex object
- try:
- glEnableVertexAttribArray( position )
- glEnableVertexAttribArray( texcoords )
- glEnableVertexAttribArray( texid )
- #4 bytes per number, 6 numbers, so 4*6 bytes between the start of each record.
- stride = 6*4
- glVertexAttribPointer(
- position,
- 3, GL_FLOAT,False, stride, avbo
- )
- glVertexAttribPointer(
- texcoords,
- 2, GL_FLOAT,False, stride, avbo+12
- )
- glVertexAttribPointer(
- texid,
- 1, GL_INT,False, stride, avbo+20
- )
- glDrawArrays(GL_TRIANGLES, 0, 9)
- finally:
- avbo.unbind() #unbind the vertex objct
- glDisableVertexAttribArray( position )
- glDisableVertexAttribArray( texcoords )
- glDisableVertexAttribArray( texid )
- finally:
- shaders.glUseProgram( 0 )#unbind the shader
- ''' this compiles, but renders blank. '''
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement