After investigation, it's an error in your code: you affect DrawingBufferPixelFormat() to a '.b' variable which is wrong, as #PB_PixelFormat_ReversedY value is 32768. In a general rule you should not use .b/.w/.a/.u/.l outside of structure or array, as it brings no advantage, but you can truncate results very easily. Also the test to remove the flag should be "dbpixelFormat & ~#PB_PixelFormat_ReversedY" now. It correctly return "inversed" on Windows, and "not inversed" on Linux/OSX. Another note: to use the *buffer directly from DrawingBuffer(), StopDrawing() should not be called before the end of the use, as it does release it ! So it can work if you are lucky, but will fail or gives strange results/crash in other case.
Code: Select all
Global RollAxisX.f
Global RollAxisY.f
Global RollAxisZ.f
Global RotateSpeedX.f = 1.0
Global RotateSpeedY.f
Global RotateSpeedZ.f = 1.0
Global ZoomFactor.f = 1.0 ; Distance of the camera. Negative value = zoom back
#GL_BGR=$80E0
#GL_BGRA=$80E1
#GL_RGB=$1907
#GL_RGBA=$1908
Structure GLTexture
id.i
width.i
height.i
depth.i
inverted.b
*bytes ;data
EndStructure
; Procedure used to load OpenGL Textures
Declare LoadGLTexture(*tex.GLTexture)
Procedure LoadGlTexture(*tex.GLTexture)
UsePNGImageDecoder()
Protected image = LoadImage(#PB_Any, "shark.png")
Protected textureId.i
glEnable_(#GL_BLEND)
glGenTextures_(1, @textureId)
glBindTexture_(#GL_TEXTURE_2D, textureId)
; grab the pixel data into the buffer
StartDrawing(ImageOutput(image))
Protected *buffer = DrawingBuffer()
Protected widthInBytes = DrawingBufferPitch()
Protected dbpixelFormat = DrawingBufferPixelFormat()
Protected invertedY = dbpixelFormat & #PB_PixelFormat_ReversedY
Protected depth = dbpixelFormat & ~#PB_PixelFormat_ReversedY
Protected imgWidth.i = ImageWidth(image)
Protected imgHeight.i = ImageHeight(image)
Protected openGLDepth
Select depth
Case #PB_PixelFormat_8Bits
openGLDepth = #GL_RED
Case #PB_PixelFormat_24Bits_RGB
openGLDepth = #GL_RGB
Case #PB_PixelFormat_24Bits_BGR
openGLDepth = #GL_BGR
Case #PB_PixelFormat_32Bits_RGB
openGLDepth = #GL_RGBA
Case #PB_PixelFormat_32Bits_BGR
openGLDepth = #GL_BGRA
EndSelect
glTexParameteri_(#GL_TEXTURE_2D, #GL_TEXTURE_MIN_FILTER, #GL_LINEAR);
glTexParameteri_ (#GL_TEXTURE_2D, #GL_TEXTURE_MAG_FILTER, #GL_NEAREST);
glTexImage2D_ (#GL_TEXTURE_2D, 0, #GL_RGBA, imgWidth, imgHeight, 0, openGLDepth, #GL_UNSIGNED_BYTE, *buffer);
glDisable_(#GL_BLEND)
*tex\id = textureId
*tex\bytes = *buffer
*tex\width = imgWidth
*tex\height = imgHeight
StopDrawing()
If invertedY = #PB_PixelFormat_ReversedY
*tex\inverted = #True
Else
*tex\inverted = #False
EndIf
Debug *tex\inverted
FreeImage(image)
EndProcedure
OpenWindow(0, 0, 0, 530, 320, "OpenGL Gadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
OpenGLGadget(1, 0, 0, 530, 320)
glClearColor_(0.4, 0.6, 0.9, 1)
AddWindowTimer(0, 1, 16) ; about 60 fps
Global tex.GLTexture
LoadGLTexture(@tex)
Repeat
Event = WaitWindowEvent()
Select Event
Case #PB_Event_Timer
If EventTimer() = 1
SetGadgetAttribute(1, #PB_OpenGL_SetContext, #True)
glClear_(#GL_COLOR_BUFFER_BIT | #GL_DEPTH_BUFFER_BIT);
glMatrixMode_(#GL_PROJECTION);
glPushMatrix_() ;
glLoadIdentity_() ;
glOrtho_(0.0, 800, 0.0, 600, -1.0, 1.0);
glMatrixMode_(#GL_MODELVIEW) ;
glPushMatrix_() ;
glLoadIdentity_();
glDisable_(#GL_LIGHTING);
glBindTexture_(#GL_TEXTURE_2D, tex\id)
glEnable_(#GL_TEXTURE_2D)
glEnable_(#GL_BLEND)
glBlendFunc_(#GL_SRC_ALPHA, #GL_ONE_MINUS_SRC_ALPHA);
glBegin_(#GL_QUADS)
glTexCoord2f_(0.0, 0.0);
glVertex3f_( 0.0, 0.0, 0.0);
glTexCoord2f_(0.0, 1.0);
glVertex3f_( 0.0, 120, 0.0);
glTexCoord2f_(1.0, 1.0);
glVertex3f_( 60.2, 120.0, 0.0);
glTexCoord2f_(1.0, 0.0);
glVertex3f_( 60.2, 0.0, 0.0);
glEnd_()
glFinish_()
SetGadgetAttribute(1, #PB_OpenGL_FlipBuffers, #True)
EndIf
EndSelect
Until Event = #PB_Event_CloseWindow