eugenedakin wrote:
It looks like I can't seem to get the textures working. The textures for the skycube are oback6.raw, ofront6.raw, etc.
Got your code running and no textures either, but it does look OK to me: generate texture bank, store image data, bind to bank, draw with TexCoord. Not familiar with the use of .raw pictures and how you passed them into glTexImage2D; guess it works though because there's no complaining.
Here's a relatively minimal example that works for me. You may need to change the "OpenGL.framework" lib used. Once you have textures working a skybox is keeping the cube centered about the camera (can't tell if your example does this).
There are open source rb projects that do much more advanced texturing, half this code is snipped from such. I think some have skyboxes built in. A couple at hand...
http://www.jcquan.com/REALbasic/index.htmlhttp://forums.realsoftware.com/viewtopic.php?f=4&t=33569//*Start with OpenGLSurface1 sized and locked to window edges
//*and picture dragged into project and renamed "myPic"
//--------- window events
Sub Open()
genTexBank(0) //create bank for 1 texture (0 based)
storeImage(0, myPic) //put an image in the bank
OpenGLSurface1.Render //ready to draw
End Sub
Sub Resizing()
OpenGLSurface1.Render
End Sub
//-------- OpenGLSurface1 event
Function Render() As Boolean
initGLDrawing(me) //setup projection and clear buffers
OpenGL.glEnable(OpenGL.GL_TEXTURE_2D)
bindTo(0) //bind to image in first bank
OpenGL.glBegin(OpenGL.GL_QUADS) //draw quad
OpenGL.glTexCoord2f(1, 1)
OpenGL.glVertex3f(-1, -1, 0)
OpenGL.glTexCoord2f(1, 0)
OpenGL.glVertex3f(-1, 1, 0)
OpenGL.glTexCoord2f(0, 0)
OpenGL.glVertex3f( 1, 1, 0)
OpenGL.glTexCoord2f(0, 1)
OpenGL.glVertex3f( 1, -1, 0)
OpenGL.glEnd
End Function
//======================== texture helpers (window property and methods)
texNames(-1) As Integer //stores list of generated bank 'names'
Sub genTexBank(lastBankIdx As integer)
dim count As integer = lastBankIdx + 1
dim m As new MemoryBlock(count * 4) //array of 4 byte integers
OpenGL.glGenTextures(count, m) //retrieve ids
redim texNames(lastBankIdx) //scan values into easier to use int array
for i As integer = 0 to lastBankIdx
texNames(i) = m.Int32Value(i * 4)
next
End Sub
Sub storeImage(bankIdx As integer, p As Picture)
dim imgW As integer = p.Width
dim imgH As integer = p.Height
dim memImg As new MemoryBlock(imgW * imgH * 3)
dim surf As RGBSurface = p.RGBSurface
if surf = nil then //need a new pic with a surface
dim p2 As new Picture(imgW, imgH, 32)
p2.Graphics.DrawPicture p, 0, 0
p = p2 'repoint cause p2 goes out of scope, not necessary tho
surf = p.RGBSurface 'grab surf now, should be good
end
dim x, y, offset As integer 'scan surf into memoryblock
for y = 0 to imgH - 1
for x = 0 to imgW - 1
memImg.ColorValue(offset, 24) = surf.Pixel(x, y)
offset = offset + 3
next
next
OpenGL.glBindTexture(OpenGL.GL_TEXTURE_2D, texNames(bankIdx))
OpenGL.glTexParameteri(OpenGL.GL_TEXTURE_2D, OpenGL.GL_TEXTURE_WRAP_S, OpenGL.GL_REPEAT)
OpenGL.glTexParameteri(OpenGL.GL_TEXTURE_2D, OpenGL.GL_TEXTURE_WRAP_T, OpenGL.GL_REPEAT)
OpenGL.glTexParameteri(OpenGL.GL_TEXTURE_2D, OpenGL.GL_TEXTURE_MAG_FILTER, OpenGL.GL_LINEAR)'NEAREST)
OpenGL.glTexParameteri(OpenGL.GL_TEXTURE_2D, OpenGL.GL_TEXTURE_MIN_FILTER, OpenGL.GL_LINEAR)'GL_NEAREST)
OpenGL.glPixelStorei(OpenGL.GL_UNPACK_ALIGNMENT, 1)
OpenGL.glTexImage2D(OpenGL.GL_TEXTURE_2D, 0, OpenGL.GL_RGBA, imgW, imgH, 0, OpenGL.GL_BGR, OpenGL.GL_UNSIGNED_BYTE, memImg)
End Sub
Sub bindTo(bankIdx As integer)
OpenGL.glBindTexture(OpenGL.GL_TEXTURE_2D, texNames(bankIdx))
End Sub
//======================= setup drawing (window method)
Sub initGLDrawing(disp As OpenGLSurface)
//viewport
OpenGL.glViewport 0, 0, disp.Width, disp.Height
//projection transform (camera)
OpenGL.glMatrixMode(OpenGL.GL_PROJECTION)
OpenGL.glLoadIdentity
dim imageRatio As single = disp.Width / disp.Height //fix for fov in x
OpenGL.gluPerspective 55 / imageRatio, imageRatio, 0.1, 100
Soft Declare sub gluLookAt lib "OpenGL.framework" (eyeX as Double, eyeY as Double, eyeZ as Double, centerX as Double, centerY as Double, centerZ as Double, upX as Double, upY as Double, upZ as Double)
gluLookAt 2, 1.5, -5, 0, 0, 0, 0, 1, 0 //cam position, lookat point, up vector
//model transform
OpenGL.glMatrixMode(OpenGL.GL_MODELVIEW)
OpenGL.glLoadIdentity
//clear
OpenGL.glClearColor 1, 1, 0, 0 'yellow
OpenGL.glClear OpenGL.GL_COLOR_BUFFER_BIT + OpenGL.GL_DEPTH_BUFFER_BIT
OpenGL.glEnable OpenGL.GL_DEPTH_TEST
End Sub