Page 1 of 1

Re: Render with OpenGL on Ogre screen

Posted: Sun Apr 05, 2015 7:10 am
by applePi
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.

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

Re: Render with OpenGL on Ogre screen

Posted: Sun Apr 05, 2015 9:05 pm
by applePi
look at the following example Alexi, it display ogre cube and opengl cube at the same screen "OpenWindowedScreen(WindowID(0),.....)", but with big drop in ftp. also when we moveEntity the ogre cube the opengl cube follow it, also the opengl cube are affected by the color of the ogre cube, one bottleneck in how we render the ogre and opengl scenes:
RotateEntity(0, 0,1,0, #PB_Relative) ; ogre
RenderWorld() ;ogre
FlipBuffers() ;ogre

glTranslatef_(-3.0, 2.0, -1.0); opengl
Cube_Render() ; call opengl code
FlipBuffers()

Delay(5)
note that the ogre cube are flickered too much, you need to solve the flicker and the other things, for me and the usual usage the opengl gadget, or directly using OpenWindowedScreen to display the opengl shapes are very good.
note: set the subsystem to OpenGL

Code: Select all

InitEngine3D()
InitKeyboard()
InitSprite()
InitMouse()

InitKeyboard()
CompilerIf #PB_Compiler_OS = #PB_OS_Windows
  CompilerIf Subsystem("OpenGL") = #False
    MessageRequester("Error", "Please set the Library subsystem to OpenGL from IDE : Compiler... Compiler Options")
    End
  CompilerEndIf
CompilerEndIf

If InitSprite() = 0
  MessageRequester("Error", "Can't open screen & sprite environment!")
  End
EndIf

OpenWindow(0, 0, 20, 800, 600, "same window display Ogre and OpenGL But with low fps", #PB_Window_SystemMenu | #PB_Window_Invisible)
SetWindowColor(0, 14403509)
ContainerGadget(0, 5, WindowHeight(0)-50, 250, 60, #PB_Container_Raised)
ButtonGadget(1, 5, 5, 55, 20, "Stop/Run")
TrackBarGadget(2, 60, 10, 90, 20, 0, 200)
TextGadget(3, 150, 10, 100, 25, "0")
CloseGadgetList()
SetGadgetState(0, 0)

OpenWindowedScreen(WindowID(0), 0, 20, WindowWidth(0)-50, WindowHeight(0)-60, 0, 0, 0)

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()

CreateCube(0,2)
CreateMaterial(3, LoadTexture(3, "Geebee2.bmp"))
MaterialBlendingMode(3, #PB_Material_AlphaBlend)
SetMaterialColor(3, #PB_Material_DiffuseColor, RGBA(255, 255, 255, 150))

CreateEntity(0, MeshID(0), MaterialID(3) )
MoveEntity(0, 0,0,10, #PB_Absolute)
;Create Camera
CreateCamera(0,0,0,100,100)
MoveCamera(0,0,0,20,#PB_Absolute)
CameraLookAt(0, 0, 0, 0)
;CameraBackColor(0, RGB(227,239,242))

HideWindow(0, #False)
Global RollAxisX.f
Global RollAxisY.f
Global RollAxisZ.f

Global RotateSpeedX.f
Global RotateSpeedY.f
Global RotateSpeedZ.f

Global ZoomFactor.f
Global running = 1

glClearColor_ (0.0, 0.0, 0.0, 0.0);
glShadeModel_ (#GL_SMOOTH)

glEnable_(#GL_LIGHTING);
glEnable_(#GL_LIGHT0);
glEnable_(#GL_DEPTH_TEST);


glColorMaterial_(#GL_FRONT,  #GL_AMBIENT_AND_DIFFUSE)
glEnable_(#GL_COLOR_MATERIAL) ; color tracking

glEnable_(#GL_NORMALIZE)

Procedure.l Cube_Render()

 glPushMatrix_()                  ; Save the original Matrix coordinates
  glMatrixMode_(#GL_MODELVIEW)

  glTranslatef_(0, 0, ZoomFactor)  ;  move it forward a bit

  glRotatef_ (RollAxisX, 1.0, 0, 0) ; rotate around X axis
  glRotatef_ (RollAxisY, 0, 1.0, 0) ; rotate around Y axis
  glRotatef_ (RollAxisZ, 0, 0, 1.0) ; rotate around Z axis
 
  RollAxisX + RotateSpeedX 
  RollAxisY + RotateSpeedY 
  RollAxisZ + RotateSpeedZ 

  ; clear framebuffer And depth-buffer

  glClear_ (#GL_COLOR_BUFFER_BIT | #GL_DEPTH_BUFFER_BIT)

  ; draw the faces of a cube
  
  ; draw colored faces

  glDisable_(#GL_LIGHTING)
  glBegin_  (#GL_QUADS)
  
  ; Build a face, composed of 4 vertex ! 
  ; glBegin() specify how the vertexes are considered. Here a group of
  ; 4 vertexes (GL_QUADS) form a rectangular surface.

  ; Now, the color stuff: It's r,v,b but with float values which
  ; can go from 0.0 To 1.0 (0 is .. zero And 1.0 is full intensity) 
  
  glNormal3f_ (0,0,1.0)
  glColor3f_  (0,0,1.0)
  glVertex3f_ (0.5,0.5,0.5)   
  glColor3f_  (0,1.0,1.0)         
  glVertex3f_ (-0.5,0.5,0.5)
  glColor3f_  (1.0,1.0,1.0)
  glVertex3f_ (-0.5,-0.5,0.5)
  glColor3f_  (0,0,0)
  glVertex3f_ (0.5,-0.5,0.5) 

  ; The other face is the same than the previous one 
  ; except the colour which is nice blue To white gradiant

  glNormal3f_ (0,0,-1.0)
  glColor3f_  (0,0,1.0)
  glVertex3f_ (-0.5,-0.5,-0.5)
  glColor3f_  (0,0,1.0)
  glVertex3f_ (-0.5,0.5,-0.5)
  glColor3f_  (1.0,1.0,1.0)
  glVertex3f_ (0.5,0.5,-0.5)
  glColor3f_  (1.0,1.0,1.0)
  glVertex3f_ (0.5,-0.5,-0.5)
  
  glEnd_()
  
  ; draw shaded faces

  glEnable_(#GL_LIGHTING)
  glEnable_(#GL_LIGHT0)
  glBegin_ (#GL_QUADS)

  glNormal3f_ (   0, 1.0,   0)
  glVertex3f_ ( 0.5, 0.5, 0.5)
  glVertex3f_ ( 0.5, 0.5,-0.5)
  glVertex3f_ (-0.5, 0.5,-0.5)
  glVertex3f_ (-0.5, 0.5, 0.5)

  glNormal3f_ (0,-1.0,0)
  glVertex3f_ (-0.5,-0.5,-0.5)
  glVertex3f_ (0.5,-0.5,-0.5)
  glVertex3f_ (0.5,-0.5,0.5)
  glVertex3f_ (-0.5,-0.5,0.5)

  glNormal3f_ (1.0,0,0)
  glVertex3f_ (0.5,0.5,0.5)
  glVertex3f_ (0.5,-0.5,0.5)
  glVertex3f_ (0.5,-0.5,-0.5)
  glVertex3f_ (0.5,0.5,-0.5)

  glNormal3f_ (-1.0,   0,   0)
  glVertex3f_ (-0.5,-0.5,-0.5)
  glVertex3f_ (-0.5,-0.5, 0.5)
  glVertex3f_ (-0.5, 0.5, 0.5)
  glVertex3f_ (-0.5, 0.5,-0.5)

  glEnd_()

  glPopMatrix_()
  glFinish_()
    

EndProcedure

HideWindow(0, #False)

RotateSpeedX = 2.0   ; The speed of the rotation For the 3 axis
RotateSpeedY = 2
RotateSpeedZ = 2.0

ZoomFactor = 0      ; Distance of the camera. Negative value = zoom back

glViewport_(0, 0, WindowWidth(0), WindowHeight(0))
glMatrixMode_(#GL_PROJECTION)
glLoadIdentity_()
gluPerspective_(30.0, Abs(WindowWidth(0) / WindowHeight(0)), 0.1, 500.0)
glMatrixMode_(#GL_MODELVIEW)
glLoadIdentity_()
glClear_(#GL_COLOR_BUFFER_BIT | #GL_DEPTH_BUFFER_BIT)
glLoadIdentity_ ()
gluLookAt_(0,5,15,0,1.5,0,0,1,0);
  

Repeat
  
  StartDrawing(WindowOutput(0))
      DrawText(440, 1, "FPS: "+ StrF(Engine3DStatus(#PB_Engine3D_CurrentFPS )))
   StopDrawing()
   
    EventID = WindowEvent()
    Select EventID
      Case #PB_Event_Gadget
          If EventGadget() = 1
            running ! 1
            RotateSpeedX = running
            RotateSpeedY = running
            RotateSpeedZ = running
          EndIf
          If EventGadget() = 2
            ZoomFactor = (GetGadgetState(2)/200)*5
           
           SetGadgetText(3, Str(ZoomFactor))
          EndIf     
      Case #PB_Event_CloseWindow
        Quit = 1
    EndSelect
    ExamineKeyboard()
    
  RotateEntity(0, 0,1,0, #PB_Relative) ; ogre
  RenderWorld() ;ogre
  FlipBuffers() ;ogre
  
  glTranslatef_(-3.0, 2.0, -1.0);  opengl 
  Cube_Render() ; call opengl code
  FlipBuffers()
  
  Delay(5)

  
  Until Quit = 1 Or KeyboardPushed(#PB_Key_Escape)

End

Re: Render with OpenGL on Ogre screen

Posted: Sun Apr 05, 2015 9:22 pm
by luis
First off all, I don't know anything about PB OGRE (PBO from now on).
What you ask can be done in OGRE, but that's another beast with another API.

With that out of the way, since the RC used by PBO seem to be associated to your main thread, you don't even have to select it in your thread, know its value, or anything like that, you can simply start using OpenGL commands and draw.
This is also assuming the RC used by PBO is a legacy one or at least backward compatible (I don't even know what OGRE version PB is using).

Probably the best place to insert your stuff is between RenderWorld() and FlipBuffers().

The big problems I see are:

The GL state machine is in a certain state after RenderWold() so you need to reset the various states you don't need for your code and set just what you need.
Example, PBO is using lightning and you don't need that ? You must issue a glDisable_(#GL_LIGHTING) or your stuff will have the wrong colors.
PBO is using textures and your code don't ? You must issue a glDisable_(#GL_TEXTURE_2D) or your stuff will be textured even if you just wanted a shaded triangle.
You need something PBO have not set ? You need to enable it.
Also you should save all the attributes you are going to change entering your code and restore them at the exit of your code.
All this could range from the difficult to the nearly impossible.
Probably there is not a single set you can save and restore reliably for every PBO program, as it will depend on the feature set it's using in that particular case. Simple stuff can work with few problems, more complex stuff certainly not.
All this may apply to the GL matrices as well, or maybe not because PBO could reset them at every frame (probably) but again who knows ? Tons of experimentation required.

The PBO could use shaders, they could be active between each frame, disabled, reinstated, modified, who knows what's happening. They can mess your state or disable half of your pipeline and it can be hard to discover how (probably this will not happen but... it could).

PB supports only GL 1.2 commands, if PBO is using commands higher than that you may need also those commands to undo what they are doing, so you need to import more GL commands, or maybe even extensions, who knows.
applePi wrote:note that the ogre cube are flickered too much, you need to solve the flicker and the other things
for that just do a single FlipBuffers() and remove the glclear() from Cube_Render(), there are some remaining problems but this is just due to the double swapping.

Also mixing 3d stuff with the correct depth testing, light etc. would be really challenging (if possible at all), for 2D all that does not apply so I hope that's what Alexi wants to do.

Re: Render with OpenGL on Ogre screen

Posted: Mon Apr 06, 2015 7:12 am
by applePi
now it works, thanks luis for the valuable suggestions, the fps now is 60. i have added/ deleted what you have suggested. and now it works with the normal color. the only problem is that when we change MoveEntity(0, 0,0,10, #PB_Absolute) to MoveEntity(0, 4,0,10, #PB_Absolute) Line 42 to move the ogre cube , it moves also the opengl cube with it. but anyway it is a fun exercise.

Code: Select all

InitEngine3D()
InitKeyboard()
InitSprite()
InitMouse()

InitKeyboard()
CompilerIf #PB_Compiler_OS = #PB_OS_Windows
  CompilerIf Subsystem("OpenGL") = #False
    MessageRequester("Error", "Please set the Library subsystem to OpenGL from IDE : Compiler... Compiler Options")
    End
  CompilerEndIf
CompilerEndIf

If InitSprite() = 0
  MessageRequester("Error", "Can't open screen & sprite environment!")
  End
EndIf

OpenWindow(0, 0, 20, 800, 600, "same window display Ogre and OpenGL But with low fps", #PB_Window_SystemMenu | #PB_Window_Invisible)
SetWindowColor(0, 14403509)
ContainerGadget(0, 5, WindowHeight(0)-50, 250, 60, #PB_Container_Raised)
ButtonGadget(1, 5, 5, 55, 20, "Stop/Run")
TrackBarGadget(2, 60, 10, 90, 20, 0, 200)
TextGadget(3, 150, 10, 100, 25, "0")
CloseGadgetList()
SetGadgetState(0, 0)

OpenWindowedScreen(WindowID(0), 0, 20, WindowWidth(0)-50, WindowHeight(0)-60, 0, 0, 0)

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()

CreateCube(0,2)
CreateMaterial(3, LoadTexture(3, "Geebee2.bmp"))
MaterialBlendingMode(3, #PB_Material_AlphaBlend)
SetMaterialColor(3, #PB_Material_DiffuseColor, RGBA(255, 255, 255, 150))

CreateEntity(0, MeshID(0), MaterialID(3) )
MoveEntity(0, 0,0,10, #PB_Absolute)
;Create Camera
CreateCamera(0,0,0,100,100)
MoveCamera(0,0,0,20,#PB_Absolute)
CameraLookAt(0, 0, 0, 0)
;CameraBackColor(0, RGB(227,239,242))

HideWindow(0, #False)
Global RollAxisX.f
Global RollAxisY.f
Global RollAxisZ.f

Global RotateSpeedX.f
Global RotateSpeedY.f
Global RotateSpeedZ.f

Global ZoomFactor.f
Global running = 1

glClearColor_ (0.0, 0.0, 0.0, 0.0);
glShadeModel_ (#GL_SMOOTH)

glEnable_(#GL_LIGHTING);
glEnable_(#GL_LIGHT0);
glEnable_(#GL_DEPTH_TEST);


glColorMaterial_(#GL_FRONT,  #GL_AMBIENT_AND_DIFFUSE)
glEnable_(#GL_COLOR_MATERIAL) ; color tracking

glEnable_(#GL_NORMALIZE)

Procedure.l Cube_Render()

 glPushMatrix_()                  ; Save the original Matrix coordinates
  glMatrixMode_(#GL_MODELVIEW)

  glTranslatef_(0, 0, ZoomFactor)  ;  move it forward a bit
 
  glRotatef_ (RollAxisX, 1.0, 0, 0) ; rotate around X axis
  glRotatef_ (RollAxisY, 0, 1.0, 0) ; rotate around Y axis
  glRotatef_ (RollAxisZ, 0, 0, 1.0) ; rotate around Z axis
 
  RollAxisX + RotateSpeedX 
  RollAxisY + RotateSpeedY 
  RollAxisZ + RotateSpeedZ 

  ; clear framebuffer And depth-buffer

  ;glClear_ (#GL_COLOR_BUFFER_BIT | #GL_DEPTH_BUFFER_BIT)

  ; draw the faces of a cube
  
  ; draw colored faces

  glDisable_(#GL_LIGHTING)
  glDisable_(#GL_TEXTURE_2D)
  glBegin_  (#GL_QUADS)
  
  ; Build a face, composed of 4 vertex ! 
  ; glBegin() specify how the vertexes are considered. Here a group of
  ; 4 vertexes (GL_QUADS) form a rectangular surface.

  ; Now, the color stuff: It's r,v,b but with float values which
  ; can go from 0.0 To 1.0 (0 is .. zero And 1.0 is full intensity) 
  
  glNormal3f_ (0,0,1.0)
  glColor3f_  (0,0,1.0)
  glVertex3f_ (0.5,0.5,0.5)   
  glColor3f_  (0,1.0,1.0)         
  glVertex3f_ (-0.5,0.5,0.5)
  glColor3f_  (1.0,1.0,1.0)
  glVertex3f_ (-0.5,-0.5,0.5)
  glColor3f_  (0,0,0)
  glVertex3f_ (0.5,-0.5,0.5) 

  ; The other face is the same than the previous one 
  ; except the colour which is nice blue To white gradiant

  glNormal3f_ (0,0,-1.0)
  glColor3f_  (0,0,1.0)
  glVertex3f_ (-0.5,-0.5,-0.5)
  glColor3f_  (0,0,1.0)
  glVertex3f_ (-0.5,0.5,-0.5)
  glColor3f_  (1.0,1.0,1.0)
  glVertex3f_ (0.5,0.5,-0.5)
  glColor3f_  (1.0,1.0,1.0)
  glVertex3f_ (0.5,-0.5,-0.5)
  
  glEnd_()
  
  ; draw shaded faces

  glEnable_(#GL_LIGHTING)
  glEnable_(#GL_LIGHT0)
  glBegin_ (#GL_QUADS)

  glNormal3f_ (   0, 1.0,   0)
  glVertex3f_ ( 0.5, 0.5, 0.5)
  glVertex3f_ ( 0.5, 0.5,-0.5)
  glVertex3f_ (-0.5, 0.5,-0.5)
  glVertex3f_ (-0.5, 0.5, 0.5)

  glNormal3f_ (0,-1.0,0)
  glVertex3f_ (-0.5,-0.5,-0.5)
  glVertex3f_ (0.5,-0.5,-0.5)
  glVertex3f_ (0.5,-0.5,0.5)
  glVertex3f_ (-0.5,-0.5,0.5)

  glNormal3f_ (1.0,0,0)
  glVertex3f_ (0.5,0.5,0.5)
  glVertex3f_ (0.5,-0.5,0.5)
  glVertex3f_ (0.5,-0.5,-0.5)
  glVertex3f_ (0.5,0.5,-0.5)

  glNormal3f_ (-1.0,   0,   0)
  glVertex3f_ (-0.5,-0.5,-0.5)
  glVertex3f_ (-0.5,-0.5, 0.5)
  glVertex3f_ (-0.5, 0.5, 0.5)
  glVertex3f_ (-0.5, 0.5,-0.5)

  glEnd_()

  glPopMatrix_()
  glFinish_()
    

EndProcedure

HideWindow(0, #False)

RotateSpeedX = 2.0   ; The speed of the rotation For the 3 axis
RotateSpeedY = 2
RotateSpeedZ = 2.0

ZoomFactor = 0      ; Distance of the camera. Negative value = zoom back

glViewport_(0, 0, WindowWidth(0), WindowHeight(0))
glMatrixMode_(#GL_PROJECTION)
glLoadIdentity_()
gluPerspective_(30.0, Abs(WindowWidth(0) / WindowHeight(0)), 0.1, 500.0)
glMatrixMode_(#GL_MODELVIEW)
glLoadIdentity_()
;glClear_(#GL_COLOR_BUFFER_BIT | #GL_DEPTH_BUFFER_BIT)
glLoadIdentity_ ()
gluLookAt_(0,5,15,0,1.5,0,0,1,0);
  

Repeat
  
  StartDrawing(WindowOutput(0))
      DrawText(440, 1, "FPS: "+ StrF(Engine3DStatus(#PB_Engine3D_CurrentFPS )))
   StopDrawing()
   
    EventID = WindowEvent()
    Select EventID
      Case #PB_Event_Gadget
          If EventGadget() = 1
            running ! 1
            RotateSpeedX = running
            RotateSpeedY = running
            RotateSpeedZ = running
          EndIf
          If EventGadget() = 2
            ZoomFactor = (GetGadgetState(2)/200)*5
           
           SetGadgetText(3, Str(ZoomFactor))
          EndIf     
      Case #PB_Event_CloseWindow
        Quit = 1
    EndSelect
    ExamineKeyboard()
    
  RotateEntity(0, 0,1,0, #PB_Relative) ; ogre
  RenderWorld() ;ogre
  ;FlipBuffers() ;ogre
  
  glTranslatef_(0.0, 2.0, 0.0);  opengl 
  
  Cube_Render() ; call opengl code
  
  FlipBuffers()
    
  Delay(5)

  
  Until Quit = 1 Or KeyboardPushed(#PB_Key_Escape)

End

Re: Render with OpenGL on Ogre screen

Posted: Tue Apr 07, 2015 9:43 am
by applePi
Alexi said: i got an IMA on line 37?
CreateMaterial(3, LoadTexture(3, "Geebee2.bmp"))
you are the expert , try #PB_Material_None. it works on my system windows xp 32bit Purebasic v5.31 .. Geforce GT520
i have found that also the opengl cube will be attached to any new ogre Created Entity, and even if we scaled the entity down/up it will be scaled accordingly, and if we hide the entity the opengl cube will be attached again to the first entity . but we can scale the opengl cube and move it, but in rotation it will rotate around the PB ogre entity
now i can do screen print the graphics, previously i was not able to do screen print when the fps = 30. but now it is 60 thanks for luis help.
Image

Code: Select all

InitEngine3D()
InitKeyboard()
InitSprite()
InitMouse()

InitKeyboard()
CompilerIf #PB_Compiler_OS = #PB_OS_Windows
  CompilerIf Subsystem("OpenGL") = #False
    MessageRequester("Error", "Please set the Library subsystem to OpenGL from IDE : Compiler... Compiler Options")
    End
  CompilerEndIf
CompilerEndIf

If InitSprite() = 0
  MessageRequester("Error", "Can't open screen & sprite environment!")
  End
EndIf

OpenWindow(0, 0, 20, 800, 600, "same window display Ogre and OpenGL But with good fps", #PB_Window_SystemMenu | #PB_Window_Invisible)
SetWindowColor(0, 14403509)
ContainerGadget(0, 5, WindowHeight(0)-50, 250, 60, #PB_Container_Raised)
ButtonGadget(1, 5, 5, 55, 20, "Stop/Run")
TrackBarGadget(2, 60, 10, 90, 20, 0, 200)
TextGadget(3, 150, 10, 100, 25, "0")
CloseGadgetList()
SetGadgetState(0, 0)

OpenWindowedScreen(WindowID(0), 0, 20, WindowWidth(0)-50, WindowHeight(0)-60, 0, 0, 0)

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()

CreateCube(0,2)
CreateMaterial(3, LoadTexture(3, "Geebee2.bmp"))
;MaterialBlendingMode(3, #PB_Material_AlphaBlend)
;SetMaterialColor(3, #PB_Material_DiffuseColor, RGBA(255, 255, 255, 150))

CreateEntity(0, MeshID(0), MaterialID(3) )
MoveEntity(0, 4,0,5, #PB_Absolute)

CreateCube(5,2)
CreateMaterial(4, LoadTexture(4, "clouds.jpg"))
;MaterialBlendingMode(3, #PB_Material_AlphaBlend)
;SetMaterialColor(3, #PB_Material_DiffuseColor, RGBA(255, 255, 255, 150))

CreateEntity(5, MeshID(5), MaterialID(4) )
ScaleEntity(5, 0.9,0.9,0.9)
MoveEntity(5, -4,0,5, #PB_Absolute)
HideEntity(5,0)

;CreateNode(6, -2,0,0)
;AttachNodeObject(6, EntityID(5))

;Create Camera
CreateCamera(0,0,0,100,100)
MoveCamera(0,0,0,20,#PB_Absolute)
CameraLookAt(0, 0, 0, 0)
;CameraBackColor(0, RGB(227,239,242))

HideWindow(0, #False)
Global RollAxisX.f
Global RollAxisY.f
Global RollAxisZ.f

Global RotateSpeedX.f
Global RotateSpeedY.f
Global RotateSpeedZ.f

Global ZoomFactor.f
Global running = 1

glClearColor_ (0.0, 0.0, 0.0, 0.0);
glShadeModel_ (#GL_SMOOTH)

glEnable_(#GL_LIGHTING);
glEnable_(#GL_LIGHT0);
glEnable_(#GL_DEPTH_TEST);


glColorMaterial_(#GL_FRONT,  #GL_AMBIENT_AND_DIFFUSE)
glEnable_(#GL_COLOR_MATERIAL) ; color tracking

glEnable_(#GL_NORMALIZE)
 

Procedure.l Cube_Render()
  glPushMatrix_() 
  glDisable_(#GL_LIGHTING)
  glDisable_(#GL_TEXTURE_2D)
glTranslatef_(3, 0, 0)
glColor3f_(0.0, 1.0, 0.0)
glutWireDodecahedron_() 
glPopMatrix_()

 glPushMatrix_()                  ; Save the original Matrix coordinates
  glMatrixMode_(#GL_MODELVIEW)

  glTranslatef_(0, 2, ZoomFactor)  ;  move it forward a bit
  
  
  glRotatef_ (RollAxisX, 1.0, 0, 0) ; rotate around X axis
  glRotatef_ (RollAxisY, 0, 1.0, 0) ; rotate around Y axis
  glRotatef_ (RollAxisZ, 0, 0, 1.0) ; rotate around Z axis
 
  RollAxisX + RotateSpeedX 
  RollAxisY + RotateSpeedY 
  RollAxisZ + RotateSpeedZ 

  ; clear framebuffer And depth-buffer

  ;glClear_ (#GL_COLOR_BUFFER_BIT | #GL_DEPTH_BUFFER_BIT)

  ; draw the faces of a cube
  
  ; draw colored faces
  glScalef_(3,0.5,3)
  glDisable_(#GL_LIGHTING)
  glDisable_(#GL_TEXTURE_2D)
  glBegin_  (#GL_QUADS)
  
  ; Build a face, composed of 4 vertex ! 
  ; glBegin() specify how the vertexes are considered. Here a group of
  ; 4 vertexes (GL_QUADS) form a rectangular surface.

  ; Now, the color stuff: It's r,v,b but with float values which
  ; can go from 0.0 To 1.0 (0 is .. zero And 1.0 is full intensity) 
  
  glNormal3f_ (0,0,1.0)
  glColor3f_  (0,0,1.0)
  glVertex3f_ (0.5,0.5,0.5)   
  glColor3f_  (0,1.0,1.0)         
  glVertex3f_ (-0.5,0.5,0.5)
  glColor3f_  (1.0,1.0,1.0)
  glVertex3f_ (-0.5,-0.5,0.5)
  glColor3f_  (0,0,0)
  glVertex3f_ (0.5,-0.5,0.5) 

  ; The other face is the same than the previous one 
  ; except the colour which is nice blue To white gradiant

  glNormal3f_ (0,0,-1.0)
  glColor3f_  (0,0,1.0)
  glVertex3f_ (-0.5,-0.5,-0.5)
  glColor3f_  (0,0,1.0)
  glVertex3f_ (-0.5,0.5,-0.5)
  glColor3f_  (1.0,1.0,1.0)
  glVertex3f_ (0.5,0.5,-0.5)
  glColor3f_  (1.0,1.0,1.0)
  glVertex3f_ (0.5,-0.5,-0.5)
  
  glEnd_()
  
  ; draw shaded faces

  glEnable_(#GL_LIGHTING)
  glEnable_(#GL_LIGHT0)
  glBegin_ (#GL_QUADS)

  glNormal3f_ (   0, 1.0,   0)
  glVertex3f_ ( 0.5, 0.5, 0.5)
  glVertex3f_ ( 0.5, 0.5,-0.5)
  glVertex3f_ (-0.5, 0.5,-0.5)
  glVertex3f_ (-0.5, 0.5, 0.5)

  glNormal3f_ (0,-1.0,0)
  glVertex3f_ (-0.5,-0.5,-0.5)
  glVertex3f_ (0.5,-0.5,-0.5)
  glVertex3f_ (0.5,-0.5,0.5)
  glVertex3f_ (-0.5,-0.5,0.5)

  glNormal3f_ (1.0,0,0)
  glVertex3f_ (0.5,0.5,0.5)
  glVertex3f_ (0.5,-0.5,0.5)
  glVertex3f_ (0.5,-0.5,-0.5)
  glVertex3f_ (0.5,0.5,-0.5)

  glNormal3f_ (-1.0,   0,   0)
  glVertex3f_ (-0.5,-0.5,-0.5)
  glVertex3f_ (-0.5,-0.5, 0.5)
  glVertex3f_ (-0.5, 0.5, 0.5)
  glVertex3f_ (-0.5, 0.5,-0.5)

  glEnd_()

  glPopMatrix_()
  
  glFinish_()
  ;glColor3f_(1.0, 0.0, 1.0)
 ;glutWireDodecahedron_()  

EndProcedure

HideWindow(0, #False)

RotateSpeedX = 2.0   ; The speed of the rotation For the 3 axis
RotateSpeedY = 2
RotateSpeedZ = 2.0

ZoomFactor = 0      ; Distance of the camera. Negative value = zoom back

glViewport_(0, 0, WindowWidth(0), WindowHeight(0))
glMatrixMode_(#GL_PROJECTION)
glLoadIdentity_()
gluPerspective_(30.0, Abs(WindowWidth(0) / WindowHeight(0)), 0.1, 500.0)
glMatrixMode_(#GL_MODELVIEW)
glLoadIdentity_()
;glClear_(#GL_COLOR_BUFFER_BIT | #GL_DEPTH_BUFFER_BIT)
glLoadIdentity_ ()
gluLookAt_(0,5,15,0,1.5,0,0,1,0);
  

Repeat
  RenderWorld() ;ogre
  StartDrawing(WindowOutput(0))
      DrawText(440, 1, "FPS: "+ StrF(Engine3DStatus(#PB_Engine3D_CurrentFPS )))
   StopDrawing()
   
    EventID = WindowEvent()
    Select EventID
      Case #PB_Event_Gadget
          If EventGadget() = 1
            running ! 1
            RotateSpeedX = running
            RotateSpeedY = running
            RotateSpeedZ = running
          EndIf
          If EventGadget() = 2
            ZoomFactor = (GetGadgetState(2)/200)*5
           
           SetGadgetText(3, Str(ZoomFactor))
          EndIf     
      Case #PB_Event_CloseWindow
        Quit = 1
    EndSelect
    ExamineKeyboard()
    
    RotateEntity(0, 0,1,0, #PB_Relative) ; ogre
    RotateEntity(5, 0,1,0, #PB_Relative) ; ogre
  ;RenderWorld() ;ogre
  ;FlipBuffers() ;ogre
  
  glTranslatef_(0.0, 2.0, 0.0);  opengl 
  
  Cube_Render() ; call opengl code
  
  FlipBuffers()
    
  Delay(5)

  
  Until Quit = 1 Or KeyboardPushed(#PB_Key_Escape)

End

Re: Render with OpenGL on Ogre screen

Posted: Thu Apr 09, 2015 7:43 am
by applePi
Thanks Alexi for the solution, and now looking at your modification in glTranslatef_(0, 2, -(ZoomFactor+10)) have recognized that i was cheated 2 days ago by the disappearance of the opengl cube behind me (so to speak) since the ogre Z direction are different than opengl Z direction.
there is still a big problem with the camera, it has no effect on detached or liberated opengl , and even the attached Dodecahedron to right cube appears to jump to the left cube when we move the camera by mouse , and if we textured the cubes the Dodecahedron will be attached to the left cube and not the right cube !!!!.
and if we use gluLookAt as in line 112 below it will affect only the opengl cube.
i suggest to keep the attached opengl object and make the ogre parent object transparent so no one will see it, but then we must use glDisable_(#GL_BLEND)

Code: Select all

#CameraSpeed = 0.5
Define.f KeyX, KeyY, MouseX, MouseY

InitEngine3D()
InitKeyboard()
InitSprite()
InitMouse()

InitKeyboard()
CompilerIf #PB_Compiler_OS = #PB_OS_Windows
  CompilerIf Subsystem("OpenGL") = #False
    MessageRequester("Error", "Please set the Library subsystem to OpenGL from IDE : Compiler... Compiler Options")
    End
  CompilerEndIf
CompilerEndIf

If InitSprite() = 0
  MessageRequester("Error", "Can't open screen & sprite environment!")
  End
EndIf

OpenWindow(0, 0, 20, 800, 600, "same window display Ogre and OpenGL... use keys / mouse to move the camera", #PB_Window_SystemMenu | #PB_Window_Invisible)
SetWindowColor(0, 14403509)
ContainerGadget(0, 5, WindowHeight(0)-50, 250, 60, #PB_Container_Raised)
ButtonGadget(1, 5, 5, 55, 20, "Stop/Run")
TrackBarGadget(2, 60, 10, 90, 20, 0, 200)
TextGadget(3, 150, 10, 100, 25, "0")
CloseGadgetList()
SetGadgetState(0, 0)

OpenWindowedScreen(WindowID(0), 0, 20, WindowWidth(0)-50, WindowHeight(0)-60, 0, 0, 0)

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()

CreateCube(0,2)
;CreateMaterial(3, LoadTexture(3, "Geebee2.bmp"))
;MaterialBlendingMode(3, #PB_Material_AlphaBlend)
;SetMaterialColor(3, #PB_Material_DiffuseColor, RGBA(255, 255, 255, 150))

CreateEntity(0, MeshID(0), #PB_Material_None  )
MoveEntity(0, 4,0,5, #PB_Absolute)

CreateCube(5,2)
;CreateMaterial(4, LoadTexture(4, "clouds.jpg"))
;MaterialBlendingMode(3, #PB_Material_AlphaBlend)
;SetMaterialColor(3, #PB_Material_DiffuseColor, RGBA(255, 255, 255, 150))

CreateEntity(5, MeshID(5), #PB_Material_None )
ScaleEntity(5, 0.5,0.5,0.5)
MoveEntity(5, -5,0,5, #PB_Absolute)
HideEntity(5,0)

;CreateNode(6, -2,0,0)
;AttachNodeObject(6, EntityID(5))

;Create Camera
CreateCamera(0,0,0,100,100)
MoveCamera(0,0,0,20,#PB_Absolute)
CameraLookAt(0, 0, 0, 0)
;CameraBackColor(0, RGB(227,239,242))

HideWindow(0, #False)
Global RollAxisX.f
Global RollAxisY.f
Global RollAxisZ.f

Global RotateSpeedX.f
Global RotateSpeedY.f
Global RotateSpeedZ.f

Global ZoomFactor.f
Global running = 1

glClearColor_ (0.0, 0.0, 0.0, 0.0);
glShadeModel_ (#GL_SMOOTH)

glEnable_(#GL_LIGHTING);
glEnable_(#GL_LIGHT0);
glEnable_(#GL_DEPTH_TEST);


glColorMaterial_(#GL_FRONT,  #GL_AMBIENT_AND_DIFFUSE)
glEnable_(#GL_COLOR_MATERIAL) ; color tracking

glEnable_(#GL_NORMALIZE)
 

Procedure.l Cube_Render()
  glPushMatrix_() 
  glDisable_(#GL_LIGHTING)
  glDisable_(#GL_TEXTURE_2D)
  glDisable_(#GL_BLEND)
glTranslatef_(3, 2, 0)
glColor3f_(0.0, 1.0, 0.0)
;glLoadIdentity_()
;glTranslatef_(0, 2, -10)
glRotatef_ (RollAxisY, 0, 1.0, 0) ; rotate around Y axis
glutWireDodecahedron_() 
glPopMatrix_()


glPushMatrix_()                  ; Save the original Matrix coordinates
  glMatrixMode_(#GL_MODELVIEW)
  glLoadIdentity_()
  ;glTranslatef_(0, 0, ZoomFactor)  ;  move it forward a bit
  glTranslatef_(-4, 0, -8)  ;  move it forward a bit
  
  ;gluLookAt_(0, 0,20, 0,0,0,1,1,1)
  
  glRotatef_ (RollAxisX, 1.0, 0, 0) ; rotate around X axis
  glRotatef_ (RollAxisY, 0, 1.0, 0) ; rotate around Y axis
  glRotatef_ (RollAxisZ, 0, 0, 1.0) ; rotate around Z axis
 
  RollAxisX + RotateSpeedX 
  RollAxisY + RotateSpeedY 
  RollAxisZ + RotateSpeedZ 

  ; clear framebuffer And depth-buffer

  ;glClear_ (#GL_COLOR_BUFFER_BIT | #GL_DEPTH_BUFFER_BIT)

  ; draw the faces of a cube
  
  ; draw colored faces

  glDisable_(#GL_LIGHTING)
  glDisable_(#GL_TEXTURE_2D)
  glBegin_  (#GL_QUADS)
  
  ; Build a face, composed of 4 vertex ! 
  ; glBegin() specify how the vertexes are considered. Here a group of
  ; 4 vertexes (GL_QUADS) form a rectangular surface.

  ; Now, the color stuff: It's r,v,b but with float values which
  ; can go from 0.0 To 1.0 (0 is .. zero And 1.0 is full intensity) 
  
  glNormal3f_ (0,0,1.0)
  glColor3f_  (0,0,1.0)
  glVertex3f_ (0.5,0.5,0.5)   
  glColor3f_  (0,1.0,1.0)         
  glVertex3f_ (-0.5,0.5,0.5)
  glColor3f_  (1.0,1.0,1.0)
  glVertex3f_ (-0.5,-0.5,0.5)
  glColor3f_  (0,0,0)
  glVertex3f_ (0.5,-0.5,0.5) 

  ; The other face is the same than the previous one 
  ; except the colour which is nice blue To white gradiant

  glNormal3f_ (0,0,-1.0)
  glColor3f_  (0,0,1.0)
  glVertex3f_ (-0.5,-0.5,-0.5)
  glColor3f_  (0,0,1.0)
  glVertex3f_ (-0.5,0.5,-0.5)
  glColor3f_  (1.0,1.0,1.0)
  glVertex3f_ (0.5,0.5,-0.5)
  glColor3f_  (1.0,1.0,1.0)
  glVertex3f_ (0.5,-0.5,-0.5)
  
  glEnd_()
  
  ; draw shaded faces

  glEnable_(#GL_LIGHTING)
  glEnable_(#GL_LIGHT0)
  glBegin_ (#GL_QUADS)

  glNormal3f_ (   0, 1.0,   0)
  glVertex3f_ ( 0.5, 0.5, 0.5)
  glVertex3f_ ( 0.5, 0.5,-0.5)
  glVertex3f_ (-0.5, 0.5,-0.5)
  glVertex3f_ (-0.5, 0.5, 0.5)

  glNormal3f_ (0,-1.0,0)
  glVertex3f_ (-0.5,-0.5,-0.5)
  glVertex3f_ (0.5,-0.5,-0.5)
  glVertex3f_ (0.5,-0.5,0.5)
  glVertex3f_ (-0.5,-0.5,0.5)

  glNormal3f_ (1.0,0,0)
  glVertex3f_ (0.5,0.5,0.5)
  glVertex3f_ (0.5,-0.5,0.5)
  glVertex3f_ (0.5,-0.5,-0.5)
  glVertex3f_ (0.5,0.5,-0.5)

  glNormal3f_ (-1.0,   0,   0)
  glVertex3f_ (-0.5,-0.5,-0.5)
  glVertex3f_ (-0.5,-0.5, 0.5)
  glVertex3f_ (-0.5, 0.5, 0.5)
  glVertex3f_ (-0.5, 0.5,-0.5)

  glEnd_()

  glPopMatrix_()
  
  glFinish_()
  ;glColor3f_(1.0, 0.0, 1.0)
 ;glutWireDodecahedron_()  

EndProcedure

HideWindow(0, #False)

RotateSpeedX = 2.0   ; The speed of the rotation For the 3 axis
RotateSpeedY = 2
RotateSpeedZ = 2.0

ZoomFactor = 0      ; Distance of the camera. Negative value = zoom back

glViewport_(0, 0, WindowWidth(0), WindowHeight(0))
glMatrixMode_(#GL_PROJECTION)
glLoadIdentity_()
gluPerspective_(30.0, Abs(WindowWidth(0) / WindowHeight(0)), 0.1, 500.0)
glMatrixMode_(#GL_MODELVIEW)
glLoadIdentity_()
;glClear_(#GL_COLOR_BUFFER_BIT | #GL_DEPTH_BUFFER_BIT)
glLoadIdentity_ ()
gluLookAt_(0,5,15,0,1.5,0,0,1,0);
  

Repeat
  
  If ExamineMouse()
        MouseX = -MouseDeltaX() * #CameraSpeed * 0.1
        MouseY = -MouseDeltaY() * #CameraSpeed * 0.1
      EndIf
      
      If ExamineKeyboard()
               
        If KeyboardPushed(#PB_Key_Left)
          KeyX = -#CameraSpeed
        ElseIf KeyboardPushed(#PB_Key_Right)
          KeyX = #CameraSpeed
        Else
          KeyX = 0
        EndIf
        
        If KeyboardPushed(#PB_Key_Up)
          KeyY = -#CameraSpeed
        ElseIf KeyboardPushed(#PB_Key_Down)
          KeyY = #CameraSpeed
        Else
          KeyY = 0
        EndIf
        
      EndIf
      
      MoveCamera  (0, KeyX, 0, KeyY)
      RotateCamera(0,  MouseY, MouseX, 0, #PB_Relative)
  RenderWorld() ;ogre
  StartDrawing(WindowOutput(0))
      DrawText(440, 1, "FPS: "+ StrF(Engine3DStatus(#PB_Engine3D_CurrentFPS )))
   StopDrawing()
   
    EventID = WindowEvent()
    Select EventID
      Case #PB_Event_Gadget
          If EventGadget() = 1
            running ! 1
            RotateSpeedX = running
            RotateSpeedY = running
            RotateSpeedZ = running
          EndIf
          If EventGadget() = 2
            ZoomFactor = (GetGadgetState(2)/200)*5
           
           SetGadgetText(3, Str(ZoomFactor))
          EndIf     
      Case #PB_Event_CloseWindow
        Quit = 1
    EndSelect
    ExamineKeyboard()
    
    RotateEntity(0, 0,1,0, #PB_Relative) ; ogre
    RotateEntity(5, 0,1,0, #PB_Relative) ; ogre
  ;RenderWorld() ;ogre
  ;FlipBuffers() ;ogre
  
  ;glTranslatef_(0.0, 2.0, 0.0);  opengl 
  
  Cube_Render() ; call opengl code
  
  FlipBuffers()
    
  Delay(5)

  
  Until Quit = 1 Or KeyboardPushed(#PB_Key_Escape)

End

Re: Render with OpenGL on Ogre screen

Posted: Thu Apr 09, 2015 8:23 am
by Joris
Just trying some of the code above tells me I need the glut32.dll (XP SP3).
It seems that dll is hard to find or dad like someone tells, is it ? :
http://answers.microsoft.com/en-us/wind ... cb4a883227
Where to get this safely ?

Re: Render with OpenGL on Ogre screen

Posted: Thu Apr 09, 2015 9:18 am
by applePi
my system is also xp3 , i have renamed the glut32.dll in window\system32 but the last example above still working, don't know the reason.
the glut32.dll was in the site http://user.xmission.com/~nate/glut.html
so download from archive.org https://web.archive.org/web/20140331042 ... /glut.html
it is in the package glut-3.7.6-bin.zip (117 KB)

another link:
http://garr.dl.sourceforge.net/project/ ... .6-bin.zip

Re: Render with OpenGL on Ogre screen

Posted: Thu Apr 09, 2015 6:33 pm
by Samuel
Joris wrote:Just trying some of the code above tells me I need the glut32.dll (XP SP3).
Looking through the code above the only glut call I see is glutWireDodecahedron_().
If you comment out this command it should run unless there's another glut call hiding somewhere.

Also the reason glut32.dll is harder to find is because it has been abandoned since the late nineties.
Now a days it seems like Freeglut (glut with some much needed fixes and features) and GLFW are the most popular alternatives.