📄 matsyswin.cpp
字号:
glShadeModel (GL_SMOOTH);
}
*/
}
void DrawBackground()
{
float mTempModel[4][4];
float mTempView[4][4];
g_pMaterialSystem->Bind(g_materialBackground);
g_pMaterialSystem->MatrixMode(MATERIAL_MODEL);
g_pMaterialSystem->GetMatrix(MATERIAL_MODEL, (float*)mTempModel);
g_pMaterialSystem->LoadIdentity();
g_pMaterialSystem->MatrixMode(MATERIAL_VIEW);
g_pMaterialSystem->GetMatrix(MATERIAL_VIEW, (float*)mTempView);
g_pMaterialSystem->LoadIdentity();
{
float dist=-15000.0f;
float tMin=0, tMax=1;
IMesh* pMesh = g_pMaterialSystem->GetDynamicMesh();
CMeshBuilder meshBuilder;
meshBuilder.Begin( pMesh, MATERIAL_QUADS, 1 );
meshBuilder.Position3f(-dist, dist, dist);
meshBuilder.TexCoord2f( 0, tMin,tMax );
meshBuilder.Color4ub( 255, 255, 255, 255 );
meshBuilder.AdvanceVertex();
meshBuilder.Position3f( dist, dist, dist);
meshBuilder.TexCoord2f( 0, tMax,tMax );
meshBuilder.Color4ub( 255, 255, 255, 255 );
meshBuilder.AdvanceVertex();
meshBuilder.Position3f( dist,-dist, dist);
meshBuilder.TexCoord2f( 0, tMax,tMin );
meshBuilder.Color4ub( 255, 255, 255, 255 );
meshBuilder.AdvanceVertex();
meshBuilder.Position3f(-dist,-dist, dist);
meshBuilder.TexCoord2f( 0, tMin,tMin );
meshBuilder.Color4ub( 255, 255, 255, 255 );
meshBuilder.AdvanceVertex();
meshBuilder.End();
pMesh->Draw();
}
g_pMaterialSystem->MatrixMode(MATERIAL_MODEL);
g_pMaterialSystem->LoadMatrix((float*)mTempModel);
g_pMaterialSystem->MatrixMode(MATERIAL_VIEW);
g_pMaterialSystem->LoadMatrix((float*)mTempView);
}
void
MatSysWindow::draw ()
{
g_pMaterialSystem->BeginFrame();
g_pStudioRender->BeginFrame();
g_pMaterialSystem->ClearBuffers(true, true);
g_pMaterialSystem->Viewport( 0, 0, w(), h() );
g_pMaterialSystem->MatrixMode( MATERIAL_PROJECTION );
g_pMaterialSystem->LoadIdentity( );
g_pMaterialSystem->PerspectiveX(65.0f, (float)w() / (float)h(), 1.0f, 20000.0f);
DrawBackground();
/*
glClearColor (g_viewerSettings.bgColor[0], g_viewerSettings.bgColor[1], g_viewerSettings.bgColor[2], 0.0f);
if (g_viewerSettings.useStencil)
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
else
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glViewport (0, 0, w2 (), h2 ());
//
// show textures
//
if (g_viewerSettings.showTexture)
{
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
glOrtho (0.0f, (float) w2 (), (float) h2 (), 0.0f, 1.0f, -1.0f);
studiohdr_t *hdr = g_studioModel.getTextureHeader ();
if (hdr)
{
mstudiotexture_t *ptextures = (mstudiotexture_t *) ((byte *) hdr + hdr->textureindex);
float w = (float) ptextures[g_viewerSettings.texture].width * g_viewerSettings.textureScale;
float h = (float) ptextures[g_viewerSettings.texture].height * g_viewerSettings.textureScale;
glMatrixMode (GL_MODELVIEW);
glPushMatrix ();
glLoadIdentity ();
glDisable (GL_CULL_FACE);
glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
float x = ((float) w2 () - w) / 2;
float y = ((float) h2 () - h) / 2;
glDisable (GL_TEXTURE_2D);
glColor4f (1.0f, 0.0f, 0.0f, 1.0f);
glRectf (x - 2, y - 2, x + w + 2, y + h + 2);
glEnable (GL_TEXTURE_2D);
glColor4f (1.0f, 1.0f, 1.0f, 1.0f);
glBindTexture (GL_TEXTURE_2D, g_viewerSettings.texture + 3); //d_textureNames[0]);
glBegin (GL_TRIANGLE_STRIP);
glTexCoord2f (0, 0);
glVertex2f (x, y);
glTexCoord2f (1, 0);
glVertex2f (x + w, y);
glTexCoord2f (0, 1);
glVertex2f (x, y + h);
glTexCoord2f (1, 1);
glVertex2f (x + w, y + h);
glEnd ();
glPopMatrix ();
glClear (GL_DEPTH_BUFFER_BIT);
glBindTexture (GL_TEXTURE_2D, 0);
}
return;
}
//
// draw background
//
if (g_viewerSettings.showBackground && d_textureNames[0] && !g_viewerSettings.showTexture)
{
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
glOrtho (0.0f, 1.0f, 1.0f, 0.0f, 1.0f, -1.0f);
glMatrixMode (GL_MODELVIEW);
glPushMatrix ();
glLoadIdentity ();
glDisable (GL_CULL_FACE);
glEnable (GL_TEXTURE_2D);
glColor4f (1.0f, 1.0f, 1.0f, 1.0f);
glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
glBindTexture (GL_TEXTURE_2D, d_textureNames[0]);
glBegin (GL_TRIANGLE_STRIP);
glTexCoord2f (0, 0);
glVertex2f (0, 0);
glTexCoord2f (1, 0);
glVertex2f (1, 0);
glTexCoord2f (0, 1);
glVertex2f (0, 1);
glTexCoord2f (1, 1);
glVertex2f (1, 1);
glEnd ();
glPopMatrix ();
glClear (GL_DEPTH_BUFFER_BIT);
glBindTexture (GL_TEXTURE_2D, 0);
}
*/
//g_pMaterialSystem->MatrixMode( MATERIAL_PROJECTION );
//g_pMaterialSystem->LoadIdentity( );
//g_pMaterialSystem->PerspectiveX(65.0f, w() / h(), 1.0f, 4096.0f);
g_pMaterialSystem->MatrixMode( MATERIAL_VIEW );
// g_pMaterialSystem->PushMatrix( );
g_pMaterialSystem->LoadIdentity( );
g_pMaterialSystem->MatrixMode( MATERIAL_MODEL );
g_pMaterialSystem->LoadIdentity( );
// g_pMaterialSystem->Translate( -g_viewerSettings.trans[0], -g_viewerSettings.trans[1], -g_viewerSettings.trans[2]);
// g_pMaterialSystem->Rotate(g_viewerSettings.rot[0], 1.0f, 0.0f, 0.0f);
// g_pMaterialSystem->Rotate(g_viewerSettings.rot[1], 0.0f, 0.0f, 1.0f);
// g_studioModel.DrawModel ();
// g_vright[0] = g_vright[1] = g_viewerSettings.trans[2];
/*
if (g_viewerSettings.mirror)
{
glPushMatrix ();
glScalef (1, 1, -1);
glCullFace (GL_BACK);
setupRenderMode ();
g_studioModel.DrawModel ();
glPopMatrix ();
}
*/
/*
//
// draw ground
//
if (g_viewerSettings.showGround)
{
glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
glEnable (GL_DEPTH_TEST);
glEnable (GL_CULL_FACE);
if (g_viewerSettings.useStencil)
glFrontFace (GL_CW);
else
glDisable (GL_CULL_FACE);
glEnable (GL_BLEND);
if (!d_textureNames[1])
{
glDisable (GL_TEXTURE_2D);
glColor4f (g_viewerSettings.gColor[0], g_viewerSettings.gColor[1], g_viewerSettings.gColor[2], 0.7f);
glBindTexture (GL_TEXTURE_2D, 0);
}
else
{
glEnable (GL_TEXTURE_2D);
glColor4f (1.0f, 1.0f, 1.0f, 0.6f);
glBindTexture (GL_TEXTURE_2D, d_textureNames[1]);
}
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
drawFloor ();
glDisable (GL_BLEND);
if (g_viewerSettings.useStencil)
{
glCullFace (GL_BACK);
glColor4f (0.1f, 0.1f, 0.1f, 1.0f);
glBindTexture (GL_TEXTURE_2D, 0);
drawFloor ();
glFrontFace (GL_CCW);
}
else
glEnable (GL_CULL_FACE);
}
glPopMatrix ();
*/
g_pMaterialSystem->SwapBuffers();
g_pStudioRender->EndFrame();
g_pMaterialSystem->EndFrame();
}
/*
int
MatSysWindow::loadTexture (const char *filename, int name)
{
if (!filename || !strlen (filename))
{
if (d_textureNames[name])
{
glDeleteTextures (1, (const GLuint *) &d_textureNames[name]);
d_textureNames[name] = 0;
if (name == 0)
strcpy (g_viewerSettings.backgroundTexFile, "");
else
strcpy (g_viewerSettings.groundTexFile, "");
}
return 0;
}
mxImage *image = 0;
char ext[16];
strcpy (ext, mx_getextension (filename));
if (!mx_strcasecmp (ext, ".tga"))
image = mxTgaRead (filename);
else if (!mx_strcasecmp (ext, ".pcx"))
image = mxPcxRead (filename);
else if (!mx_strcasecmp (ext, ".bmp"))
image = mxBmpRead (filename);
if (image)
{
if (name == 0)
strcpy (g_viewerSettings.backgroundTexFile, filename);
else
strcpy (g_viewerSettings.groundTexFile, filename);
d_textureNames[name] = name + 1;
if (image->bpp == 8)
{
mstudiotexture_t texture;
texture.width = image->width;
texture.height = image->height;
g_studioModel.UploadTexture (&texture, (byte *) image->data, (byte *) image->palette, name + 1);
}
else
{
glBindTexture (GL_TEXTURE_2D, d_textureNames[name]);
glTexImage2D (GL_TEXTURE_2D, 0, 3, image->width, image->height, 0, GL_RGB, GL_UNSIGNED_BYTE, image->data);
glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
}
delete image;
return name + 1;
}
return 0;
}
*/
/*
void
MatSysWindow::dumpViewport (const char *filename)
{
#ifdef WIN32
redraw ();
int w = w2 ();
int h = h2 ();
mxImage *image = new mxImage ();
if (image->create (w, h, 24))
{
#if 0
glReadBuffer (GL_FRONT);
glReadPixels (0, 0, w, h, GL_RGB, GL_UNSIGNED_BYTE, image->data);
#else
HDC hdc = GetDC ((HWND) getHandle ());
byte *data = (byte *) image->data;
int i = 0;
for (int y = 0; y < h; y++)
{
for (int x = 0; x < w; x++)
{
COLORREF cref = GetPixel (hdc, x, y);
data[i++] = (byte) ((cref >> 0)& 0xff);
data[i++] = (byte) ((cref >> 8) & 0xff);
data[i++] = (byte) ((cref >> 16) & 0xff);
}
}
ReleaseDC ((HWND) getHandle (), hdc);
#endif
if (!mxTgaWrite (filename, image))
mxMessageBox (this, "Error writing screenshot.", g_appTitle, MX_MB_OK | MX_MB_ERROR);
delete image;
}
#endif
}
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -