175 lines
4.6 KiB
C++
175 lines
4.6 KiB
C++
#include "CKAll.h"
|
|
|
|
#include "DrawingPrimitives.h"
|
|
|
|
void
|
|
DrawFillRectangle(CKRenderContext *dev,CKDWORD col,CKMaterial* mat,const VxRect& rect,const VxRect& uvrect,int mode)
|
|
{
|
|
CKDWORD oldfog = dev->GetState(VXRENDERSTATE_FOGENABLE);
|
|
dev->SetState(VXRENDERSTATE_FOGENABLE, FALSE);
|
|
|
|
if (mat) mat->SetAsCurrent(dev);
|
|
else {
|
|
dev->SetTexture(NULL);
|
|
dev->SetState(VXRENDERSTATE_CULLMODE, VXCULL_NONE);
|
|
dev->SetState(VXRENDERSTATE_ZWRITEENABLE , FALSE);
|
|
if (ColorGetAlpha(col) == 255) {
|
|
dev->SetState(VXRENDERSTATE_ALPHABLENDENABLE, FALSE);
|
|
dev->SetState(VXRENDERSTATE_SRCBLEND, VXBLEND_ONE);
|
|
dev->SetState(VXRENDERSTATE_DESTBLEND, VXBLEND_ZERO);
|
|
} else {
|
|
dev->SetState(VXRENDERSTATE_ALPHABLENDENABLE, TRUE);
|
|
dev->SetState(VXRENDERSTATE_SRCBLEND, VXBLEND_SRCALPHA);
|
|
dev->SetState(VXRENDERSTATE_DESTBLEND, VXBLEND_INVSRCALPHA);
|
|
}
|
|
|
|
}
|
|
|
|
VxDrawPrimitiveData* data;
|
|
if(mode & (TRANSFORM|LIGHTING)) data = dev->GetDrawPrimitiveStructure(CKRST_DP_TR_VNT,4);
|
|
else
|
|
if(mode & TRANSFORM) data = dev->GetDrawPrimitiveStructure(CKRST_DP_TR_VCT,4);
|
|
else
|
|
if(mode & LIGHTING) data = dev->GetDrawPrimitiveStructure(CKRST_DP_TR_VNT,4);
|
|
else
|
|
data = dev->GetDrawPrimitiveStructure(CKRST_DP_CL_VCT,4);
|
|
|
|
XPtrStrided<VxUV> uvs = data->TexCoord;
|
|
XPtrStrided<VxVector4> positions= data->Positions;
|
|
XPtrStrided<VxVector> normals = data->Normals;
|
|
XPtrStrided<DWORD> colors = data->Colors;
|
|
|
|
if(mode & LIGHTING) {
|
|
/////////////////
|
|
// Normals
|
|
|
|
// Normal 0
|
|
normals->Set(0 , 0 , 1.0f);
|
|
++normals;
|
|
// Normal 1
|
|
normals->Set(0 , 0 , 1.0f);
|
|
++normals;
|
|
// Normal 2
|
|
normals->Set(0 , 0 , 1.0f);
|
|
++normals;
|
|
// Normal 3
|
|
normals->Set(0 , 0 , 1.0f);
|
|
++normals;
|
|
|
|
} else {
|
|
/////////////////
|
|
// Colors
|
|
VxFillStructure(4,colors,4,&col);
|
|
}
|
|
|
|
/////////////////
|
|
// UVs
|
|
|
|
// Uvs
|
|
uvs[0].Set(uvrect.left , uvrect.top );
|
|
uvs[1].Set(uvrect.right , uvrect.top );
|
|
uvs[2].Set(uvrect.right , uvrect.bottom );
|
|
uvs[3].Set(uvrect.left , uvrect.bottom );
|
|
|
|
/////////////////
|
|
// Positions
|
|
|
|
// Vertex 0
|
|
positions->Set(rect.left , rect.top , 0.0f , 1.0f );
|
|
++positions;
|
|
// Vertex 1
|
|
positions->Set(rect.right , rect.top , 0.0f , 1.0f );
|
|
++positions;
|
|
// Vertex 2
|
|
positions->Set(rect.right , rect.bottom , 0.0f , 1.0f );
|
|
++positions;
|
|
// Vertex 3
|
|
positions->Set(rect.left , rect.bottom , 0.0f , 1.0f );
|
|
++positions;
|
|
|
|
// the drawing itself
|
|
dev->DrawPrimitive( VX_TRIANGLEFAN, (WORD*)0, 4, data );
|
|
|
|
if (oldfog)
|
|
dev->SetState(VXRENDERSTATE_FOGENABLE,oldfog);
|
|
|
|
|
|
}
|
|
|
|
void
|
|
DrawBorderRectangle(CKRenderContext *dev,CKDWORD col,CKMaterial* mat,const VxRect& screen,const float bsize)
|
|
{
|
|
VxRect rect = screen;
|
|
|
|
if (mat) mat->SetAsCurrent(dev);
|
|
else {
|
|
dev->SetTexture(NULL);
|
|
dev->SetState(VXRENDERSTATE_CULLMODE, VXCULL_NONE);
|
|
dev->SetState(VXRENDERSTATE_ZWRITEENABLE , FALSE);
|
|
if (ColorGetAlpha(col) == 255) {
|
|
dev->SetState(VXRENDERSTATE_ALPHABLENDENABLE, FALSE);
|
|
dev->SetState(VXRENDERSTATE_SRCBLEND, VXBLEND_ONE);
|
|
dev->SetState(VXRENDERSTATE_DESTBLEND, VXBLEND_ZERO);
|
|
} else {
|
|
dev->SetState(VXRENDERSTATE_ALPHABLENDENABLE, TRUE);
|
|
dev->SetState(VXRENDERSTATE_SRCBLEND, VXBLEND_SRCALPHA);
|
|
dev->SetState(VXRENDERSTATE_DESTBLEND, VXBLEND_INVSRCALPHA);
|
|
}
|
|
|
|
}
|
|
|
|
VxDrawPrimitiveData* data;
|
|
data = dev->GetDrawPrimitiveStructure(CKRST_DP_CL_VC,8);
|
|
|
|
XPtrStrided<VxVector4> positions= data->Positions;
|
|
|
|
/////////////////
|
|
// Colors
|
|
|
|
VxFillStructure(8,data->Colors,4,&col);
|
|
|
|
/////////////////
|
|
// Positions
|
|
|
|
// Vertex 0
|
|
positions->Set(rect.left , rect.top , 0.0f , 1.0f );
|
|
++positions;
|
|
// Vertex 1
|
|
positions->Set(rect.right , rect.top , 0.0f , 1.0f );
|
|
++positions;
|
|
// Vertex 2
|
|
positions->Set(rect.right , rect.bottom , 0.0f , 1.0f );
|
|
++positions;
|
|
// Vertex 3
|
|
positions->Set(rect.left , rect.bottom , 0.0f , 1.0f );
|
|
++positions;
|
|
|
|
rect.Inflate(Vx2DVector(-bsize,-bsize));
|
|
|
|
positions->Set(rect.left , rect.top , 0.0f , 1.0f );
|
|
++positions;
|
|
// Vertex 1
|
|
positions->Set(rect.right , rect.top , 0.0f , 1.0f );
|
|
++positions;
|
|
// Vertex 2
|
|
positions->Set(rect.right , rect.bottom , 0.0f , 1.0f );
|
|
++positions;
|
|
// Vertex 3
|
|
positions->Set(rect.left , rect.bottom , 0.0f , 1.0f );
|
|
++positions;
|
|
|
|
// Indices
|
|
CKWORD* indices = dev->GetDrawPrimitiveIndices(24);
|
|
indices[0] = 0;indices[1] = 5;indices[2] = 4;
|
|
indices[3] = 5;indices[4] = 0;indices[5] = 1;
|
|
indices[6] = 5;indices[7] = 1;indices[8] = 2;
|
|
indices[9] = 5;indices[10] = 2;indices[11] = 6;
|
|
indices[12] = 6;indices[13] = 2;indices[14] = 3;
|
|
indices[15] = 6;indices[16] = 3;indices[17] = 7;
|
|
indices[18] = 7;indices[19] = 3;indices[20] = 4;
|
|
indices[21] = 4;indices[22] = 3;indices[23] = 0;
|
|
|
|
// the drawing itself
|
|
dev->DrawPrimitive( VX_TRIANGLELIST, indices, 24, data );
|
|
}
|