Last active
April 10, 2021 18:43
-
-
Save Hezkore/4e458baf4dce333acbe562bde94af663 to your computer and use it in GitHub Desktop.
Image buffer for BlitzMax
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Type TImageBuffer | |
Field rb:Int[1] | |
Field fb:Byte[1] | |
Field origX:Int, OrigY:Int | |
Field origW:Int, OrigH:Int | |
Field width:Int, height:Int | |
Field glTextureId:Int | |
Method Create:TImageBuffer( image:TImage, frameNo:Int = 0 ) | |
_initBuffer( image.width, image.height, TGLImageFrame( Image.frame( frameNo ) ).name ) | |
Return Self | |
EndMethod | |
Method _initBuffer( width:Int, height:Int, glTextureId:Int ) | |
Self.width = width | |
Self.height = height | |
Self.glTextureId = glTextureId | |
_generateFBO() | |
EndMethod | |
Method _generateFBO() | |
Local w:Int = width | |
Local h:Int = height | |
AdjustTexSize( W , H ) | |
glGenFramebuffersEXT( 1, fb ) | |
glGenRenderbuffersEXT( 1 , rb ) | |
glBindTexture( GL_TEXTURE_2D, glTextureId ) | |
glBindFramebufferEXT( GL_FRAMEBUFFER_EXT , fb[0] ) | |
glFramebufferTexture2DEXT( GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, glTextureId, 0 ) | |
glBindRenderbufferEXT( GL_RENDERBUFFER_EXT, rb[0] ) | |
glRenderbufferStorageEXT( GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT24, W, H ) | |
glFramebufferRenderbufferEXT( GL_FRAMEBUFFER_EXT , GL_DEPTH_ATTACHMENT_EXT , GL_RENDERBUFFER_EXT , rb[0] ) | |
Local status:Int = glCheckFramebufferStatusEXT( GL_FRAMEBUFFER_EXT ) | |
Select status | |
Case GL_FRAMEBUFFER_COMPLETE_EXT | |
Print( "OK" + " : " + Status ) | |
Case GL_FRAMEBUFFER_UNSUPPORTED_EXT | |
Print( "GL Framebuffer Unsupported - choose different formats" ) | |
Default | |
End | |
EndSelect | |
EndMethod | |
Method Bind() | |
GetViewport( OrigX, OrigY, OrigW, OrigH ) | |
glBindFramebufferEXT( GL_FRAMEBUFFER_EXT , fb[0] ) | |
glMatrixMode( GL_PROJECTION ) | |
glLoadIdentity() | |
glOrtho( 0, width, 0, width, -1, 1 ) | |
glMatrixMode( GL_MODELVIEW ) | |
glViewport( 0, 0, width, height ) | |
glScissor( 0, 0, width, height ) | |
EndMethod | |
Method Unbind() | |
glBindFramebufferEXT( GL_FRAMEBUFFER_EXT , 0 ) | |
glMatrixMode( GL_PROJECTION ) | |
glLoadIdentity() | |
glOrtho( 0, OrigW, Origh, 0, -1, 1 ) | |
glMatrixMode( GL_MODELVIEW ) | |
glViewport( 0, 0, OrigW, OrigH ) | |
glScissor( 0, 0, OrigW, OrigH ) | |
EndMethod | |
EndType |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment