News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Need help with Shadow

Started by Farabi, January 07, 2012, 11:23:39 PM

Previous topic - Next topic

Farabi



fCreateShadowTexture proc w:dword,h:dword
LOCAL textID:dword

invoke Check_Extension,CADD("GL_ARB_shadow")
.if eax==FALSE
invoke MessageBox,0,CADD("Not Support GL_ARB_shadow"),0,0
xor eax,eax
dec eax
.endif

invoke Check_Extension,CADD("GL_ARB_depth_texture")
.if eax==FALSE
invoke MessageBox,0,CADD("Not Support GL_ARB_depth_texture"),0,0
xor eax,eax
dec eax
.endif

invoke glGenTextures,1,addr textID
invoke glBindTexture,GL_TEXTURE_2D,textID
invoke glTexParameteri,GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST;
invoke glTexParameteri,GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST;
invoke glTexParameteri,GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP;
invoke glTexParameteri,GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP;
invoke glTexParameteri,GL_TEXTURE_2D, 0884Ch, 0884Eh;
invoke glTexParameteri,GL_TEXTURE_2D, 0884Dh, GL_LEQUAL;
invoke glTexParameteri,GL_TEXTURE_2D, 0884Bh, GL_INTENSITY;
invoke glTexImage2D,GL_TEXTURE_2D,0,GL_DEPTH_COMPONENT,w,h,0,GL_DEPTH_COMPONENT,GL_UNSIGNED_BYTE,0




mov eax,textID

ret
fCreateShadowTexture endp


fShadowInit proc uses esi edi lpfCamCrnt:dword,lpfCamLght:dword,nTexID:dword

invoke glMatrixMode,GL_MODELVIEW
invoke glLoadIdentity

invoke glShadeModel,GL_SMOOTH
invoke glClearColor,FP4(0.0),FP4(0.0),FP4(0.0),FP4(0.0)
invoke glColor4f,FP4(1.0),FP4(1.0),FP4(1.0),FP4(1.0)
invoke glHint,GL_PERSPECTIVE_CORRECTION_HINT,GL_NICEST

invoke glClearDepth,FP8(1.0)
invoke glDepthFunc,GL_LEQUAL
invoke glEnable,GL_DEPTH_TEST

invoke glEnable,GL_CULL_FACE
invoke glEnable,GL_NORMALIZE


invoke glBindTexture,GL_TEXTURE_2D,nTexID
invoke glColorMaterial,GL_FRONT, GL_AMBIENT_AND_DIFFUSE;
invoke glEnable,GL_COLOR_MATERIAL;
invoke glMaterialfv,GL_FRONT, GL_SPECULAR, addr white;
invoke glMaterialf,GL_FRONT, GL_SHININESS, FP4(16.0);

invoke glPushMatrix
invoke glLoadIdentity

invoke gluPerspective,FP8(45.0),FP8(1.33333333333333),FP8(1.0),FP8(1000000000.0)
invoke glGetFloatv,GL_MODELVIEW_MATRIX,addr cpm
invoke glLoadIdentity
invoke fCameraLook,lpfCamCrnt
invoke glGetFloatv,GL_MODELVIEW_MATRIX,addr cvm


invoke gluPerspective,FP8(45.0),FP8(1.0),FP8(2.0),FP8(8.0)
invoke glGetFloatv,GL_MODELVIEW_MATRIX,addr _lpm
invoke glLoadIdentity
invoke fCameraLook,lpfCamLght
invoke glGetFloatv,GL_MODELVIEW_MATRIX,addr _lvm

invoke glPopMatrix


ret
fShadowInit endp

fShadowBegin proc uses esi edi nTexID:dword
LOCAL ngrnd,nlmp:dword
LOCAL ray:dword
LOCAL fc:fCam
LOCAL mat[16]:dword

invoke glMatrixMode,GL_PROJECTION
invoke glLoadMatrixf,addr _lpm
invoke glMatrixMode,GL_MODELVIEW
invoke glLoadMatrixf,addr _lvm

invoke glViewport,0,0,640,480
invoke glCullFace,GL_FRONT
invoke glShadeModel,GL_FLAT
invoke glColorMask,0,0,0,0
invoke fCameraLook,addr lamp
invoke fSceneDrawAll
invoke glBindTexture,GL_TEXTURE_2D,nTexID
invoke glCopyTexSubImage2D,GL_TEXTURE_2D,0,0,0,0,0,640,480
invoke glCullFace,GL_BACK
invoke glShadeModel,GL_SMOOTH
invoke glColorMask,1,1,1,1

