Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Sub LoadCharacter(ByRef char As Character, filename As String)
- Dim myimg As Any Ptr
- Dim myimg_data As UInteger Ptr
- Dim i As UInteger
- Dim size As Integer
- 'Load texture & Set up texture to be used
- LoadBMP(filename, char.bmp_width, char.bmp_height, myimg, myimg_data)
- ImageInfo myimg, ,,,,,size
- For i = 0 To (size/4)
- If myimg_data[i] = &HFF00FF00 Then
- myimg_data[i] = myimg_data[i] And &H00FF0FF
- EndIf
- Next
- 'Enable blending
- glEnable(GL_BLEND)
- glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA)
- 'Enable textures
- glEnable(GL_TEXTURE_2D)
- 'Generate texture
- glGenTextures(1, @(char.textureObject))
- 'Bind texture object to texture
- glBindTexture(GL_TEXTURE_2D, char.textureObject)
- 'Set texture filtering
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)
- 'Set texture data
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, char.bmp_width, char.bmp_height, 0, GL_BGRA, GL_UNSIGNED_BYTE, myimg_data)
- glDisable(GL_BLEND)
- End Sub
- Sub DrawCharacter(ByRef char As Character)
- 'What needs to be done:
- 'Each character has one texture for it with multiple frames in that one texture.
- 'Pretty much think of characters as Sprites in 3D.
- 'To figure out the frame of the sprite (texture coordinates) you use (frame_width*(frame_number-1))/texture_width
- 'for the starting u-value, and (frame_width*frame_number)/texture_width for ending u-value; and then you use
- '(frame_height*(frame_number-1))/texture_height for starting v-value, and (frame_height*frame_number)/texture_height
- 'for ending v-value.
- 'Set up coords
- Dim west As Single = (char.cur_direction * 32) / char.bmp_width
- Dim east As Single = (((char.cur_direction+1) * 32)-1) / char.bmp_width
- Dim top As Single = (char.cur_frame * 32) / char.bmp_height
- Dim bottom As Single = (((char.cur_frame+1) * 32)-1) / char.bmp_height
- 'Enable blending
- glEnable(GL_BLEND)
- glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA)
- 'Bind texture to quad size of screen and draw.
- glBindTexture(GL_TEXTURE_2D, char.textureObject)
- glBegin(GL_QUADS)
- glTexCoord2f(west, top)
- glVertex3f(char.x_pos - 10, char.y_pos + 10, char.z_pos)
- glTexCoord2f(west, bottom)
- glVertex3f(char.x_pos - 10, char.y_pos - 10, char.z_pos)
- glTexCoord2f(east, bottom)
- glVertex3f(char.x_pos + 10, char.y_pos - 10, char.z_pos)
- glTexCoord2f(east, top)
- glVertex3f(char.x_pos + 10, char.y_pos + 10, char.z_pos)
- glEnd()
- End Sub
Add Comment
Please, Sign In to add comment