White quads instead of textured quads

pkraft
Unregistered
 
Post: #1
Hi folks. This is my first post here.

I am using BlitzMax to create OpenGL programs. I am working on a program which should, simply, just load an image, upload it as a texture, then draw it to the display with texture mapping onto a quad.

On my humble G3 300Mhz ibook, which has software opengl only, the routine works fine and you see the textured quad on the screen.

However, I move to my G4 1GHz iMac,which has hardware accelerated opengl, and everything works except the texture disappears and is replaced with all white pixels.

Now, I read in another thread that this might be to do with the MIN and MAG filters not being set up when you aren't using mipmapping. I'm not using mipmapping so I have set up those both to GL_NEAREST. The problem still persists.

Is there some other thing that needs to be set or defined or something in order to make the texture show up?

Any insight or help greatly appreciated. You can see from the enclosed code the opengl calls mixed in with other BlitzMax commands, hopefully understandable. Note that comment lines or text begin with an apostrophe '''''''''

Code:
Strict

Local ballsize:Int=256 'based on 256x256 image
Local ballsizehalf:Int=ballsize Shr 1

AutoMidHandle True
Local px1:TPixmap=LoadPixmap("Ball09.png") '4 to 9
px1=ConvertPixmap(px1,PF_RGBA8888)

bglCreateContext(640,480,32,0,BGL_BACKBUFFER|BGL_ALPHABUFFER|BGL_FULLSCREEN)'|BG​L_STENCILBUFFER)
glViewport(0,0,640,480)
glMatrixMode (GL_PROJECTION)
glLoadIdentity
glOrtho(0,640,480,0,-1,1)
'gluOrtho2D(0,640,0,480)
glMatrixMode(GL_MODELVIEW)
glLoadIdentity
glClear(GL_COLOR_BUFFER_BIT)
bglSwapBuffers
glClear(GL_COLOR_BUFFER_BIT)
bglSwapBuffers
glDisable(GL_DEPTH_TEST)
glDisable(GL_STENCIL_TEST)
glDisable(GL_ALPHA_TEST)
glDisable(GL_SCISSOR_TEST)
glDisable(GL_CULL_FACE)
glDisable(GL_POLYGON_SMOOTH)
'glDisable(GL_LOGIC_OP)
glColorMask(GL_TRUE,GL_TRUE,GL_TRUE,GL_TRUE)
bglSetSwapInterval(0) 'no vbl sync
GLDisable(GL_DITHER)

glClearColor(0,0,0,0)
glColor4b($FF,$FF,$FF,$FF)
SeedRnd(MilliSecs())

'Create bank space to store a downloaded image
Local bnk:TBank=CreateBank(ballsize*ballsize) 'to store screen image
Local where:Byte Ptr=BankBuf(bnk)

'Give our image an alpha buffer
Local pxp:Byte Ptr=PixmapPixelPtr(px1,0,0)
Local pitch:Int=PixmapPitch(px1)
For Local yy:Int=0 To ballsize-1
    Local yloc:Int=yy*pitch
    For Local xx:Int=0 To ballsize-1
        pxp[yloc+(xx Shl 2)+3]=pxp[yloc+(xx Shl 2)] 'copy the red component into the image's alpha buffer
    Next
Next
'Pixmap now has equivalent data in alpha buffer

'Upload our pixmap as a texture
glDrawBuffer(GL_BACK)
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP_TO_EDGE)
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP_TO_EDGE)
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST)
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST)
glPixelStorei(GL_UNPACK_ALIGNMENT,4)
glPixelStorei(GL_UNPACK_ROW_LENGTH,PixmapPitch(px1)/4) '4 bytes per pixel RGB format
glPixelTransferf(GL_RED_SCALE,1.0)
glPixelTransferf(GL_RED_BIAS,0.0)
glPixelTransferf(GL_GREEN_SCALE,1.0)
glPixelTransferf(GL_GREEN_BIAS,0.0)
glPixelTransferf(GL_BLUE_SCALE,1.0)
glPixelTransferf(GL_BLUE_BIAS,0.0)
glPixelTransferf(GL_ALPHA_SCALE,1.0)
glPixelTransferf(GL_ALPHA_BIAS,0.0)
glPixelTransferi(GL_MAP_COLOR,GL_FALSE)
glPixelTransferi(GL_MAP_STENCIL,GL_FALSE)
glPixelStorei(GL_UNPACK_SWAP_BYTES,GL_FALSE)
glPixelStorei(GL_UNPACK_LSB_FIRST,GL_FALSE)
glPixelStorei(GL_UNPACK_SKIP_PIXELS,0)
glPixelStorei(GL_UNPACK_SKIP_ROWS,0)
Global name:Int=0
glGenTextures(1,VarPtr(name))
glBindTexture(GL_TEXTURE_2D,name)
glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,ballsize,ballsize,0,GL_RGBA,GL_UNSIGNED_BYT​E,Null) 'RGB=no alpha in pixmap!
glPixelStorei(GL_UNPACK_ROW_LENGTH,PixmapPitch(px1)/4) '4 bytes per pixel RGB format
glTexSubImage2D GL_TEXTURE_2D,0,0,0,ballsize,ballsize,GL_RGBA,GL_UNSIGNED_BYTE,PixmapPixelPtr(px​1,0,0)

Local objx:Int=Rand(0,619-ballsize)+10
Local objy:Int=Rand(0,459-ballsize)+10
Local objx2:Int=Rand(0,619-ballsize)+10
Local objy2:Int=Rand(0,459-ballsize)+10
Local xadd:Int=Rand(1,5)
Local yadd:Int=Rand(1,5)
Local xadd2:Int=Rand(1,5)
Local yadd2:Int=Rand(1,5)
Local spin:Int=0
Local spin2:Int=0
Repeat
    'Move objects
    If ballsize<620
        objx:+xadd; objx2:+xadd2
        If objx>630-ballsize Or objx<10
            xadd=-xadd
            objx:+xadd
        EndIf
        If objx2>630-ballsize Or objx2<10
            xadd2=-xadd2
            objx2:+xadd2
        EndIf
    EndIf
    If ballsize<460
        objy:+yadd; objy2:+yadd2
        If objy>470-ballsize Or objy<10
            yadd=-yadd
            objy:+yadd
        EndIf
        If objy2>470-ballsize Or objy2<10
            yadd2=-yadd2
            objy2:+yadd2
        EndIf
    EndIf

    glClear(GL_COLOR_BUFFER_BIT) 'cls
    'SetBlend LIGHTBLEND
    glEnable(GL_BLEND)
    glBlendFunc GL_SRC_ALPHA,GL_ONE 'lightblend
    'glBlendFunc GL_SRC_COLOR,GL_ONE_MINUS_SRC_COLOR
'    glColorMask(GL_FALSE,GL_FALSE,GL_FALSE,GL_TRUE) 'Draw in alpha only
    'spin=(spin+3) Mod 360
    'SetRotation spin
    'Draw texture
'    glColor4b($FF,$FF,$FF,$80)
    glEnable(GL_TEXTURE_2D)
    glShadeModel(GL_FLAT)'SMOOTH)
    glPolygonMode(GL_FRONT_AND_BACK,GL_FILL) 'face
    glBegin GL_QUADS
'        glTexCoord2f(0,0); glColor4b($FF,0,0,$80); glVertex2i(objx,objy)
'        glTexCoord2f(0,1); glColor4b($FF,$FF,$FF,$80); glVertex2i(objx,objy+ballsize)
'        glTexCoord2f(1,1); glColor4b($0,$0,$0,$80); glVertex2i(objx+ballsize,objy+ballsize)
'        glTexCoord2f(1,0); glColor4b($FF,$FF,$FF,$80); glVertex2i(objx+ballsize,objy)
        glTexCoord2f(0,0); glVertex2i(objx,objy)
        glTexCoord2f(0,1); glVertex2i(objx,objy+ballsize)
        glTexCoord2f(1,1); glVertex2i(objx+ballsize,objy+ballsize)
        glTexCoord2f(1,0); glVertex2i(objx+ballsize,objy)
    glEnd
    'DrawImage img1,objx+ballsizehalf,objy+ballsizehalf
    'SetRotation -spin
    glBegin GL_QUADS
'        glTexCoord2f(0,0); glColor4b(0,$FF,0,$80); glVertex2i(objx2,objy2)
'        glTexCoord2f(0,1); glColor4b($FF,$FF,$FF,$80); glVertex2i(objx2,objy2+ballsize)
'        glTexCoord2f(1,1); glColor4b($0,$0,$0,$80); glVertex2i(objx2+ballsize,objy2+ballsize)
'        glTexCoord2f(1,0); glColor4b($FF,$FF,$FF,$80); glVertex2i(objx2+ballsize,objy2)
        glTexCoord2f(0,0); glVertex2i(objx2,objy2)
        glTexCoord2f(0,1); glVertex2i(objx2,objy2+ballsize)
        glTexCoord2f(1,1); glVertex2i(objx2+ballsize,objy2+ballsize)
        glTexCoord2f(1,0); glVertex2i(objx2+ballsize,objy2)
    glEnd
    'DrawImage img1,objx2+ballsizehalf,objy2+ballsizehalf
    Local mx:Int=Int(MouseX())-ballsizehalf
    Local my:Int=Int(MouseY())-ballsizehalf
    glBegin GL_QUADS
'        glTexCoord2i(0,0); glColor4b(0,0,$FF,$40); glVertex2i(mx,my)
'        glTexCoord2i(0,1); glColor4b($FF,$FF,$FF,$40); glVertex2i(mx,my+ballsize)
'        glTexCoord2i(1,1); glColor4b($0,$0,$0,$40); glVertex2i(mx+ballsize,my+ballsize)
'        glTexCoord2i(1,0); glColor4b($FF,$FF,$FF,$40); glVertex2i(mx+ballsize,my)
        glTexCoord2f(0,0); glVertex2i(mx,my)
        glTexCoord2f(0,1); glVertex2i(mx,my+ballsize)
        glTexCoord2f(1,1); glVertex2i(mx+ballsize,my+ballsize)
        glTexCoord2f(1,0); glVertex2i(mx+ballsize,my)
    glEnd
    glDisable(GL_TEXTURE_2D)
    glDisable(GL_BLEND)
    'DrawImage img1,mx+ballsizehalf,my+ballsizehalf
    'SetRotation 0
    
    glColorMask(GL_TRUE,GL_TRUE,GL_TRUE,GL_TRUE)
    glPixelZoom(1.0,1.0) 'no zooming
    glPixelStorei(GL_PACK_ROW_LENGTH,ballsize) 'row length
    glPixelStorei(GL_PACK_ALIGNMENT,4) 'byte alignment
    glReadPixels(mx,my,ballsize,ballsize,GL_ALPHA,GL_UNSIGNED_BYTE,where) 'grab alpha into buffer
    glRasterPos2i 0,256'mx,my 'Set the position top-left to draw this object at
    glPixelStorei(GL_UNPACK_ROW_LENGTH,ballsize)
    glPixelStorei(GL_UNPACK_ALIGNMENT,4)
    glDrawPixels(ballsize,ballsize,GL_RED,GL_UNSIGNED_BYTE,where) 'Render alpha buffer into the stencil buffer
'    'GL_INDEX_SHIFT
'    'GL_INDEX_OFFSET
    
'    glEnable(GL_STENCIL_TEST) 'Test the stencil
'    glStencilFunc(GL_GEQUAL,140,$FF) 'Allow any pixels where the alpha is >=140
'    glEnable(GL_BLEND) 'Do blending
'    glBlendFunc(GL_SRC_ALPHA,GL_ZERO) 'Multiply source color by the alpha value, ignore dest
'    'glEnable(GL_ALPHA_TEST)
'    'glAlphaFunc(GL_GREATER,0.5)
'    'glEnable(GL_ALPHA_TEST)
'    'glAlphaFunc(GL_GREATER,0.5)

'    glColor3b($44,$FF,$88) 'What color to render
'    glColorMask True,True,True,False 'Draw in color components only, keep alpha for future operations
'    glRasterPos2i 0,my+ballsize 'Set the position top-left to draw this object at
'    glBegin GL_QUADS
'        glVertex2i(mx,my)
'        glVertex2i(mx,my+ballsize)
'        glVertex2i(mx+ballsize,my+ballsize)
'        glVertex2i(mx+ballsize,my)
'    glEnd
'    glDisable(GL_STENCIL_TEST)
'    glDisable(GL_BLEND)
    glFlush()

    'old stuff
    'glPixelMapusv(GL_PIXEL_MAP_R_TO_R,256,redmap)
    'glPixelMapusv(GL_PIXEL_MAP_G_TO_G,256,greenmap)
    'glPixelMapusv(GL_PIXEL_MAP_B_TO_B,256,bluemap)
    'glPixelZoom(1.0,1.0)
    'glPixelTransferi(GL_MAP_COLOR,GL_TRUE)
    'glPixelTransferf(GL_RED_SCALE,1.0)
    'glPixelTransferf(GL_RED_BIAS,0.0)
    'glPixelTransferf(GL_GREEN_SCALE,1.0)
    'glPixelTransferf(GL_GREEN_BIAS,0.0)
    'glPixelTransferf(GL_BLUE_SCALE,1.0)
    'glPixelTransferf(GL_BLUE_BIAS,0.0)
    'glRasterPos2i(0,480)
    'glDisable(GL_TEXTURE_2D)
    'glCopyPixels(0,0,640,480,GL_COLOR)
    'glEnable(GL_TEXTURE_2D)
    'glPixelTransferi(GL_MAP_COLOR,GL_FALSE)

    bglSwapBuffers
'    Repeat;Until KeyHit(KEY_SPACE)
Until KeyHit(KEY_ESCAPE)
End
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #2
glTexParameter only affects the currently-bound texture. You're calling it before you've bound your texture.
Quote this message in a reply
pkraft
Unregistered
 
Post: #3
Ok, sounds like a plan. I will try that this evening. Thankyou!
Quote this message in a reply
AngelDaniel
Unregistered
 
Post: #4
Thanks !!! This actually worked and removed the whole problem! Very cool.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Replacing edges with degenerate quads (for shadow volumes) Coyote 9 7,700 Jan 15, 2010 07:08 PM
Last Post: Coyote
  One texture... multiple quads? Jones 6 4,540 Jul 12, 2006 01:14 PM
Last Post: kordova
  Question about how textures are applied to quads which are scaled unevenly TomorrowPlusX 9 3,887 Feb 9, 2006 12:12 PM
Last Post: Chris Ball
  Nearly overlapping Quads causing Jagged Edges Lunatic 3 3,863 Oct 28, 2005 04:41 AM
Last Post: Lunatic
  glColor4f and glBlendFunc for fading to white? dave05 3 5,228 Jun 24, 2005 05:31 PM
Last Post: Skorche