Guest User

Untitled

a guest
Jun 18th, 2018
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Sub LoadCharacter(ByRef char As Character, filename As String)
  2.     Dim myimg As Any Ptr
  3.     Dim myimg_data As UInteger Ptr
  4.     Dim i As UInteger
  5.     Dim size As Integer
  6.    
  7.     'Load texture & Set up texture to be used
  8.     LoadBMP(filename, char.bmp_width, char.bmp_height, myimg, myimg_data)
  9.     ImageInfo myimg, ,,,,,size
  10.    
  11.     For i = 0 To (size/4)
  12.         If myimg_data[i] = &HFF00FF00 Then
  13.             myimg_data[i] = myimg_data[i] And &H00FF0FF
  14.         EndIf
  15.     Next
  16.    
  17.         'Enable blending
  18.     glEnable(GL_BLEND)
  19.     glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA)
  20.    
  21.     'Enable textures
  22.     glEnable(GL_TEXTURE_2D)
  23.     'Generate texture
  24.     glGenTextures(1, @(char.textureObject))
  25.     'Bind texture object to texture
  26.     glBindTexture(GL_TEXTURE_2D, char.textureObject)
  27.     'Set texture filtering
  28.     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
  29.     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)
  30.     'Set texture data
  31.     glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, char.bmp_width, char.bmp_height, 0, GL_BGRA, GL_UNSIGNED_BYTE, myimg_data)
  32.    
  33.     glDisable(GL_BLEND)
  34. End Sub
  35.  
  36. Sub DrawCharacter(ByRef char As Character)
  37.     'What needs to be done:
  38.     'Each character has one texture for it with multiple frames in that one texture.
  39.     'Pretty much think of characters as Sprites in 3D.
  40.     'To figure out the frame of the sprite (texture coordinates) you use (frame_width*(frame_number-1))/texture_width
  41.     'for the starting u-value, and (frame_width*frame_number)/texture_width for ending u-value; and then you use
  42.     '(frame_height*(frame_number-1))/texture_height for starting v-value, and (frame_height*frame_number)/texture_height
  43.     'for ending v-value.
  44.    
  45.     'Set up coords
  46.     Dim west As Single = (char.cur_direction * 32) / char.bmp_width
  47.     Dim east As Single = (((char.cur_direction+1) * 32)-1) / char.bmp_width
  48.     Dim top As Single = (char.cur_frame * 32) / char.bmp_height
  49.     Dim bottom As Single = (((char.cur_frame+1) * 32)-1) / char.bmp_height
  50.    
  51.         'Enable blending
  52.     glEnable(GL_BLEND)
  53.     glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA)
  54.    
  55.     'Bind texture to quad size of screen and draw.
  56.     glBindTexture(GL_TEXTURE_2D, char.textureObject)
  57.    
  58.    
  59.     glBegin(GL_QUADS)
  60.         glTexCoord2f(west, top)
  61.         glVertex3f(char.x_pos - 10, char.y_pos + 10, char.z_pos)
  62.        
  63.         glTexCoord2f(west, bottom)
  64.         glVertex3f(char.x_pos - 10, char.y_pos - 10, char.z_pos)
  65.        
  66.         glTexCoord2f(east, bottom)
  67.         glVertex3f(char.x_pos + 10, char.y_pos - 10, char.z_pos)
  68.        
  69.         glTexCoord2f(east, top)
  70.         glVertex3f(char.x_pos + 10, char.y_pos + 10, char.z_pos)
  71.     glEnd()
  72.    
  73. End Sub
  74.  
  75. Sub LoadBMP(filename As String, ByRef w As Integer, ByRef h As Integer, img As Any Ptr, ByRef imgdata As UInteger Ptr)
  76.     Dim filenum As Integer
  77.     filenum = FreeFile()
  78.     Open filename For Binary Access Read As #filenum
  79.     Get #filenum, 19, w ' width from file
  80.     Get #filenum, 23, h ' height from file
  81.     h = Abs(h)
  82.     Close #filenum
  83.     img = ImageCreate(w, h)
  84.     BLoad filename, img
  85.     ImageInfo(img,,,,,imgdata)
  86. End Sub
Add Comment
Please, Sign In to add comment