Page 1 of 1

VertexColor & Light

Posted: Sun Sep 08, 2013 8:29 am
by Phantomas
Hello. I have that code:

Code: Select all

EnableExplicit

Procedure error(error_num.i)
  Debug "error"
  Debug error_num
  End
EndProcedure

Enumeration
  #window
  
  ;3D
  #texture
  #material
  #camera  
EndEnumeration

#window_w = 640
#window_h = 480
#window_title = "CLIPViewer"

;3D Options
#FPS = 60
#mouse_speed = 0.2
#camera_speed = 0.5

#texture_w = 32
#texture_h = 32
#texture_color = 16750130
#fog_color = 10526880
#for_intensity = 1
#fog_start = 128
#fog_end = 1024
#axis_color = 65535

Procedure.i mouse()  
  Protected MouseX.f = - MouseDeltaX() / 6; * #mouse_speed
  Protected MouseY.f = - MouseDeltaY() / 6; * #mouse_speed
  RotateCamera(#camera, MouseY, MouseX, 0, #PB_Relative)
EndProcedure

Procedure.i keyboard()  
  Protected cam_forward_backward.f
  Protected cam_leftward_rightward.f
  
  If KeyboardPushed(#PB_Key_W)
    cam_forward_backward = - #camera_speed
  ElseIf KeyboardPushed(#PB_Key_S)
    cam_forward_backward = #camera_speed
  Else
    cam_forward_backward = 0
  EndIf
  
  If KeyboardPushed(#PB_Key_A)
    cam_leftward_rightward = - #camera_speed
  ElseIf KeyboardPushed(#PB_Key_D)
    cam_leftward_rightward = #camera_speed
  Else
    cam_leftward_rightward = 0
  EndIf
  
  If KeyboardPushed(#PB_Key_LeftShift) 
    cam_forward_backward * 10
    cam_leftward_rightward * 10
  EndIf
  
  MoveCamera(#camera, cam_leftward_rightward, 0, cam_forward_backward)
EndProcedure

Procedure.i create_axis()
  CreateLine3D(#PB_Any, 0, 0, 0, #axis_color, 5, 0, 0, #axis_color)
  CreateLine3D(#PB_Any, 0, 0, 0, #axis_color, 0, 5, 0, #axis_color)
  CreateLine3D(#PB_Any, 0, 0, 0, #axis_color, 0, 0, 5, #axis_color)
  
  Protected cube.i = CreateCube(#PB_Any, 5)
  CreateEntity(#PB_Any, MeshID(cube), MaterialID(#material))
EndProcedure

If InitEngine3D() = 0
  error(0)
Else
  If InitSprite() = 0
    error(1)
  Else
    If InitKeyboard() = 0
      error(2)
    Else
      If InitMouse() = 0
        error(3)
      Else
        If OpenWindow(#window, #PB_Ignore, #PB_Ignore, #window_w, #window_h, #window_title, #PB_Window_SystemMenu | #PB_Window_ScreenCentered) = 0
          error(4)
        Else
          If OpenWindowedScreen(WindowID(#window), 0, 0, #window_w, #window_h, 0, 0, 0, #PB_Screen_NoSynchronization) = 0
            error(5)
          Else
            SetFrameRate(#FPS)
            If CreateTexture(#texture, 32, 32) = 0
              error(6)
            Else
              If StartDrawing(TextureOutput(#texture)) = 0
                error(7)
              Else
                Box(0, 0, #texture_w, #texture_h, #texture_color)
                StopDrawing()
                If CreateMaterial(#material, TextureID(#texture)) = 0
                  error(8)
                Else
                  CreateCamera(#camera, 0, 0, 100, 100)
                  MoveCamera(#camera, 0, 5, -20)
                  RotateCamera(#camera, 0, 180, 0)
                 
                  ;Fog(#fog_color, #for_intensity, #fog_start, #fog_end)
                  ;MaterialShadingMode(#material,  #PB_Material_Phong       | #PB_Material_Wireframe)
                  create_axis()
                  
                  Define current_mesh.i = CreateMesh(#PB_Any, #PB_Mesh_TriangleFan, #PB_Mesh_Static)
                  MeshVertexPosition(0, 0, 0)
                  MeshVertexColor(RGB(Random(255),Random(255),Random(255)))
                  MeshVertexPosition(-5, 5, 0)
                  MeshVertexColor(RGB(Random(255),Random(255),Random(255)))
                  MeshVertexPosition(-3, 7, 0)
                  MeshVertexColor(RGB(Random(255),Random(255),Random(255)))
                  MeshVertexPosition(0, 10, 0)
                  MeshVertexColor(RGB(Random(255),Random(255),Random(255)))
                  MeshVertexPosition(3, 7, 0)
                  MeshVertexColor(RGB(Random(255),Random(255),Random(255)))
                  MeshVertexPosition(5, 5, 0)
                  MeshVertexColor(RGB(Random(255),Random(255),Random(255)))
                  FinishMesh(1)
                  CreateEntity(#PB_Any, MeshID(current_mesh), MaterialID(#material))
                  
                  CreateLight(#PB_Any, RGB(255, 0, 0), 10, 10, 0)
                  
                  Repeat
                    Select WaitWindowEvent()
                      Case #PB_Event_CloseWindow
                        Break
                      Default
                        ExamineKeyboard()
                        keyboard()
                        ExamineMouse()
                        mouse()
                        RenderWorld()
                        FlipBuffers()
                        If KeyboardPushed(#PB_Key_Escape) <> 0
                          Break
                        EndIf
                    EndSelect
                  ForEver
                EndIf   
              EndIf
            EndIf
          EndIf
        EndIf
      EndIf
    EndIf
  EndIf
EndIf
Two questions:
  • Why MeshVertexColor() does not work?
  • Why CreateLight() does not work (no shadows)?

Re: VertexColor & Light

Posted: Sun Sep 08, 2013 1:37 pm
by Phantomas
If I add:

Code: Select all

WorldShadows(#PB_Shadow_Modulative)
After OpenWindowedScreen() function, I got error:
Image
What is wrong?

Log:

Code: Select all

00:38:47: Creating resource group General
00:38:47: Creating resource group Internal
00:38:47: Creating resource group Autodetect
00:38:47: SceneManagerFactory for type 'DefaultSceneManager' registered.
00:38:47: Registering ResourceManager for type Material
00:38:47: Registering ResourceManager for type Mesh
00:38:47: Registering ResourceManager for type Skeleton
00:38:47: MovableObjectFactory for type 'ParticleSystem' registered.
00:38:47: OverlayElementFactory for type Panel registered.
00:38:47: OverlayElementFactory for type BorderPanel registered.
00:38:47: OverlayElementFactory for type TextArea registered.
00:38:47: Registering ResourceManager for type Font
00:38:47: ArchiveFactory for archive type FileSystem registered.
00:38:47: ArchiveFactory for archive type Zip registered.
00:38:47: ArchiveFactory for archive type EmbeddedZip registered.
00:38:47: DDS codec registering
00:38:47: FreeImage version: 3.10.0
00:38:47: This program uses FreeImage, a free, open source image library supporting all common bitmap formats. See http://freeimage.sourceforge.net for details
00:38:47: Supported formats: bmp,ico,jpg,jif,jpeg,jpe,koa,iff,lbm,pbm,pbm,pcd,pcx,pgm,pgm,png,ppm,ppm,ras,tga,targa,tif,tiff,wap,wbmp,wbm,psd,cut,xbm,xpm,dds,gif,g3,sgi,j2k,j2c,jp2
00:38:47: PVRTC codec registering
00:38:47: Registering ResourceManager for type HighLevelGpuProgram
00:38:47: Registering ResourceManager for type Compositor
00:38:47: MovableObjectFactory for type 'Entity' registered.
00:38:47: MovableObjectFactory for type 'Light' registered.
00:38:47: MovableObjectFactory for type 'BillboardSet' registered.
00:38:47: MovableObjectFactory for type 'ManualObject' registered.
00:38:47: MovableObjectFactory for type 'BillboardChain' registered.
00:38:47: MovableObjectFactory for type 'RibbonTrail' registered.
00:38:47: *-*-* OGRE Initialising
00:38:47: *-*-* Version 1.8.2 (Byatis)
00:38:47: D3D9 : Direct3D9 Rendering Subsystem created.
00:38:47: D3D9: Driver Detection Starts
00:38:47: D3D9: Driver Detection Ends
00:38:47: OpenGL Rendering Subsystem created.
00:38:47: Particle Emitter Type 'Point' registered
00:38:47: Particle Emitter Type 'Box' registered
00:38:47: Particle Emitter Type 'Ellipsoid' registered
00:38:47: Particle Emitter Type 'Cylinder' registered
00:38:47: Particle Emitter Type 'Ring' registered
00:38:47: Particle Emitter Type 'HollowEllipsoid' registered
00:38:47: Particle Affector Type 'LinearForce' registered
00:38:47: Particle Affector Type 'ColourFader' registered
00:38:47: Particle Affector Type 'ColourFader2' registered
00:38:47: Particle Affector Type 'ColourImage' registered
00:38:47: Particle Affector Type 'ColourInterpolator' registered
00:38:47: Particle Affector Type 'Scaler' registered
00:38:47: Particle Affector Type 'Rotator' registered
00:38:47: Particle Affector Type 'DirectionRandomiser' registered
00:38:47: Particle Affector Type 'DeflectorPlane' registered
00:38:47: PCZone Factory Type 'ZoneType_Default' registered
00:38:47: CPU Identifier & Features
00:38:47: -------------------------
00:38:47:  *   CPU ID: GenuineIntel: Intel(R) Core(TM) i3-3110M CPU @ 2.40GHz
00:38:47:  *      SSE: yes
00:38:47:  *     SSE2: yes
00:38:47:  *     SSE3: yes
00:38:47:  *      MMX: yes
00:38:47:  *   MMXEXT: yes
00:38:47:  *    3DNOW: no
00:38:47:  * 3DNOWEXT: no
00:38:47:  *     CMOV: yes
00:38:47:  *      TSC: yes
00:38:47:  *      FPU: yes
00:38:47:  *      PRO: yes
00:38:47:  *       HT: no
00:38:47: -------------------------
00:38:47: D3D9 : Subsystem Initialising
00:38:47: Registering ResourceManager for type Texture
00:38:47: Registering ResourceManager for type GpuProgram
00:38:47: ***************************************
00:38:47: *** D3D9 : Subsystem Initialised OK ***
00:38:47: ***************************************
00:38:47: SceneManagerFactory for type 'OctreeSceneManager' registered.
00:38:47: SceneManagerFactory for type 'BspSceneManager' registered.
00:38:47: Registering ResourceManager for type BspLevel
00:38:48: D3D9RenderSystem::_createRenderWindow "PureBasic Ogre", 640x480 windowed  miscParams: FSAA=0 displayFrequency=0 externalWindowHandle=2032242 vsync=false 
00:38:48: D3D9 : Created D3D9 Rendering Window 'PureBasic Ogre' : 640x480, 32bpp
00:38:48: D3D9 : WARNING - disabling VSync in windowed mode can cause timing issues at lower frame rates, turn VSync on if you observe this problem.
00:38:48: D3D9: Vertex texture format supported - PF_A8R8G8B8
00:38:48: D3D9: Vertex texture format supported - PF_B8G8R8A8
00:38:48: D3D9: Vertex texture format supported - PF_FLOAT16_RGB
00:38:48: D3D9: Vertex texture format supported - PF_FLOAT16_RGBA
00:38:48: D3D9: Vertex texture format supported - PF_FLOAT32_RGB
00:38:48: D3D9: Vertex texture format supported - PF_FLOAT32_RGBA
00:38:48: D3D9: Vertex texture format supported - PF_R8G8B8A8
00:38:48: D3D9: Vertex texture format supported - PF_DEPTH
00:38:48: D3D9: Vertex texture format supported - PF_FLOAT16_R
00:38:48: D3D9: Vertex texture format supported - PF_FLOAT32_R
00:38:48: D3D9: Vertex texture format supported - PF_FLOAT16_GR
00:38:48: D3D9: Vertex texture format supported - PF_FLOAT32_GR
00:38:48: D3D9: Vertex texture format supported - PF_PVRTC_RGB2
00:38:48: D3D9: Vertex texture format supported - PF_PVRTC_RGBA2
00:38:48: D3D9: Vertex texture format supported - PF_PVRTC_RGB4
00:38:48: D3D9: Vertex texture format supported - PF_PVRTC_RGBA4
00:38:48: D3D9: Vertex texture format supported - PF_R8
00:38:48: D3D9: Vertex texture format supported - PF_RG8
00:38:48: RenderSystem capabilities
00:38:48: -------------------------
00:38:48: RenderSystem Name: Direct3D9 Rendering Subsystem
00:38:48: GPU Vendor: nvidia
00:38:48: Device Name: Monitor-1-NVIDIA GeForce 610M
00:38:48: Driver Version: 9.18.13.1422
00:38:48:  * Fixed function pipeline: yes
00:38:48:  * Hardware generation of mipmaps: yes
00:38:48:  * Texture blending: yes
00:38:48:  * Anisotropic texture filtering: yes
00:38:48:  * Dot product texture operation: yes
00:38:48:  * Cube mapping: yes
00:38:48:  * Hardware stencil buffer: yes
00:38:48:    - Stencil depth: 8
00:38:48:    - Two sided stencil support: yes
00:38:48:    - Wrap stencil values: yes
00:38:48:  * Hardware vertex / index buffers: yes
00:38:48:  * Vertex programs: yes
00:38:48:  * Number of floating-point constants for vertex programs: 256
00:38:48:  * Number of integer constants for vertex programs: 16
00:38:48:  * Number of boolean constants for vertex programs: 16
00:38:48:  * Fragment programs: yes
00:38:48:  * Number of floating-point constants for fragment programs: 224
00:38:48:  * Number of integer constants for fragment programs: 16
00:38:48:  * Number of boolean constants for fragment programs: 16
00:38:48:  * Geometry programs: no
00:38:48:  * Number of floating-point constants for geometry programs: 8192
00:38:48:  * Number of integer constants for geometry programs: 8312
00:38:48:  * Number of boolean constants for geometry programs: 14388
00:38:48:  * Supported Shader Profiles: hlsl ps_1_1 ps_1_2 ps_1_3 ps_1_4 ps_2_0 ps_2_a ps_2_b ps_2_x ps_3_0 vs_1_1 vs_2_0 vs_2_a vs_2_x vs_3_0
00:38:48:  * Texture Compression: yes
00:38:48:    - DXT: yes
00:38:48:    - VTC: no
00:38:48:    - PVRTC: no
00:38:48:  * Scissor Rectangle: yes
00:38:48:  * Hardware Occlusion Query: yes
00:38:48:  * User clip planes: yes
00:38:48:  * VET_UBYTE4 vertex element type: yes
00:38:48:  * Infinite far plane projection: yes
00:38:48:  * Hardware render-to-texture: yes
00:38:48:  * Floating point textures: yes
00:38:48:  * Non-power-of-two textures: yes
00:38:48:  * Volume textures: yes
00:38:48:  * Multiple Render Targets: 4
00:38:48:    - With different bit depths: yes
00:38:48:  * Point Sprites: yes
00:38:48:  * Extended point parameters: yes
00:38:48:  * Max Point Size: 8192
00:38:48:  * Vertex texture fetch: yes
00:38:48:  * Number of world matrices: 0
00:38:48:  * Number of texture units: 8
00:38:48:  * Stencil buffer depth: 8
00:38:48:  * Number of vertex blend matrices: 0
00:38:48:    - Max vertex textures: 4
00:38:48:    - Vertex textures shared: no
00:38:48:  * Render to Vertex Buffer : no
00:38:48:  * DirectX per stage constants: yes
00:38:48: DefaultWorkQueue('Root') initialising on thread main.
00:38:48: Particle Renderer Type 'billboard' registered

Re: VertexColor & Light

Posted: Sun Sep 08, 2013 1:52 pm
by Num3
Do you have the latest DirectX 9 version installed for your system?

Get the latest here http://filehippo.com/download_directx/

By the error window style I think you're on windows 2000.

Re: VertexColor & Light

Posted: Sun Sep 08, 2013 2:02 pm
by Phantomas
Num3 wrote:Do you have the latest DirectX 9 version installed for your system?

Get the latest here http://filehippo.com/download_directx/

By the error window style I think you're on windows 2000.
I have DirectX 11. Windows 7.
In default "StaticGeometry.pb" example — all is okay, I can see shadows. But, if I try enable shadows in code above — I got error.

Re: VertexColor & Light

Posted: Sun Sep 08, 2013 2:08 pm
by Num3
I always install DX9 side by side with DX11, give it a try, some dll might be needed from DX9 version.

Re: VertexColor & Light

Posted: Sun Sep 08, 2013 2:15 pm
by Phantomas
Num3 wrote:I always install DX9 side by side with DX11, give it a try, some dll might be needed from DX9 version.
If you add:

Code: Select all

WorldShadows(#PB_Shadow_Modulative)
In my code () — it's works for you? No critical error?

Re: VertexColor & Light

Posted: Sun Sep 08, 2013 2:55 pm
by Phantomas
So, I found reason of error, this code:

Code: Select all

                  Define current_mesh.i = CreateMesh(#PB_Any, #PB_Mesh_TriangleFan, #PB_Mesh_Static)
                  MeshVertexPosition(0, 0, 0)
                  MeshVertexColor(RGB(Random(255),Random(255),Random(255)))
                  MeshVertexPosition(-5, 5, 0)
                  MeshVertexColor(RGB(Random(255),Random(255),Random(255)))
                  MeshVertexPosition(-3, 7, 0)
                  MeshVertexColor(RGB(Random(255),Random(255),Random(255)))
                  MeshVertexPosition(0, 10, 0)
                  MeshVertexColor(RGB(Random(255),Random(255),Random(255)))
                  MeshVertexPosition(3, 7, 0)
                  MeshVertexColor(RGB(Random(255),Random(255),Random(255)))
                  MeshVertexPosition(5, 5, 0)
                  MeshVertexColor(RGB(Random(255),Random(255),Random(255)))
                  FinishMesh(1)
                  CreateEntity(#PB_Any, MeshID(current_mesh), MaterialID(#material))
Anyone known why?

Re: VertexColor & Light

Posted: Sun Sep 08, 2013 3:04 pm
by Num3
Yes the code works without any errors, if i remember correctly that error happens because some dependency is not installed in your system!

Re: VertexColor & Light

Posted: Sun Sep 08, 2013 5:24 pm
by Comtois
Phantomas wrote:If you add:

Code: Select all

WorldShadows(#PB_Shadow_Modulative)
In my code () — it's works for you? No critical error?
It crash, yes.
---------------------------
Microsoft Visual C++ Runtime Library
---------------------------
Assertion failed!

Program: ...
File: z:\ogre\ogremain\include\OgreSharedPtr.h
Line: 160

Expression: pRep

For information on how your program can cause an assertion
failure, see the Visual C++ documentation on asserts

(Press Retry to debug the application - JIT must be enabled)
---------------------------
Abandonner Recommencer Ignorer
---------------------------
Need to do some research about this bug (CreateMesh(#PB_Any, #PB_Mesh_TriangleFan, #PB_Mesh_Static)).

for color , add this

Code: Select all

DisableMaterialLighting(#material, 1)

Re: VertexColor & Light

Posted: Sun Sep 08, 2013 5:57 pm
by Comtois
If you convert mesh to a static mesh (FinishMesh(1)) you need to add index.

Code: Select all

Define current_mesh.i = CreateMesh(#PB_Any, #PB_Mesh_TriangleFan, #PB_Mesh_Static)
MeshVertexPosition(0, 0, 0)
MeshVertexColor(RGB(Random(255),Random(255),Random(255)))
MeshVertexPosition(-5, 5, 0)
MeshVertexColor(RGB(Random(255),Random(255),Random(255)))
MeshVertexPosition(-3, 7, 0)
MeshVertexColor(RGB(Random(255),Random(255),Random(255)))
MeshVertexPosition(0, 10, 0)
MeshVertexColor(RGB(Random(255),Random(255),Random(255)))
MeshVertexPosition(3, 7, 0)
MeshVertexColor(RGB(Random(255),Random(255),Random(255)))
MeshVertexPosition(5, 5, 0)
MeshVertexColor(RGB(Random(255),Random(255),Random(255)))
MeshIndex(0)
MeshIndex(1)
MeshIndex(2)
MeshIndex(3)
MeshIndex(4)
MeshIndex(5)
FinishMesh(1)
If you dont convert your mesh (FinishMesh(0)), it work like this

Code: Select all

Define current_mesh.i = CreateMesh(#PB_Any, #PB_Mesh_TriangleFan, #PB_Mesh_Static)
MeshVertexPosition(0, 0, 0)
MeshVertexColor(RGB(Random(255),Random(255),Random(255)))
MeshVertexPosition(-5, 5, 0)
MeshVertexColor(RGB(Random(255),Random(255),Random(255)))
MeshVertexPosition(-3, 7, 0)
MeshVertexColor(RGB(Random(255),Random(255),Random(255)))
MeshVertexPosition(0, 10, 0)
MeshVertexColor(RGB(Random(255),Random(255),Random(255)))
MeshVertexPosition(3, 7, 0)
MeshVertexColor(RGB(Random(255),Random(255),Random(255)))
MeshVertexPosition(5, 5, 0)
MeshVertexColor(RGB(Random(255),Random(255),Random(255)))

FinishMesh(0)

CreateNode(0)
SetMeshMaterial(current_mesh, MaterialID(#material))
AttachNodeObject(0, MeshID(current_mesh))