Re: Render with OpenGL on Ogre screen
Posted: Sun Apr 05, 2015 7:10 am
not sure what you want exactly, but i have asked myself before if it is possible to mix ogre and opengl with the same code and the screen , it seems to work , since my opinion is that the PB ogre functions InitEngine3D and InitSprite() are OpenGLized. so when we add OpenGLGadget then every thing are in home.
here is in the left the OpenGLGadget display some 2D function, and in the right a PB ogre window display a rotating cube. the dimensions are not carefully designed since i have copied 2 examples in one. and the shape in the opengl window needs to be centered , look this post under the subtitle Centering the Graphics http://www.purebasic.fr/english/viewtop ... ng#p454330 . but in pb ogre window the things are more exact, look the cube at the 0,0,0 relative to that window even the pb ogre window are to the extreme right.
Edit: i have added glTranslatef_(-5.0, -2.0, -10) and the shape can be moved to any place centered and rotated like we want, the code corrected
Edit2: added FPS measure using different procedures all from the forum and not from me. one of the fps measure are glutGet_(#GLUT_ELAPSED_TIME) , the other are using Engine3DStatus(#PB_Engine3D_CurrentFPS ) . since they are 3 procedures there is a drop in the fps from 60 to 54 on my system. seems all gives the same measure.
here is in the left the OpenGLGadget display some 2D function, and in the right a PB ogre window display a rotating cube. the dimensions are not carefully designed since i have copied 2 examples in one. and the shape in the opengl window needs to be centered , look this post under the subtitle Centering the Graphics http://www.purebasic.fr/english/viewtop ... ng#p454330 . but in pb ogre window the things are more exact, look the cube at the 0,0,0 relative to that window even the pb ogre window are to the extreme right.
Edit: i have added glTranslatef_(-5.0, -2.0, -10) and the shape can be moved to any place centered and rotated like we want, the code corrected
Edit2: added FPS measure using different procedures all from the forum and not from me. one of the fps measure are glutGet_(#GLUT_ELAPSED_TIME) , the other are using Engine3DStatus(#PB_Engine3D_CurrentFPS ) . since they are 3 procedures there is a drop in the fps from 60 to 54 on my system. seems all gives the same measure.
Code: Select all
Declare FPS(timer.l)
Declare calculateFPS() ; using glutGet_(#GLUT_ELAPSED_TIME)
Global fpsGlut.f
#GLUT_ELAPSED_TIME = 700 ; used only for glutget_(#GLUT_ELAPSED_TIME) function
Structure Point3D
x.f
y.f
z.f
r.f
g.f
b.f
EndStructure
Enumeration
#mesh
#entity
#tex
#light
#camera
#plane
EndEnumeration
InitEngine3D()
InitKeyboard()
InitSprite()
InitMouse()
Define event, quit
OpenWindow(0, 0, 0, 800, 600, "OpenGL...Fun 2D curves in 3D env + Ogre code")
SetWindowColor(0, RGB(200,220,200))
OpenWindowedScreen(WindowID(0),410,20,800-400, 600-200,1,0,0,#PB_Screen_WaitSynchronization)
OpenGLGadget(0, 20, 20, WindowWidth(0)-400 , WindowHeight(0)-200)
InitKeyboard()
Add3DArchive(".", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/Textures", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/fonts", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/Scripts", #PB_3DArchive_FileSystem)
Parse3DScripts()
KeyboardMode(#PB_Keyboard_AllowSystemKeys)
CreateMaterial(0, LoadTexture(0, "White.jpg"))
DisableMaterialLighting(0, #True)
CreateMaterial(1, LoadTexture(1, "ground_diffuse.png"))
MaterialCullingMode(1, #PB_Material_NoCulling)
CreatePlane(#plane, 50, 50, 1, 1, 5, 5)
CreateEntity(#plane,MeshID(#plane),MaterialID(1), 0,-16,0)
CreateMaterial(3, LoadTexture(3, "Geebee2.bmp"))
CreateLight(0,RGB(245,245,205),19,13,0)
;Create Camera
CreateCamera(0,0,0,100,100)
MoveCamera(0,0,10,100,#PB_Absolute)
CameraLookAt(0, 0, 5, 0)
CameraBackColor(0, RGB(227,239,242))
AmbientColor(RGB(255,255,255))
CreateLine3D(#PB_Any, -20, 0, 0, #Red, 20, 0, 0, RGB(255, 0, 0)) ; Red
CreateLine3D(#PB_Any, 0,-20,0, #Green, 0, 20, 0, RGB(0, 255, 0)); Green
;CreateLine3D(#PB_Any, 0,0,-20, #Blue, 0, 0, 20, RGB(0, 0, 255)) ;Blue
;-Mesh
;DrawPoints() ; call the function drawing procedure
CreateTexture(2,32,32)
StartDrawing(TextureOutput(2))
Box(0,0,32,32,RGB(255,0,0))
StopDrawing()
CreateMaterial(2,TextureID(2))
MaterialCullingMode(2, #PB_Material_NoCulling)
CreateCube(200, 4)
CreateEntity(200, MeshID(200), MaterialID(3) )
ScaleEntity(200, 5,5,5)
MoveEntity(200, 0, 0, 0, #PB_Absolute)
x.f = xMin
start = 0
;============================================================================
glLoadIdentity_();
gluPerspective_(45.0, 800/600, 1.0, 60.0)
glTranslatef_(0, 0, -5)
glEnable_(#GL_DEPTH_TEST)
Nb = 10054
Dim Point3D.Point3D(Nb)
;Debug ArraySize(Point3D())
u.f : v.f=-1 :r.f :t.f
x.f: y.f :z.f : N.l=0
;a.f = 1.3 :b.f=2 ; k=0.65
a.f = 3.8 :b.f=2 ; k=1.9
;a.f = 3 :b.f=0.5 ; k=6
;a.f = 0.66 :b.f=2 ; k=0.33
While t <= 32*#PI
x = (a - b) * Cos(t) + b * Cos(t * ((a / b) - 1))
y = (a - b) * Sin(t) - b * Sin(t * ((a / b) - 1))
Point3D(N)\x = x/2
Point3D(N)\y = y/2
Point3D(N)\r = 0 :Point3D(N)\g = 1 :Point3D(N)\b = 0
N+1
t + 0.01
Wend
arrayLength = ArraySize(Point3D())
rot.f = 1
glTranslatef_(-5.0, -2.0, -10)
Repeat
glViewport_(0, 0, WindowWidth(0), WindowHeight(0))
glClear_(#GL_COLOR_BUFFER_BIT | #GL_DEPTH_BUFFER_BIT)
glEnableClientState_(#GL_VERTEX_ARRAY )
glEnableClientState_(#GL_COLOR_ARRAY)
glRotatef_(rot, 0, 1, 0);
glVertexPointer_(3, #GL_FLOAT,SizeOf(Point3D),Point3D(0))
glColorPointer_(3, #GL_FLOAT, SizeOf(Point3D), @Point3D(0)\r)
glDrawArrays_(#GL_POINTS, 0, Nb)
glDisableClientState_(#GL_VERTEX_ARRAY);
glDisableClientState_(#GL_COLOR_ARRAY)
fps$ = Str(FPS(1000))
StartDrawing(WindowOutput(0))
DrawText(20, 2, "FPS = " + fps$)
DrawText(440, 1, "FPS: "+ StrF(Engine3DStatus(#PB_Engine3D_CurrentFPS )))
StopDrawing()
calculateFPS() ; using glutGet_(#GLUT_ELAPSED_TIME)
StartDrawing(WindowOutput(0))
DrawText(200, 2, "FPS with glutget_ = " + Str(fpsGlut))
StopDrawing()
RotateEntity(200, 0,1,0, #PB_Relative) ; ogre
RenderWorld() ;ogre
FlipBuffers() ;ogre
;;==============================================
Repeat
event = WindowEvent()
If ExamineKeyboard()
If KeyboardPushed (#PB_Key_Escape)
quit = 1
EndIf
EndIf
If event = #PB_Event_CloseWindow
quit = #True
EndIf
Until event = 0 Or quit = #True
SetGadgetAttribute(0, #PB_OpenGL_FlipBuffers, #True)
Delay(10)
Until quit = #True
Procedure FPS(timer.l) ; the code are from the forum
Static FPSCount.l, FPS.l
Static delay.l
Protected t.l
If timer = 0
ProcedureReturn -1
EndIf
t = ElapsedMilliseconds()
If t-delay > timer
FPS = FPSCount*1000/timer
FPSCount = 0
delay = t
Else
FPSCount+1
EndIf
ProcedureReturn FPS
EndProcedure
Procedure calculateFPS() ;Calculates the frames per second
;Increase frame count
Static frameCount
Static previousTime
frameCount+1
;Get the number of milliseconds since glutInit called
;(Or first call To glutGet(GLUT ELAPSED TIME)).
currentTime = glutGet_(#GLUT_ELAPSED_TIME);
;Calculate time passed
timeInterval = currentTime - previousTime;
If(timeInterval > 1000)
;calculate the number of frames per second
fpsGlut = frameCount / (timeInterval / 1000.0);
;Set time
previousTime = currentTime;
;Reset frame count
frameCount = 0;
EndIf
EndProcedure