fb:porticula NoPaste
openGL-Test
Uploader: | csde_rats |
Datum/Zeit: | 06.07.2007 21:32:00 |
' Einbindung von OpenGL
#include once "GL/gl.bi"
#include once "GL/glu.bi"
#include once "2d_opengl.bi"
' Includes
#include "inc/freeimage.bi"
#include "inc/crt.bi"
declare function openGL_init(scrnX as integer, scrnY as integer, depth as integer, fullscreen as integer) as integer ' Initialisiert openGL
declare FUNCTION CreateTexture( BYVAL buffer AS ANY PTR, BYVAL flags AS INTEGER = 0 ) AS GLuint
openGL_init(1024,768,32,&H00)
dim filename as string
' Erstmal eine neue openGL-Textur definieren
DIM picture AS GLUInt
' Und auch einen fürs JPEG
dim jpeg as any ptr
' Wird Refresh benötigt?
dim reload as ubyte = 1
do
' *****************************************
' *Beginn der eigentlichen openGL-Schleife*
' *****************************************
glClear GL_COLOR_BUFFER_BIT OR GL_DEPTH_BUFFER_BIT
' Eigentliche Zeichen, und skalier-Befehle
if reload then
' Führende Nullen einfügen
Filename = "temp.bmp"
jpeg = Imagecreate(1024,1024,RGB(255,0,0))
BLOAD "test.bmp",jpeg
' Gibt uns einen GFXType auf die geladene Tex zurück
picture = CreateTexture(jpeg, TEX_NOFILTER)
end if
' Skaliert die Tex
glscalef (1024/2048), (768/1536), 1
gltranslatef 0,0,0
glBindTexture GL_TEXTURE_2D, picture ' Texture binden
'glColor4f 1,1,1,1
glTranslatef 0,0,0 ' z = 0
glBegin GL_QUADS
glTexCoord2f 0, 0
glVertex2i 0,786 '' LINKS UNTEN (1. Koordinate)
glTexCoord2f 1, 0
glVertex2i 1024, 768 '' RECHTS UNTEN (2. Koordinate)
glTexCoord2f 1, 1
glVertex2i 1024, 0 '' RECHTS OBEN (3. Koordinate)
glTexCoord2f 0, 1
glVertex2i 0, 0 '' LINKS OBEN (4. Koordinate)
glEnd
glLoadIdentity
glBindTexture GL_TEXTURE_2D, 0 ' Texture freigeben
' Alles Abarbeiten
glFlush ' Verarbeitung der Befehle
flip
screensync
reload = 0 ' reload wird nach einem Frame nicht gebraucht
loop
FUNCTION CreateTexture( BYVAL buffer AS ANY PTR, BYVAL flags AS INTEGER = 0 ) AS GLuint
REDIM dat(0) AS UINTEGER
DIM p AS UINTEGER PTR, s AS USHORT PTR
DIM AS INTEGER w, h, x, y
DIM AS UINTEGER col
DIM tex AS GLuint
DIM AS GLenum format, minfilter, magfilter
CreateTexture = 0
s = buffer
w = cptr(Uinteger Ptr, buffer)[2]
h = cptr(Uinteger Ptr, buffer)[3]
IF( (w AND (w-1)) OR (h AND (h-1)) ) THEN
'' Width/height not powers of 2
EXIT FUNCTION
END IF
REDIM dat(w * h * 4) AS UINTEGER
p = @dat(0)
glGenTextures 1, @tex
glBindTexture GL_TEXTURE_2D, tex
FOR y = h-1 TO 0 STEP -1
FOR x = 0 TO w-1
col = POINT(x, y, buffer)
'' Swap R and B so we can use the GL_RGBA texture format
col = RGBA(col AND &hFF, _
(col SHR 8) AND &hFF, _
(col SHR 16) AND &hFF, _
col SHR 24)
IF( flags AND TEX_HASALPHA ) THEN
*p = col
ELSE
IF( (flags AND TEX_MASKED) AND _
(col = &hFF00FF) ) THEN
*p = 0
ELSE
*p = col OR &hFF000000
END IF
END IF
p += 1
NEXT x
NEXT y
IF( flags AND ( TEX_MASKED OR TEX_HASALPHA ) ) THEN
format = GL_RGBA
ELSE
format = GL_RGB
END IF
IF( flags AND TEX_NOFILTER ) THEN
magfilter = GL_NEAREST
ELSE
magfilter = GL_LINEAR
END IF
IF( flags AND TEX_MIPMAP ) THEN
gluBuild2DMipmaps GL_TEXTURE_2D, format, w, h, GL_RGBA, _
GL_UNSIGNED_BYTE, @dat(0)
IF( flags AND TEX_NOFILTER ) THEN
minfilter = GL_NEAREST_MIPMAP_NEAREST
ELSE
minfilter = GL_LINEAR_MIPMAP_LINEAR
END IF
ELSE
glTexImage2D GL_TEXTURE_2D, 0, format, w, h, 0, GL_RGBA, _
GL_UNSIGNED_BYTE, @dat(0)
minfilter = magfilter
END IF
glTexParameteri GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, minfilter
glTexParameteri GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, magfilter
CreateTexture = tex
END FUNCTION
function openGL_init(scrnX as integer, scrnY as integer, depth as integer, fullscreen as integer) as integer ' Initialisiert openGL
'
screenres scrnX,scrnY,depth,,&H02 or fullscreen
glClear GL_COLOR_BUFFER_BIT OR GL_DEPTH_BUFFER_BIT
glflush
flip
screensync
' Konfiguration von OpenGL
glMatrixMode(GL_PROJECTION) ' Matrix definieren
glLoadIdentity
glViewport(0,0,scrnX,scrnY) ' Achse festlegen
glOrtho(0,scrnX,scrnY,0,-128,128)
glMatrixMode(GL_MODELVIEW) ' Deaktivierung des Rendern der Rückseiten
glEnable(GL_CULL_FACE)
glCullFace(GL_BACK)
glEnable GL_TEXTURE_2D ' Texturen aktivieren
glLoadIdentity
glEnable(GL_DEPTH_TEST) ' Tiefentest
glDepthFunc(GL_LESS)
glEnable(GL_ALPHA_TEST) ' Alphatest
glAlphaFunc(GL_GREATER, 0.1)
glClear GL_COLOR_BUFFER_BIT OR GL_DEPTH_BUFFER_BIT
glflush
flip
screensync
' Wenn alles geklappt hat: 1 Zurückgeben
return 1
end function