Some OpenGL related questions.

Everything related to 3D programming
User avatar
Samuel
Enthusiast
Enthusiast
Posts: 756
Joined: Sun Jul 29, 2012 10:33 pm
Location: United States

Some OpenGL related questions.

Post by Samuel »

I've created a cube with the use of CreateMesh(). When using Direct X9 everything displays properly, but with OpenGL I get some strange effects.

Here's a picture showing it.
Image

First question is do I need to create the meshes differently when using OpenGL?
Maybe you can only create them through OpenGL's commands. I just assumed Purebasic's mesh commands would work with both DirectX and OpenGL.
It would be great if someone could help me with this.

Now for my second question. It looks like OpenGL is trying to light up the cube even though I haven't set any vertex normals.
You can kinda notice it in the picture above. Does OpenGL always try to add light to the entity even without vertex normals?

Here's the code.
I'm using PB 5.2 on Windows 7 x64.

Make sure your subsystem is set to opengl.

Code: Select all


ExamineDesktops()

If InitEngine3D()
Else
  Debug "failed"
EndIf
  InitSprite()
  InitKeyboard()

DesktopW=DesktopWidth(0)
DesktopH=DesktopHeight(0)


If OpenWindow(0, 5, 5, DesktopW, DesktopH, "Test")

  If OpenWindowedScreen(WindowID(0), 0, 0, DesktopW, DesktopH, 0, 0, 0)
    
    Texture=CreateTexture(#PB_Any,8,8)
    StartDrawing(TextureOutput(Texture))
       Box(0,0,8,8,RGB(155,155,155))
    StopDrawing()
    Material=CreateMaterial(#PB_Any,TextureID(Texture))   
    
    
    Mesh=CreateMesh(#PB_Any)
      MeshVertexPosition(2,2,2)
      MeshVertexPosition(2,-2,2)
      MeshVertexPosition(-2,-2,2)
      MeshVertexPosition(-2,2,2)
      MeshVertexPosition(2,2,-2)
      MeshVertexPosition(2,-2,-2)
      MeshVertexPosition(-2,-2,-2)
      MeshVertexPosition(-2,2,-2)
      
      MeshFace(0,2,1)
      MeshFace(0,3,2)
      MeshFace(4,5,6)
      MeshFace(4,6,7)
      MeshFace(0,1,4)
      MeshFace(1,5,4)
      MeshFace(2,3,6)
      MeshFace(3,7,6)
      MeshFace(0,4,3)
      MeshFace(3,4,7)
      MeshFace(1,2,5)
      MeshFace(2,6,5)
    FinishMesh(#True)
    
    CreateEntity(#PB_Any,MeshID(Mesh),MaterialID(Material))
    
    Camera=CreateCamera(#PB_Any,0,0,100,100)
    MoveCamera(Camera,8,0,10,#PB_Absolute)
    CameraLookAt(Camera,0,0,0)
    
    CreateLight(#PB_Any,RGB(255,255,255),2,2,2)
    
  EndIf
EndIf


Repeat
  Event=WaitWindowEvent()   
    If ExamineKeyboard()
      If KeyboardPushed(#PB_Key_Up)
         MoveCamera(Camera, 0, 0, -0.4)
      ElseIf KeyboardPushed(#PB_Key_Down)
         MoveCamera(Camera, 0, 0, 0.4)
      EndIf
      If KeyboardPushed(#PB_Key_Left)
         MoveCamera(Camera, -0.4, 0, 0)
         CameraLookAt(Camera, 0, 0, 0)
      ElseIf KeyboardPushed(#PB_Key_Right)
         MoveCamera(Camera, 0.4, 0, 0)
         CameraLookAt(Camera, 0, 0, 0)
      EndIf
    EndIf
    
  RenderWorld()
  FlipBuffers()
  
Until Event = #PB_Event_CloseWindow Or KeyboardPushed(#PB_Key_Escape)

applePi
Addict
Addict
Posts: 1404
Joined: Sun Jun 25, 2006 7:28 pm

Re: Some OpenGL related questions.

Post by applePi »

Hi Samuel
try the example MeshManual.pb the same behaviour as your example so stick with dx when mesh manual . the same in 5.11 and 4.60 while every thing else other than manual mesh works okay in opengl or dx. thanks for reporting this as i have faced this issue in my example TransformMesh.
but this is not an absolute opinion since my manual meshing below which display A letter works okay the same in dx and opengl .

Code: Select all

InitEngine3D()
InitSprite()
InitKeyboard()
Declare morph()
Global width=20
Global length=20 :Global wireFrame.b = 0
Global i,j,y.f,x.f,z.f,r.f,delta.f = 0.01
ExamineDesktops()
win = OpenWindow(#PB_Any, 0, 0, DesktopWidth(0), DesktopHeight(0), "Press W for wire/solid frame", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(win),0,0,DesktopWidth(0), DesktopHeight(0))
Add3DArchive("/", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Textures", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "Examples/Sources\Data", #PB_3DArchive_FileSystem)

cam=CreateCamera(#PB_Any,0,0,100,100)
MoveCamera(cam,0,20,-15,#PB_Absolute)
CameraLookAt(cam,0,0,0)
;CameraRenderMode(cam,#PB_Camera_Wireframe)
CreateLight(#PB_Any,RGB(255,255,255),0,20,-20)

CreateMaterial(0, LoadTexture(0, "wood.jpg"))
;MaterialShadingMode(0, #PB_Material_Wireframe)
MaterialCullingMode(0, #PB_Material_NoCulling)
DisableMaterialLighting(0, #True)

Define mesh=CreateMesh(#PB_Any,#PB_Mesh_TriangleList ,#PB_Mesh_Dynamic)
SetMeshMaterial(mesh, MaterialID(0))
morph()  ; call mesh construction
node = CreateNode(#PB_Any,0,0,0)
AttachNodeObject(node, MeshID(mesh))
ScaleNode(node, 5, 5, 5)
MoveNode(node,0,1,0)
RotateNode(node,0,90,0)

;oooooooooooooooooooooooooooooooooooooooooooooo

Repeat
  ExamineKeyboard()
  If KeyboardReleased(#PB_Key_W) ; display wire frame for the material
      If wireFrame=0
      MaterialShadingMode(0, #PB_Material_Wireframe)
      wireFrame ! 1
         ElseIf wireFrame=1
           MaterialShadingMode(0, #PB_Material_Solid)
           wireFrame ! 1
      EndIf
   EndIf
    rotx.f+0.5:roty.f+0.5
  ;deciding up or down animation , delta is the rate of morphing  
  If r>=3
    delta = -0.01
  ElseIf r<=-3
    delta = 0.01
  EndIf
  
  r.f = r.f + delta ; decide how much y will be up or down
  UpdateMesh(mesh,0)
  morph() ; call mesh construction
  RotateNode(node,0,roty,0)
  RenderWorld()
  
  FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape) Or WindowEvent() = #PB_Event_CloseWindow
End

Procedure morph()
  
  t=0
  txu.f=0: txv.f=0 ; variables for uv texturing
  For i=-20 To length-1
  For j=-20 To width-1
    x=i:z=j
    x=x*1/15: z=z*1/15  ; because the A generator functions run from -1.3 to 1.3
    ; A generator function
    y = ((1-Sign(-x-0.9+Abs(z*2)))/3*(Sign(0.9-x)+1)/3)*(Sign(x+0.65)+1)/2 -((1-Sign(-x-0.39+Abs(z*2)))/3*(Sign(0.9-x)+1)/3) + ((1-Sign(-x-0.39+Abs(z*2)))/3*(Sign(0.6-x)+1)/3)*(Sign(x-0.35)+1)/2
    ;also try this:
    ;y = 0.75/Exp(Pow((x*5),2)*Pow((z*5),2))  ; ie: 0.75/Exp((x*5)^2*(y*5)^2)
    y = y*r ; r is the morphing factor
    MeshVertexPosition(x,y,z) 
    MeshVertexTextureCoordinate(txu.f, txv.f)
    MeshVertexNormal(x, y, z)
    txv = txv + 1/width ; texture coordinates
  Next j
  txv = 0
  txu = txu + 1/length ; texture coordinates
Next i
t=0
For i = -20 To length-2
  For j = -20 To width-2
          
          MeshFace(t,t+1,t + width*2+1)
          MeshFace(t,t + width*2+1,t + width*2)
          t+1
     Next
     t+1
Next  
FinishMesh(#False)
EndProcedure
marc_256
Addict
Addict
Posts: 859
Joined: Thu May 06, 2010 10:16 am
Location: Belgium
Contact:

Re: Some OpenGL related questions.

Post by marc_256 »

Hi Samuel,

I had have a similar problem here,

http://www.purebasic.fr/english/viewtop ... 36&t=56020

Still having the problem, I'm testing now MPZ 3D Software.

Will see ...

Marc,
- every professional was once an amateur - greetings from Pajottenland - Belgium -
PS: sorry for my english I speak flemish ...
User avatar
Comtois
Addict
Addict
Posts: 1432
Joined: Tue Aug 19, 2003 11:36 am
Location: Doubs - France

Re: Some OpenGL related questions.

Post by Comtois »

Please correct my english
http://purebasic.developpez.com/
User avatar
Danilo
Addict
Addict
Posts: 3036
Joined: Sat Apr 26, 2003 8:26 am
Location: Planet Earth

Re: Some OpenGL related questions.

Post by Danilo »

Samuel wrote:I've created a cube with the use of CreateMesh(). When using Direct X9 everything displays properly, but with OpenGL I get some strange effects.

Here's a picture showing it.
Image

First question is do I need to create the meshes differently when using OpenGL?
The cube is displayed correctly with PB5.20LTS on Mac OS X, using OpenGL by default.

Maybe a bug in PB/Windows with OpenGL subsystem? It should work correctly on all platforms with OpenGL subsystem.
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: Some OpenGL related questions.

Post by IdeasVacuum »

...that's a 2 year old article, has Ogre not moved-on in 2 years? I recall that there are reasons to use OpenGL instead of DX. One is the face count limit, which excludes it's use for large engineering (CAD) models. So, it would be a blow if OpenGL is off limits because Ogre does not have a viable implimentation......
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
User avatar
Samuel
Enthusiast
Enthusiast
Posts: 756
Joined: Sun Jul 29, 2012 10:33 pm
Location: United States

Re: Some OpenGL related questions.

Post by Samuel »

Danilo wrote: The cube is displayed correctly with PB5.20LTS on Mac OS X, using OpenGL by default.

Maybe a bug in PB/Windows with OpenGL subsystem? It should work correctly on all platforms with OpenGL subsystem.
I was kinda thinking it could be a bug too. I would think this would be a huge issue otherwise. Since Mac and Linux both depend on OpenGL.
I'm not saying this is a bug with Purebasic. It could be a bug with how OGRE uses OpenGL on windows.

IdeasVacuum wrote:...that's a 2 year old article, has Ogre not moved-on in 2 years? I recall that there are reasons to use OpenGL instead of DX. One is the face count limit, which excludes it's use for large engineering (CAD) models. So, it would be a blow if OpenGL is off limits because Ogre does not have a viable implimentation......
That article was on OGRE 1.8 and the current version of PB uses 1.8.2 I believe. So even if the OGRE team fixed the issues for 1.9 and 2.0 we don't have access to them yet.
If 1.8 is indeed the problem then we will just have to wait until PB updates to a newer version of OGRE.
PMV
Enthusiast
Enthusiast
Posts: 727
Joined: Sat Feb 24, 2007 3:15 pm
Location: Germany

Re: Some OpenGL related questions.

Post by PMV »

OGRE last stable version is 1.8.2
OGRE latest is 1.9 RC1 (not stable), release April 23, still waiting for next ...
The thread speaks about Google Code of Sommer 2013, that is not long ago:
http://www.ogre3d.org/forums/viewtopic. ... 50#p496178

If the changes will make it in the 1.9, it could be in this year (just a guess!)
If they will only bring it with 2.0 ... expect another year (again, just a guess!)

If you want to be up to date, read that forum regularly and look in there
bug tracker. I have just looked briefly, don't know if i have missed something. :lol:

MFG PMV
User avatar
Samuel
Enthusiast
Enthusiast
Posts: 756
Joined: Sun Jul 29, 2012 10:33 pm
Location: United States

Re: Some OpenGL related questions.

Post by Samuel »

Thanks PMV for that info.

I'll have to check out their bug tracker.
User avatar
Comtois
Addict
Addict
Posts: 1432
Joined: Tue Aug 19, 2003 11:36 am
Location: Doubs - France

Re: Some OpenGL related questions.

Post by Comtois »

PMV wrote:If the changes will make it in the 1.9, it could be in this year (just a guess!)
1.9.0 RC2
Ogre Ghadamon Release Candidate 2
Release date: 13/Oct/13
1.9.0
Ogre Ghadamon
Release date: 10/Nov/13
1.10.0
Ogre [still to be named]
Release date: 31/Dec/13
2.0.0
Ogre Tindalos
No release date
Please correct my english
http://purebasic.developpez.com/
User avatar
Samuel
Enthusiast
Enthusiast
Posts: 756
Joined: Sun Jul 29, 2012 10:33 pm
Location: United States

Re: Some OpenGL related questions.

Post by Samuel »

Thanks Comtois,

If the next stable version of OGRE is out before the next version of Purebasic. Do you think it will be included with PB?
I don't want to put you on the spotlight.
So, If you don't know or you can't tell me that's OK. I was just curious if it was a possibility that it would be included.
PMV
Enthusiast
Enthusiast
Posts: 727
Joined: Sat Feb 24, 2007 3:15 pm
Location: Germany

Re: Some OpenGL related questions.

Post by PMV »

A little more behind the scene information about the versions is given here:
http://www.ogre3d.org/forums/viewtopic. ... 25#p496225

So, it is as i have thought. 8)
Even so it will be a new version ... 1.10 will have the GSoC improvemens
and is targeting end of this year, maybe January if it doesn't go well.
Can't wait! :mrgreen: (hopefully Comtois thinks that, too :twisted: )

@Samuel
as long as fred works fulltime on PB (and that is currently the case)
you can expect regularly updates, and with this ... new version of OGRE
shouldn't take to much time. But there is never an information about,
when that will be ... just be patient. :wink:

MFG PMV
User avatar
Samuel
Enthusiast
Enthusiast
Posts: 756
Joined: Sun Jul 29, 2012 10:33 pm
Location: United States

Re: Some OpenGL related questions.

Post by Samuel »

I was fiddling around with this again and I figured out why ApplePi's example works and mine doesn't.
ApplePi used a Dynamic mesh while I was using a Static mesh. So, the OpenGL bug only seems to happen when creating static manual meshes.

Here's my original example that's now being created as a dynamic mesh.

Code: Select all

ExamineDesktops()

If InitEngine3D()
  InitSprite()
  InitKeyboard()
  
DesktopW=DesktopWidth(0)
DesktopH=DesktopHeight(0)

If OpenWindow(0, 5, 5, DesktopW, DesktopH, "Test")
  If OpenWindowedScreen(WindowID(0), 0, 0, DesktopW, DesktopH, 0, 0, 0)
    
    Texture=CreateTexture(#PB_Any,512,512)
    StartDrawing(TextureOutput(Texture))
       Box(0,0,512,512,RGB(155,155,155))
    StopDrawing()
    Material=CreateMaterial(#PB_Any,TextureID(Texture))   
    ;MaterialCullingMode(Material, #PB_Material_NoCulling)
    DisableMaterialLighting(Material, #True)
    
    Mesh=CreateMesh(#PB_Any,#PB_Mesh_TriangleList ,#PB_Mesh_Dynamic)
      MeshVertexPosition(2,2,2)
      MeshVertexPosition(2,-2,2)
      MeshVertexPosition(-2,-2,2)
      MeshVertexPosition(-2,2,2)
      
      MeshVertexPosition(2,2,-2)
      MeshVertexPosition(2,-2,-2)
      MeshVertexPosition(-2,-2,-2)
      MeshVertexPosition(-2,2,-2)
      
      MeshFace(0,3,1)
      MeshFace(3,2,1)
      MeshFace(4,5,6)
      MeshFace(4,6,7)
      MeshFace(0,1,4)
      MeshFace(1,5,4)
      MeshFace(2,3,6)
      MeshFace(3,7,6)
      MeshFace(0,4,3)
      MeshFace(3,4,7)
      MeshFace(1,2,5)
      MeshFace(2,6,5)
    FinishMesh(#False)
    SetMeshMaterial(Mesh, MaterialID(Material))  
    
    Node = CreateNode(#PB_Any,0,0,0)
    AttachNodeObject(Node, MeshID(mesh))
    
    Camera=CreateCamera(#PB_Any,0,0,100,100)
    MoveCamera(Camera,0,8,13,#PB_Absolute)
    CameraLookAt(Camera,0,0,0)
    
    CreateLight(#PB_Any,RGB(255,255,255),20,20,20)
    
  EndIf
EndIf


Repeat  
  If ExamineKeyboard()
  EndIf
  
  RotateNode(Node,0,1,0,#PB_Relative)
    
  RenderWorld()
  FlipBuffers()
  
Until KeyboardPushed(#PB_Key_Escape) Or WindowEvent() = #PB_Event_CloseWindow
Else
  End
EndIf

applePi
Addict
Addict
Posts: 1404
Joined: Sun Jun 25, 2006 7:28 pm

Re: Some OpenGL related questions.

Post by applePi »

Hi Samuel
upon the light of your last cube code, i have noticed interesting phenomena , if we attached your first cube to the node like you do in the second cube, it will show up in opengl and DX environment. so this is may be of a significance and more investigation, also it will show up in dynamic or static. so without a node the mesh will not show up correctly in opengl in windows os
attached your old cube code but with the cube attached to a node:

Code: Select all

ExamineDesktops()

If InitEngine3D()
Else
  Debug "failed"
EndIf
  InitSprite()
  InitKeyboard()

DesktopW=DesktopWidth(0)
DesktopH=DesktopHeight(0)


If OpenWindow(0, 5, 5, DesktopW, DesktopH, "Test")

  If OpenWindowedScreen(WindowID(0), 0, 0, DesktopW, DesktopH, 0, 0, 0)
    
    Texture=CreateTexture(#PB_Any,8,8)
    StartDrawing(TextureOutput(Texture))
       Box(0,0,8,8,RGB(155,155,155))
    StopDrawing()
    ;Material=CreateMaterial(#PB_Any,TextureID(Texture))   
    ;MaterialShadingMode(Material, #PB_Material_Wireframe)
    ;MaterialCullingMode(Material, #PB_Material_NoCulling)
    ;DisableMaterialLighting(Material, #True)
    
    
    ;Mesh=CreateMesh(#PB_Any)
    Mesh=CreateMesh(#PB_Any,#PB_Mesh_TriangleList ,#PB_Mesh_Static)
      MeshVertexPosition(2,2,2)
      MeshVertexPosition(2,-2,2)
      MeshVertexPosition(-2,-2,2)
      MeshVertexPosition(-2,2,2)
      MeshVertexPosition(2,2,-2)
      MeshVertexPosition(2,-2,-2)
      MeshVertexPosition(-2,-2,-2)
      MeshVertexPosition(-2,2,-2)
      
      MeshFace(0,2,1)
      MeshFace(0,3,2)
      MeshFace(4,5,6)
      MeshFace(4,6,7)
      MeshFace(0,1,4)
      MeshFace(1,5,4)
      MeshFace(2,3,6)
      MeshFace(3,7,6)
      MeshFace(0,4,3)
      MeshFace(3,4,7)
      MeshFace(1,2,5)
      MeshFace(2,6,5)
      
      
    FinishMesh(#False)
    
    Camera=CreateCamera(#PB_Any,0,0,100,100)
    MoveCamera(Camera,8,5,10,#PB_Absolute)
    CameraLookAt(Camera,0,0,0)
    
    CreateLight(#PB_Any,RGB(255,255,255),2,2,2)
    Node = CreateNode(#PB_Any,0,0,0)
    AttachNodeObject(Node, MeshID(Mesh))
    
  EndIf


Repeat  
  If ExamineKeyboard()
  EndIf
  
  RotateNode(Node,0,0.5,0,#PB_Relative)
    
  RenderWorld()
  FlipBuffers()
  
Until KeyboardPushed(#PB_Key_Escape) Or WindowEvent() = #PB_Event_CloseWindow
Else
  End
EndIf
User avatar
Samuel
Enthusiast
Enthusiast
Posts: 756
Joined: Sun Jul 29, 2012 10:33 pm
Location: United States

Re: Some OpenGL related questions.

Post by Samuel »

Hello ApplePi,
You're right about the static mesh. Looks like the bug only happens when the mesh is finished as #True and you try to create an entity with it.
Like in my original example.

Code: Select all

    FinishMesh(#True)
    CreateEntity(#PB_Any,MeshID(Mesh),MaterialID(Material))
Hopefully this bug is fixed in OGRE 1.9.0.
Post Reply