OpenGL & Textures
Posted: Tue Apr 20, 2010 1:00 pm
This is a weird one 
The textures just aren't loading. Everything *appears* to be working (no error reported, all the values are getting the correct values, etc). In fact, on my Netbook, which has an Intel chipset, it IS working as I expected it to. When I go to my NVidia machine, the textures just don't load and I get a white square, or on my works ATI machine... the square disappears.
Everything is reporting as just fine, but it just isn't. I've added in a "CreateImage" so you can see what the texture is that is being generated - just adjust the OUTPUT_TEXTURE_FILENAME$ to your requirements.
Just disable the GenerateTexture() and you will see the white square, enable it and... well, I don't know what is happening!
Help!
*** edit : I love Fred.
The textures just aren't loading. Everything *appears* to be working (no error reported, all the values are getting the correct values, etc). In fact, on my Netbook, which has an Intel chipset, it IS working as I expected it to. When I go to my NVidia machine, the textures just don't load and I get a white square, or on my works ATI machine... the square disappears.
Everything is reporting as just fine, but it just isn't. I've added in a "CreateImage" so you can see what the texture is that is being generated - just adjust the OUTPUT_TEXTURE_FILENAME$ to your requirements.
Just disable the GenerateTexture() and you will see the white square, enable it and... well, I don't know what is happening!
Help!
*** edit : I love Fred.
Code: Select all
#OUTPUT_TEXTURE_FILENAME$ = "output check.bmp"
Global WallTexture
;{--- OpenGL Setup
CompilerIf Subsystem("OpenGL")
CompilerElse
MessageRequester("ERROR", "Set the subsystem To OpenGL")
End
CompilerEndIf
; pb workaround fix
Import ""
PB_Screen_Target
EndImport
#GL_TEXTURE_RECTANGLE_ARB = $84F5
;----------------------------
#GL_BLEND = $0BE2
#GL_COLOR_BUFFER_BIT = $00004000
#GL_DEPTH_BUFFER_BIT = $00000100
#GL_DEPTH_TEST = $0B71
#GL_LEQUAL = $0203
#GL_LINEAR = $2601
#GL_LINEAR_MIPMAP_NEAREST = $2701
#GL_LUMINANCE = $1909
#GL_MODELVIEW = $1700
#GL_MODULATE = $2100
#GL_NICEST = $1102
#GL_PERSPECTIVE_CORRECTION_HINT = $0C50
#GL_PROJECTION = $1701
#GL_QUADS = $0007
#GL_SMOOTH = $1D01
#GL_TEXTURE_2D = $0DE1
#GL_TEXTURE_ENV = $2300
#GL_TEXTURE_ENV_MODE = $2200
#GL_TEXTURE_MAG_FILTER = $2800
#GL_TEXTURE_MIN_FILTER = $2801
#GL_TEXTURE_WRAP_S = $2802
#GL_TEXTURE_WRAP_T = $2803
#GL_TRUE = 1
#GL_UNSIGNED_BYTE = $1401
#GL_SRC_ALPHA = $0302
#GL_ONE = 1
#GL_UNPACK_ALIGNMENT = $0CF5
CompilerIf #PB_Compiler_OS = #PB_OS_Linux
ImportC "/usr/lib/libX11.a"+Chr('"')+" -l"+Chr('"')+"GL"
CompilerElse
Import "Opengl32.lib"
CompilerEndIf
glBegin(a.l)
glBindTexture(a.l,b.l)
glClear(a.l)
glClearColor(a.f,b.f,c.f,d.f)
glClearDepth(a.d)
glDepthFunc(a.l)
glDepthMask(a.c)
glDisable(a.l)
glEnable(a.l)
glEnd()
glGenTextures(a.l,b.l)
glGetError()
glHint(a.l,b.l)
glLoadIdentity()
glMatrixMode(a.l)
glShadeModel(a.l)
glTexCoord2f(a.f,b.f)
glTexEnvf(a.l,b.l,c.f)
glTexParameterf(a.l,b.l,c.f)
glTranslatef(a.f,b.f,c.f)
glVertex3f(a.f,b.f,c.f)
glViewport(a.l,b.l,c.l,d.l)
glBlendFunc(a.l,b.l) ; As "glBlendFunc@8"
glPixelStorei(a.l,b.l) ; As "glPixelStorei@8"
EndImport
CompilerIf #PB_Compiler_OS = #PB_OS_Linux
ImportC "/usr/lib/libGLU.a"
CompilerElse
Import "Glu32.lib"
CompilerEndIf
gluBuild2DMipmaps(a.l,b.l,c.l,d.l,e.l,f.l,g.l)
gluErrorString(a.l)
gluPerspective(a.d,b.d,c.d,d.d)
EndImport
;}
Procedure Noise(x, y)
Static salt = 0
salt = salt ! x & y
ProcedureReturn salt
EndProcedure
Procedure.i GenerateTexture(pWidth.i, pHeight.i)
Protected img = CreateImage(#PB_Any, pWidth, pHeight, 32)
Protected *mem = AllocateMemory(pWidth * pHeight)
If Not *mem : ProcedureReturn 0 : EndIf
StartDrawing(ImageOutput(img))
Protected *buffer.Ascii = *mem
For y = 0 To pHeight-1
For x = 0 To pWidth-1
n = Noise(x, y) * 4
If n < 0 : n = 0 : EndIf
If n > 255 : n = 255 : EndIf
Plot(x, y, RGBA(n, n, n, 255))
*buffer\a = n
*buffer + 1
Next
Next
StopDrawing()
SaveImage(img, #OUTPUT_TEXTURE_FILENAME$)
Protected TexID = 0
glGenTextures(1, @TexID)
glBindTexture(#GL_TEXTURE_2D, TexID)
glTexEnvf(#GL_TEXTURE_ENV, #GL_TEXTURE_ENV_MODE, #GL_MODULATE )
; when texture area is small, bilinear filter the closest mipmap
glTexParameterf(#GL_TEXTURE_2D, #GL_TEXTURE_MIN_FILTER, #GL_LINEAR_MIPMAP_NEAREST );
; when texture area is large, bilinear filter the original
glTexParameterf(#GL_TEXTURE_2D, #GL_TEXTURE_MAG_FILTER, #GL_LINEAR );
rv = gluBuild2DMipmaps(#GL_TEXTURE_2D, 1, pWidth, pHeight, #GL_LUMINANCE, #GL_UNSIGNED_BYTE, *mem)
FreeMemory(*mem)
If rv <> 0
Debug PeekS(gluErrorString(rv))
;glDeleteTextures(1, @*Image\TexID)
ProcedureReturn 0
EndIf
ProcedureReturn TexID
EndProcedure
Procedure InitGL()
glClearColor(0.0, 0.0, 0.0, 0.0)
glEnable(#GL_TEXTURE_2D)
glEnable(#GL_BLEND)
glBlendFunc(#GL_SRC_ALPHA, #GL_ONE);
glPixelStorei(#GL_UNPACK_ALIGNMENT, 1);
glShadeModel(#GL_SMOOTH)
glClearDepth(1.0)
glEnable(#GL_DEPTH_TEST)
glDepthMask(#GL_TRUE);
glDepthFunc(#GL_LEQUAL)
glHint(#GL_PERSPECTIVE_CORRECTION_HINT, #GL_NICEST)
EndProcedure
Procedure ResizeScene(width, height)
If height < 1 : height = 1 : EndIf
If width < 1 : width = 1 : EndIf
glViewport(0, 0, width, height)
glMatrixMode(#GL_PROJECTION)
glLoadIdentity()
gluPerspective(45, width / height, 0.1, 1000)
glMatrixMode(#GL_MODELVIEW)
glLoadIdentity()
EndProcedure
Procedure DrawScene()
glEnable(#GL_TEXTURE_2D)
glClear(#GL_COLOR_BUFFER_BIT | #GL_DEPTH_BUFFER_BIT)
glLoadIdentity()
glTranslatef(0, 0, -5)
glBindTexture(#GL_TEXTURE_2D, WallTexture)
glBegin(#GL_QUADS);
glTexCoord2f(0.0, 0.0);
glVertex3f(0.0, 0.0, 1.0); // Bottom Left Of The Texture and Quad
glTexCoord2f(1.0, 0.0);
glVertex3f( 1.0, 0.0, 1.0); // Bottom Right Of The Texture and Quad
glTexCoord2f(1.0, 1.0);
glVertex3f( 1.0, 1.0, 1.0); // Top Right Of The Texture and Quad
glTexCoord2f(0.0, 1.0);
glVertex3f(0.0, 1.0, 1.0); // Top Left Of The Texture and Quad
glEnd( );
EndProcedure
InitSprite() : InitKeyboard()
OpenWindow (0, 100, 100, 512, 512, "OpenGL Window")
OpenWindowedScreen(WindowID(0), 0, 0, 512, 512, 0, 0, 0, #PB_Screen_WaitSynchronization)
glDisable(#GL_TEXTURE_RECTANGLE_ARB)
PB_Screen_Target = #GL_TEXTURE_2D
; load textures
#width = 64
#height = 64
WallTexture = GenerateTexture(#width, #height)
InitGL()
Repeat
Select WindowEvent()
Case #PB_Event_CloseWindow
Break
EndSelect
ExamineKeyboard()
If KeyboardReleased(#PB_Key_Escape)
Break
EndIf
DrawScene()
FlipBuffers()
ResizeScene(WindowWidth(0), WindowHeight(0))
Repeat
glError = glGetError()
Select glError
Case 0
Break
Default
Debug PeekS(gluErrorString(glError))
EndSelect
ForEver
ForEver