invoke glClear,GL_DEPTH_BUFFER_BIT
invoke glMatrixMode,GL_PROJECTION
invoke glLoadMatrixf,addr cpm
invoke glMatrixMode,GL_MODELVIEW
invoke glLoadMatrixf,addr cvm
invoke glViewport,0,0,640,480

invoke glLightfv,GL_LIGHT1,GL_POSITION,addr lamp
invoke glLightfv,GL_LIGHT1,GL_AMBIENT,addr hwhite
invoke glLightfv,GL_LIGHT1,GL_DIFFUSE,addr hwhite
invoke glLightfv,GL_LIGHT1,GL_SPECULAR,addr black
invoke glEnable,GL_LIGHT1
invoke glEnable,GL_LIGHTING
invoke fCameraLook,addr lamp
invoke fSceneDrawAll


invoke glLightfv,GL_LIGHT1, GL_DIFFUSE, addr white
invoke glLightfv,GL_LIGHT1, GL_SPECULAR, addr white

invoke fMat4fLoadIdentity,addr mat
invoke fFillMatrix4f,addr mat,0,FP4(0.5)
invoke fFillMatrix4f,addr mat,5,FP4(0.5)
invoke fFillMatrix4f,addr mat,10,FP4(0.5)
invoke fFillMatrix4f,addr mat,12,FP4(0.5)
invoke fFillMatrix4f,addr mat,13,FP4(0.5)
invoke fFillMatrix4f,addr mat,14,FP4(0.5)

invoke glPushMatrix
invoke glMatrixMode,GL_MODELVIEW
invoke glLoadMatrixf,addr mat
invoke glMultMatrixf,addr _lpm
invoke glMultMatrixf,addr _lvm
invoke glGetFloatv,GL_MODELVIEW_MATRIX,addr mat
invoke glPopMatrix

; 3Rd Pass
;--------------------------------------------------------------------------------
invoke glTexGeni,GL_S, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR;
invoke glTexGenfv,GL_S, GL_EYE_PLANE, addr mat
invoke glEnable,GL_TEXTURE_GEN_S;

invoke glTexGeni,GL_T, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR;
invoke glTexGenfv,GL_T, GL_EYE_PLANE, addr mat+4
invoke glEnable,GL_TEXTURE_GEN_T;

invoke glTexGeni,GL_R, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR;
invoke glTexGenfv,GL_R, GL_EYE_PLANE, addr mat+8
invoke glEnable,GL_TEXTURE_GEN_R;

invoke glTexGeni,GL_Q, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR;
invoke glTexGenfv,GL_Q, GL_EYE_PLANE, addr mat+12
invoke glEnable,GL_TEXTURE_GEN_Q;

;;Bind & enable shadow map texture
invoke glBindTexture,GL_TEXTURE_2D, nTexID;
invoke glEnable,GL_TEXTURE_2D;

;;Enable shadow comparison
invoke glTexParameteri,GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE_ARB, GL_COMPARE_R_TO_TEXTURE;

;;Shadow comparison should be true ,ie not in shadow, if r<=texture
invoke glTexParameteri,GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC_ARB, GL_LEQUAL;

;;Shadow comparison should generate an INTENSITY result
invoke glTexParameteri,GL_TEXTURE_2D, GL_DEPTH_TEXTURE_MODE_ARB, GL_INTENSITY;

;;Set alpha test to discard false comparisons
invoke glAlphaFunc,GL_GEQUAL, 0.99;
invoke glEnable,GL_ALPHA_TEST;

invoke glDisable,GL_CULL_FACE

invoke fCameraLook,addr lamp
invoke fSceneDrawAll

;;Disable textures and texgen
invoke glDisable,GL_TEXTURE_2D;

invoke glDisable,GL_TEXTURE_GEN_S;
invoke glDisable,GL_TEXTURE_GEN_T;
invoke glDisable,GL_TEXTURE_GEN_R;
invoke glDisable,GL_TEXTURE_GEN_Q;

;;Restore other states
invoke glDisable,GL_LIGHTING;
invoke glDisable,GL_ALPHA_TEST;



ret
fShadowBegin endp



I never get it to work, can anyone tell me where is my mistake? Thanks.  :dazzled:
Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"