Post by 8XenoTrogdor8 on Dec 27, 2004 2:12:06 GMT -5
Apparently basic4gl can be used for much more than just fps games! To back that up, here is a program that can read and draw out a 24 bit bitmap file (.bmp). It stretches the file across the entire display area, so if you load a photo it might be a bit distorted. O well.
Questions/Comments always appreciated!
Dim ReadFile, FileName$
Dim Pixel_Data_Start, Image_Width, Image_Hieght
Dim Red#, Green#, Blue#
Dim X, Y
FileName$ = "--->Insert name of .bmp file here, I.e 'pixel.bmp'<---"
ReadFile = OpenFileRead ("files\"+ FileName$)
' Error messages given if the file wont work--
' 19778 is equivelant to BM. All bitmap files have BM at the start.
if not ReadWord (ReadFile) = 19778 then
Printr "Incorrect file type"
Printr "Please load a 24 bit bitmap image"
end
endif
Seek (ReadFile, 28)
' This is the number of bits per pixel. This program only loads 24 bit bitmaps.
if not ReadWord (ReadFile) = 24 then
Seek (ReadFile, 28)
Printr "Cannot render a " + ReadWord (ReadFile) + " bit bitmap file"
end
endif
' This is the compression of the bitmap. 0 = No compression.
if not ReadInt (ReadFile) = 0 then
Print "Cannot render compressed files"
end
endif
Seek (ReadFile, 10)
Pixel_Data_Start = ReadInt (ReadFile) ' Which byte the pixel data starts on.
Seek (ReadFile, 18)
Image_Width = ReadInt (ReadFile) ' Width of the bitmap.
Seek (ReadFile, 22)
Image_Hieght = ReadInt (ReadFile) ' Hieght of the bitmap.
glMatrixMode (GL_PROJECTION)
glLoadIdentity ()
glOrtho (0, Image_Width, 0, Image_Hieght, -1, 1)
Seek (ReadFile, Pixel_Data_Start)
for Y = 1 to Image_Hieght
for X = 1 to Image_Width
' The colors have to be backwards because a bitmap file stores
' all its pixel data backwards for some reason.
Green# = Val (ReadByte (ReadFile)) /255
Blue# = Val (ReadByte (ReadFile)) /255
Red# = Val (ReadByte (ReadFile)) /255
GlPushMatrix ()
GlTranslatef (X, Y, 0)
GlBegin (GL_QUADS)
GlColor3f (Red#, Blue#, Green#)
GlVertex2f (-1, -1)
GlVertex2f (0, -1)
GlVertex2f (0, 0)
GlVertex2f (-1, 0)
GlEnd ()
GlPopMatrix ()
next
next
CloseFile (ReadFile)
SwapBuffers ()
Questions/Comments always appreciated!