Hi
i'm trying to light a textured sphere with two lights , red light from right and green light from left, the problem is that i think i must use for the texture something like this:
MP_MaterialEmissiveColor (Texture,255,255,0,0)
MP_MaterialDiffuseColor (Texture,255,255,0,0)
to be able to light the right side a red color
but what about the left side which should be colored green and so the midpoint between left and right should be gradually yellow.
i have experimented with the "MP_Alphablending" example from MP3D and this is the picture of the result:
the texture have an alpha channel ,the code and the texture "ministones.tga" can be downloaded from here:
http://www.mediafire.com/?ets2eew6e2egt6x
Code: Select all
MP_Graphics3D (640,480,0,3)
SetWindowTitle(0, "Alpha Blending test: Key 1,2,3,4")
camera=MP_CreateCamera()
light=MP_CreateLight(2)
light2=MP_CreateLight(2)
MP_PositionEntity (light,-6,0,3)
MP_LightSetColor(light,RGB(0,255,0))
MP_EntityLookAt(light,0,0,3)
MP_PositionEntity (light2,6,0,3)
MP_LightSetColor(light2,RGB(255,0,0))
MP_EntityLookAt(light2,0,0,3)
sphere=MP_CreateSphere(16)
Texture = MP_LoadTexture("ministones.tga",1)
;MP_MaterialSpecularColor(Texture,255,0,255,128,1)
MP_MaterialEmissiveColor (Texture,255,255,0,0)
MP_MaterialDiffuseColor (Texture,255,255,0,0)
;MP_MaterialEmissiveColor (Texture,255,0,255,0)
;MP_MaterialDiffuseColor (Texture,255,0,255,0)
MP_PositionEntity (sphere,0,0,3)
MP_EntitySetTexture (sphere, Texture)
MP_MeshSetAlpha (sphere,2)
While Not MP_KeyDown(#PB_Key_Escape) And Not WindowEvent() = #PB_Event_CloseWindow
If MP_KeyDown(#PB_Key_1)=1 : MP_MeshSetAlpha (sphere,0): EndIf ; Normalmodus aktiv
If MP_KeyDown(#PB_Key_2)=1 : MP_MeshSetAlpha (sphere,1): MP_EntitySetTexture(sphere, Texture) : EndIf ; Alphamodus 1 ohne Alphakanal
If MP_KeyDown(#PB_Key_3)=1 : MP_MeshSetAlpha (sphere,1): MP_EntitySetTexture(sphere, Texture) : EndIf ; Alphamodus 1
If MP_KeyDown(#PB_Key_4)=1 : MP_MeshSetAlpha (sphere,2): MP_EntitySetTexture(sphere, Texture) : EndIf ; Alphamodus 2
If MP_KeyDown(#PB_Key_5)=1 : MP_MeshSetAlpha (sphere,3): MP_EntitySetTexture(sphere, Texture) : EndIf ; Alphamodus 3
If MP_KeyDown(#PB_Key_6)=1 : MP_MeshSetAlpha (sphere,3): MP_EntitySetTexture(sphere, Texture) : EndIf ; Alphamodus 3
If MP_KeyDown(#PB_Key_7)=1 : MP_MeshSetAlpha (sphere,4): MP_EntitySetTexture(sphere, Texture) : EndIf ; Alphamodus 4
If MP_KeyDown(#PB_Key_8)=1 : MP_MeshSetAlpha (sphere,1): MP_EntitySetTexture(sphere, Texture) : MP_CreateTextureAlpha(Texture, Texture):EndIf ; Alphamodus 2
MP_TurnEntity (sphere,0.05,0.5,1)
MP_MeshAlphaSort(1)
MP_RenderWorld ()
MP_Flip ()
Wend
on the other hand here is an equivalent opengl program "lesson 18" which i have downloaded it years ago from :
http://purebasic.developpez.com/sources/ look 3D section
i have changed it to make a left and right green, red light. it is more correctly displaying the two lights on the texture as in this image

rotate the sphere with keys, the source with the texture are found in the same mediafire download above. you must disable the debugger before run.
i never remeber the complexities of opengl, i just have used the available example to demonstrate my issue.
even the opengl example are not completely correct since the inner side on the texture on the sphere must reflect the color of the opposite light
regards