[Gambas-devel] news about opengl componant ...
Laurent Carlier
lordheavy at ...141...
Thu Nov 24 23:42:21 CET 2005
The opengl componant have started on a new base. It will be more compliant to
"official" opengl standard. So opengl coding should be easier.
I hope to have a full opengl 1.1 near the new year :)
Following is various screenshots from tutorials (nehe and others) and an
exemple of piece of c code and gambas code from gloweffect.
I guess (and hope !) that you will find all these stuff with the next unstable
release.
Contact me if you want to "alpha test" the current code ;)
Comments and criticisms are welcome !
Regards,
--
jabber : lordheavy at ...298...
mail : lordheavym at ...394...
-------------- next part --------------
A non-text attachment was scrubbed...
Name: gloweffect.png
Type: image/png
Size: 60031 bytes
Desc: not available
URL: <http://lists.gambas-basic.org/pipermail/devel/attachments/20051124/b9dfc512/attachment.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: nehetuto08.png
Type: image/png
Size: 222855 bytes
Desc: not available
URL: <http://lists.gambas-basic.org/pipermail/devel/attachments/20051124/b9dfc512/attachment-0001.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: gloweffect.cpp
Type: text/x-c++src
Size: 14030 bytes
Desc: not available
URL: <http://lists.gambas-basic.org/pipermail/devel/attachments/20051124/b9dfc512/attachment.cpp>
-------------- next part --------------
' Gambas module file
PRIVATE Textures AS Integer[]
PRIVATE UVdecal AS Float
PRIVATE Rot AS Float
PRIVATE Frames AS Integer
PRIVATE CTime AS Float
PUBLIC SUB Main()
Screen.Show(512, 512, 16)
Screen_resize()
initGL()
loadTextures()
Ctime = Timer()
END
PUBLIC SUB Screen_resize()
' Width/Height Ratio
DIM ratio AS Float
DIM Height AS Integer
Height = Screen.H
' Protect against a divide by zero
IF Height = 0 THEN Height = 1
ratio = Screen.W / Height
' Setup our viewport
Gl.Viewport(0, 0, Screen.Width, Screen.Height)
' change to the projection matrix AND set our viewing volume.
Gl.MatrixMode(glconst.Projection)
Gl.LoadIdentity()
' Set our perspective
Glu.Perspective(45.0, ratio, 1, 500.0)
' Make sure we're changing the model view and not the projection
Gl.MatrixMode(glconst.Modelview)
GL.LoadIdentity()
END
PUBLIC SUB Screen_refresh()
DIM calc AS Float
Gl.Clear(Glconst.ColorBufferBit OR Glconst.DepthBufferBit)
Gl.LoadIdentity()
Glu.LookAt(75, 75, 75, 0, 0, 0, 0, 1, 0)
RenderTotexture()
RenderGlow(20)
INC (Frames)
IF (Timer() > CTime + 5) THEN
calc = Timer() - CTime
PRINT CStr(Frames) & " frames in " & Format$(calc, "#.0") & " seconds = " & Format$((Frames / calc), "######.000") & " FPS"
Frames = 0
CTime = Timer()
ENDIF
END
PUBLIC SUB Screen_keyPressed()
IF key.Code = keyCode.F1 THEN Screen.Fullscreen = NOT Screen.Fullscreen
IF key.Code = keyCode.Esc THEN Screen.Close()
END
PUBLIC SUB initGL()
Gl.ShadeModel(Glconst.Smooth)
Gl.ClearColor(0.0, 0.0, 0.0, 0.5)
Gl.ClearDepth(1.0)
Gl.Enable(Glconst.DepthTest)
Gl.DepthFunc(Glconst.LEqual)
Gl.Hint(Glconst.PersperctiveCorrectionHint, Glconst.Nicest)
END
PUBLIC SUB loadTextures()
DIM tempSurface AS NEW Surface
Textures = Gl.GenTextures(2)
Gl.Enable(Glconst.Texture2d)
tempSurface.Load("GCN.png")
Gl.BindTexture(Glconst.Texture2d, textures[0])
Gl.TexImage2D(Glconst.Texture2d, 0, 3, tempSurface.W, tempSurface.h, 0, Glconst.rgb, Glconst.UnsignedByte, tempSurface.Pixels)
Gl.TexParameteri(Glconst.Texture2d, Glconst.TextureMinFilter, Glconst.Linear)
Gl.TexParameteri(Glconst.Texture2d, Glconst.TextureMagFilter, Glconst.Linear)
tempSurface = NEW Surface(512, 512, 32) ' 32 -> 4 bytes per pixel !
Gl.BindTexture(Glconst.Texture2d, textures[1])
Gl.TexImage2D(Glconst.Texture2d, 0, 4, tempSurface.W, tempSurface.h, 0, Glconst.rgba, Glconst.UnsignedByte, tempSurface.Pixels)
Gl.TexParameteri(Glconst.Texture2d, Glconst.TextureMinFilter, Glconst.Linear)
Gl.TexParameteri(Glconst.Texture2d, Glconst.TextureMagFilter, Glconst.Linear)
Gl.Disable(Glconst.Texture2d)
END
PUBLIC SUB RenderCube()
Gl.PushMatrix()
Gl.Rotatef(Rot, 1, 1, 0)
Gl.Scalef(10, 10, 10)
Gl.BindTexture(Glconst.Texture2d, textures[0])
Gl.Begin(Glconst.Quads)
' FACE 1
Gl.Color4f(0, 1, 1, 1)
Gl.TexCoord2f(1, 1)
Gl.Vertex3i(1, 1, 1)
Gl.Color4f(1, 0, 1, 1)
Gl.TexCoord2f(1, 0)
Gl.Vertex3i(1, -1, 1)
Gl.Color4f(1, 1, 0, 1)
Gl.TexCoord2f(0, 0)
Gl.Vertex3i(-1, -1, 1)
Gl.Color4f(1, 0, 1, 1)
Gl.TexCoord2f(0, 1)
Gl.Vertex3i(-1, 1, 1)
' FACE 2
Gl.Color4f(0, 1, 1, 1)
Gl.TexCoord2f(0, 0)
Gl.Vertex3i(1, 1, -1)
Gl.Color4f(1, 0, 1, 1)
Gl.TexCoord2f(1, 0)
Gl.Vertex3i(1, -1, -1)
Gl.Color4f(1, 1, 0, 1)
Gl.TexCoord2f(1, 1)
Gl.Vertex3i(-1, -1, -1)
Gl.Color4f(1, 0, 1, 1)
Gl.TexCoord2f(0, 1)
Gl.Vertex3i(-1, 1, -1)
' FACE 3
Gl.Color4f(0, 1, 1, 1)
Gl.TexCoord2f(0, 0)
Gl.Vertex3i(1, 1, 1)
Gl.Color4f(1, 0, 1, 1)
Gl.TexCoord2f(1, 0)
Gl.Vertex3i(1, -1, 1)
Gl.Color4f(1, 1, 0, 1)
Gl.TexCoord2f(1, 1)
Gl.Vertex3i(1, -1, -1)
Gl.Color4f(1, 0, 1, 1)
Gl.TexCoord2f(0, 1)
Gl.Vertex3i(1, 1, -1)
' FACE 4
Gl.Color4f(0, 1, 1, 1)
Gl.TexCoord2f(0, 0)
Gl.Vertex3i(-1, 1, 1)
Gl.Color4f(1, 0, 1, 1)
Gl.TexCoord2f(0, 1)
Gl.Vertex3i(-1, -1, 1)
Gl.Color4f(1, 1, 0, 1)
Gl.TexCoord2f(1, 1)
Gl.Vertex3i(-1, -1, -1)
Gl.Color4f(1, 0, 1, 1)
Gl.TexCoord2f(1, 0)
Gl.Vertex3i(-1, 1, -1)
' FACE 5
Gl.Color4f(0, 1, 1, 1)
Gl.TexCoord2f(0, 0)
Gl.Vertex3i(-1, 1, -1)
Gl.Color4f(1, 0, 1, 1)
Gl.TexCoord2f(1, 0)
Gl.Vertex3i(-1, 1, 1)
Gl.Color4f(1, 1, 0, 1)
Gl.TexCoord2f(1, 1)
Gl.Vertex3i(1, 1, 1)
Gl.Color4f(1, 0, 1, 1)
Gl.TexCoord2f(0, 1)
Gl.Vertex3i(1, 1, -1)
' FACE 6
Gl.Color4f(0, 1, 1, 1)
Gl.TexCoord2f(0, 0)
Gl.Vertex3i(-1, -1, -1)
Gl.Color4f(1, 0, 1, 1)
Gl.TexCoord2f(1, 0)
Gl.Vertex3i(-1, -1, 1)
Gl.Color4f(1, 1, 0, 1)
Gl.TexCoord2f(1, 1)
Gl.Vertex3i(1, -1, 1)
Gl.Color4f(1, 0, 1, 1)
Gl.TexCoord2f(0, 1)
Gl.Vertex3i(1, -1, -1)
Gl.End()
Gl.PopMatrix()
Rot += 1
END
PUBLIC SUB RenderToTexture()
Gl.Enable(Glconst.Texture2d)
RenderCube()
Gl.BindTexture(Glconst.Texture2d, textures[1])
Gl.CopyTexImage2D(Glconst.Texture2d, 0, Glconst.Rgb, 0, 0, 512, 512, 0)
Gl.ClearColor(0, 0, 0, 0)
Gl.Clear(Glconst.ColorBufferBit OR Glconst.DepthBufferBit)
Gl.Disable(Glconst.Texture2d)
END
PUBLIC SUB RenderGlow(count AS Integer)
DIM i AS Float
' ViewOrtho
Gl.MatrixMode(Glconst.Projection)
Gl.PushMatrix()
Gl.LoadIdentity()
Gl.Ortho(0, 512, 0, 512, -1, 1)
Gl.MatrixMode(Glconst.Modelview)
Gl.PushMatrix()
Gl.LoadIdentity()
Gl.Enable(Glconst.Texture2d)
Gl.BindTexture(Glconst.Texture2d, textures[1])
Gl.Enable(Glconst.Blend)
Gl.BlendFunc(Glconst.SrcAlpha, Glconst.OneMinusSrcAlpha)
Gl.Begin(Glconst.Quads)
WHILE (i < count)
i += 1
Gl.Color4f(1, 1, 1, 0.3 / i)
Gl.TexCoord2f(0 + (i / 75), (i / 75))
Gl.Vertex2f(0, 0)
Gl.TexCoord2f((i / 75), 1 - (i / 75))
Gl.Vertex2f(0, 512)
Gl.TexCoord2f(1 - (i / 75), 1 - (i / 75))
Gl.Vertex2f(512, 512)
Gl.TexCoord2f(1 - (i / 75), (i / 75))
Gl.Vertex2f(512, 0)
WEND
Gl.End()
' ViewPerspective
Gl.MatrixMode(Glconst.Projection)
Gl.PopMatrix()
Gl.MatrixMode(Glconst.Modelview)
Gl.PopMatrix()
Gl.Disable(Glconst.Blend)
Gl.Enable(Glconst.DepthTest)
Gl.Disable(Glconst.Texture2d)
Gl.BindTexture(Glconst.Texture2d, 0)
END
More information about the Devel
mailing list