mirror of
https://github.com/leozide/leocad
synced 2025-01-17 18:11:42 +01:00
Support gradient and texture backgrounds in the preview widget.
This commit is contained in:
parent
55e7cad5e1
commit
5834587204
9 changed files with 132 additions and 113 deletions
|
@ -171,7 +171,7 @@ bool lcApplication::Initialize(int argc, char* argv[], const char* LibraryInstal
|
|||
|
||||
// Image output options.
|
||||
bool SaveImage = false;
|
||||
bool ImageHighlight = false;
|
||||
// bool ImageHighlight = false;
|
||||
int ImageWidth = lcGetProfileInt(LC_PROFILE_IMAGE_WIDTH);
|
||||
int ImageHeight = lcGetProfileInt(LC_PROFILE_IMAGE_HEIGHT);
|
||||
lcStep ImageStart = 0;
|
||||
|
@ -222,8 +222,8 @@ bool lcApplication::Initialize(int argc, char* argv[], const char* LibraryInstal
|
|||
ParseIntegerArgument(&i, argc, argv, &Step);
|
||||
ImageEnd = Step;
|
||||
}
|
||||
else if (strcmp(Param, "--highlight") == 0)
|
||||
ImageHighlight = true;
|
||||
// else if (strcmp(Param, "--highlight") == 0)
|
||||
// ImageHighlight = true;
|
||||
else if ((strcmp(Param, "-v") == 0) || (strcmp(Param, "--version") == 0))
|
||||
{
|
||||
printf("LeoCAD Version " LC_VERSION_TEXT "\n");
|
||||
|
|
|
@ -62,6 +62,19 @@ void lcContext::SetDefaultState()
|
|||
mMatrixMode = GL_MODELVIEW;
|
||||
}
|
||||
|
||||
void lcContext::SetViewport(int x, int y, int Width, int Height)
|
||||
{
|
||||
if (mViewportX == x && mViewportY == y && mViewportWidth == Width && mViewportHeight == Height)
|
||||
return;
|
||||
|
||||
glViewport(x, y, Width, Height);
|
||||
|
||||
mViewportX = x;
|
||||
mViewportY = y;
|
||||
mViewportWidth = Width;
|
||||
mViewportHeight = Height;
|
||||
}
|
||||
|
||||
void lcContext::SetWorldViewMatrix(const lcMatrix44& WorldViewMatrix)
|
||||
{
|
||||
if (mMatrixMode != GL_MODELVIEW)
|
||||
|
|
|
@ -9,8 +9,19 @@ public:
|
|||
lcContext();
|
||||
~lcContext();
|
||||
|
||||
int GetViewportWidth() const
|
||||
{
|
||||
return mViewportWidth;
|
||||
}
|
||||
|
||||
int GetViewportHeight() const
|
||||
{
|
||||
return mViewportHeight;
|
||||
}
|
||||
|
||||
void SetDefaultState();
|
||||
|
||||
void SetViewport(int x, int y, int Width, int Height);
|
||||
void SetWorldViewMatrix(const lcMatrix44& WorldViewMatrix);
|
||||
void SetProjectionMatrix(const lcMatrix44& ProjectionMatrix);
|
||||
// void SetColor(const lcVector4& Color);
|
||||
|
@ -37,6 +48,11 @@ protected:
|
|||
float mLineWidth;
|
||||
int mMatrixMode;
|
||||
|
||||
int mViewportX;
|
||||
int mViewportY;
|
||||
int mViewportWidth;
|
||||
int mViewportHeight;
|
||||
|
||||
GLuint mFramebufferObject;
|
||||
GLuint mFramebufferTexture;
|
||||
GLuint mDepthRenderbufferObject;
|
||||
|
|
|
@ -429,6 +429,91 @@ void lcModel::LoadLDraw(QTextStream& Stream)
|
|||
delete Light;
|
||||
}
|
||||
|
||||
void lcModel::DrawBackground(lcContext* Context)
|
||||
{
|
||||
if (mProperties.mBackgroundType == LC_BACKGROUND_SOLID)
|
||||
{
|
||||
glClearColor(mProperties.mBackgroundSolidColor[0], mProperties.mBackgroundSolidColor[1], mProperties.mBackgroundSolidColor[2], 0.0f);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
return;
|
||||
}
|
||||
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
glDepthMask(GL_FALSE);
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
glDisable(GL_LIGHTING);
|
||||
|
||||
float ViewWidth = (float)Context->GetViewportWidth();
|
||||
float ViewHeight = (float)Context->GetViewportHeight();
|
||||
|
||||
Context->SetProjectionMatrix(lcMatrix44Ortho(0.0f, ViewWidth, 0.0f, ViewHeight, -1.0f, 1.0f));
|
||||
Context->SetWorldViewMatrix(lcMatrix44Translation(lcVector3(0.375f, 0.375f, 0.0f)));
|
||||
|
||||
if (mProperties.mBackgroundType == LC_BACKGROUND_GRADIENT)
|
||||
{
|
||||
glShadeModel(GL_SMOOTH);
|
||||
|
||||
const lcVector3& Color1 = mProperties.mBackgroundGradientColor1;
|
||||
const lcVector3& Color2 = mProperties.mBackgroundGradientColor2;
|
||||
|
||||
float Verts[] =
|
||||
{
|
||||
ViewWidth, ViewHeight, Color1[0], Color1[1], Color1[2], 1.0f,
|
||||
0.0f, ViewHeight, Color1[0], Color1[1], Color1[2], 1.0f,
|
||||
0.0f, 0.0f, Color2[0], Color2[1], Color2[2], 1.0f,
|
||||
ViewWidth, 0.0f, Color2[0], Color2[1], Color2[2], 1.0f
|
||||
};
|
||||
|
||||
glVertexPointer(2, GL_FLOAT, 6 * sizeof(float), Verts);
|
||||
glEnableClientState(GL_COLOR_ARRAY);
|
||||
glColorPointer(4, GL_FLOAT, 6 * sizeof(float), Verts + 2);
|
||||
|
||||
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
|
||||
|
||||
glDisableClientState(GL_COLOR_ARRAY);
|
||||
|
||||
glShadeModel(GL_FLAT);
|
||||
}
|
||||
|
||||
if (mProperties.mBackgroundType == LC_BACKGROUND_IMAGE)
|
||||
{
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
|
||||
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
|
||||
glBindTexture(GL_TEXTURE_2D, mBackgroundTexture->mTexture);
|
||||
|
||||
float TileWidth = 1.0f, TileHeight = 1.0f;
|
||||
|
||||
if (mProperties.mBackgroundImageTile)
|
||||
{
|
||||
TileWidth = ViewWidth / mBackgroundTexture->mWidth;
|
||||
TileHeight = ViewHeight / mBackgroundTexture->mHeight;
|
||||
}
|
||||
|
||||
float Verts[] =
|
||||
{
|
||||
0.0f, ViewHeight, 0.0f, 0.0f,
|
||||
ViewWidth, ViewHeight, TileWidth, 0.0f,
|
||||
ViewWidth, 0.0f, TileWidth, TileHeight,
|
||||
0.0f, 0.0f, 0.0f, TileHeight
|
||||
};
|
||||
|
||||
glVertexPointer(2, GL_FLOAT, 4 * sizeof(float), Verts);
|
||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
glTexCoordPointer(2, GL_FLOAT, 4 * sizeof(float), Verts + 2);
|
||||
|
||||
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
|
||||
|
||||
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
}
|
||||
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glDepthMask(GL_TRUE);
|
||||
}
|
||||
|
||||
void lcModel::UpdateBackgroundTexture()
|
||||
{
|
||||
lcReleaseTexture(mBackgroundTexture);
|
||||
|
|
|
@ -150,6 +150,8 @@ public:
|
|||
void SaveLDraw(QTextStream& Stream) const;
|
||||
void LoadLDraw(QTextStream& Stream);
|
||||
|
||||
void DrawBackground(lcContext* Context);
|
||||
|
||||
void RayTest(lcObjectRayTest& ObjectRayTest) const;
|
||||
void BoxTest(lcObjectBoxTest& ObjectBoxTest) const;
|
||||
|
||||
|
|
|
@ -964,7 +964,9 @@ void MinifigWizard::ParseSettings(lcFile& Settings)
|
|||
void MinifigWizard::OnDraw()
|
||||
{
|
||||
float Aspect = (float)mWidth/(float)mHeight;
|
||||
glViewport(0, 0, mWidth, mHeight);
|
||||
mContext->SetViewport(0, 0, mWidth, mHeight);
|
||||
|
||||
lcGetActiveProject()->DrawBackground(mContext);
|
||||
|
||||
float Box[6] = { 10000, 10000, 10000, -10000, -10000, -10000 };
|
||||
|
||||
|
@ -1042,12 +1044,6 @@ void MinifigWizard::OnDraw()
|
|||
ViewMatrix = lcMatrix44LookAt(Eye * m_Distance, Center, lcVector3(0, 0, 1));
|
||||
}
|
||||
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
float *bg = lcGetActiveProject()->GetBackgroundColor();
|
||||
glClearColor(bg[0], bg[1], bg[2], bg[3]);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
Calculate();
|
||||
|
||||
lcArray<lcRenderMesh> OpaqueMeshes(LC_MFW_NUMITEMS);
|
||||
|
|
|
@ -32,9 +32,11 @@ void PiecePreview::OnDraw()
|
|||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
float aspect = (float)mWidth/(float)mHeight;
|
||||
glViewport(0, 0, mWidth, mHeight);
|
||||
mContext->SetViewport(0, 0, mWidth, mHeight);
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
|
||||
lcGetActiveProject()->DrawBackground(mContext);
|
||||
|
||||
lcVector3 Eye(0.0f, 0.0f, 1.0f);
|
||||
|
||||
Eye = lcMul30(Eye, lcMatrix44RotationX(-m_RotateX * LC_DTOR));
|
||||
|
@ -57,9 +59,6 @@ void PiecePreview::OnDraw()
|
|||
glLoadMatrixf(lcMatrix44LookAt(Eye * m_Distance, m_PieceInfo->GetCenter(), lcVector3(0, 0, 1)));
|
||||
}
|
||||
|
||||
float *bg = lcGetActiveProject()->GetBackgroundColor();
|
||||
glClearColor(bg[0], bg[1], bg[2], bg[3]);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
m_PieceInfo->RenderPiece(gMainWindow->mColorIndex);
|
||||
|
||||
glDisableClientState(GL_VERTEX_ARRAY);
|
||||
|
|
|
@ -722,6 +722,7 @@ bool Project::SaveIfModified()
|
|||
|
||||
switch (QMessageBox::question(gMainWindow->mHandle, tr("Save Project"), tr("Save changes to '%1'?").arg(GetTitle()), QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel))
|
||||
{
|
||||
default:
|
||||
case QMessageBox::Cancel:
|
||||
return false;
|
||||
|
||||
|
@ -878,10 +879,12 @@ void Project::CheckPoint(const char* Description)
|
|||
|
||||
void Project::Render(View* View, bool ToMemory)
|
||||
{
|
||||
View->mContext->SetDefaultState();
|
||||
glViewport(0, 0, View->mWidth, View->mHeight);
|
||||
lcContext* Context = View->mContext;
|
||||
|
||||
RenderBackground(View);
|
||||
Context->SetDefaultState();
|
||||
Context->SetViewport(0, 0, View->mWidth, View->mHeight);
|
||||
|
||||
DrawBackground(Context);
|
||||
|
||||
RenderScenePieces(View, !ToMemory);
|
||||
|
||||
|
@ -891,93 +894,6 @@ void Project::Render(View* View, bool ToMemory)
|
|||
}
|
||||
}
|
||||
|
||||
void Project::RenderBackground(View* View)
|
||||
{
|
||||
lcContext* Context = View->mContext;
|
||||
|
||||
if (mProperties.mBackgroundType == LC_BACKGROUND_SOLID)
|
||||
{
|
||||
glClearColor(mProperties.mBackgroundSolidColor[0], mProperties.mBackgroundSolidColor[1], mProperties.mBackgroundSolidColor[2], 0.0f);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
return;
|
||||
}
|
||||
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
glDepthMask(GL_FALSE);
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
glDisable(GL_LIGHTING);
|
||||
|
||||
float ViewWidth = (float)View->mWidth;
|
||||
float ViewHeight = (float)View->mHeight;
|
||||
|
||||
Context->SetProjectionMatrix(lcMatrix44Ortho(0.0f, ViewWidth, 0.0f, ViewHeight, -1.0f, 1.0f));
|
||||
Context->SetWorldViewMatrix(lcMatrix44Translation(lcVector3(0.375f, 0.375f, 0.0f)));
|
||||
|
||||
if (mProperties.mBackgroundType == LC_BACKGROUND_GRADIENT)
|
||||
{
|
||||
glShadeModel(GL_SMOOTH);
|
||||
|
||||
const lcVector3& Color1 = mProperties.mBackgroundGradientColor1;
|
||||
const lcVector3& Color2 = mProperties.mBackgroundGradientColor2;
|
||||
|
||||
float Verts[] =
|
||||
{
|
||||
ViewWidth, ViewHeight, Color1[0], Color1[1], Color1[2], 1.0f,
|
||||
0.0f, ViewHeight, Color1[0], Color1[1], Color1[2], 1.0f,
|
||||
0.0f, 0.0f, Color2[0], Color2[1], Color2[2], 1.0f,
|
||||
ViewWidth, 0.0f, Color2[0], Color2[1], Color2[2], 1.0f
|
||||
};
|
||||
|
||||
glVertexPointer(2, GL_FLOAT, 6 * sizeof(float), Verts);
|
||||
glEnableClientState(GL_COLOR_ARRAY);
|
||||
glColorPointer(4, GL_FLOAT, 6 * sizeof(float), Verts + 2);
|
||||
|
||||
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
|
||||
|
||||
glDisableClientState(GL_COLOR_ARRAY);
|
||||
|
||||
glShadeModel(GL_FLAT);
|
||||
}
|
||||
|
||||
if (mProperties.mBackgroundType == LC_BACKGROUND_IMAGE)
|
||||
{
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
|
||||
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
|
||||
glBindTexture(GL_TEXTURE_2D, mBackgroundTexture->mTexture);
|
||||
|
||||
float TileWidth = 1.0f, TileHeight = 1.0f;
|
||||
|
||||
if (mProperties.mBackgroundImageTile)
|
||||
{
|
||||
TileWidth = ViewWidth / mBackgroundTexture->mWidth;
|
||||
TileHeight = ViewHeight / mBackgroundTexture->mHeight;
|
||||
}
|
||||
|
||||
float Verts[] =
|
||||
{
|
||||
0.0f, ViewHeight, 0.0f, 0.0f,
|
||||
ViewWidth, ViewHeight, TileWidth, 0.0f,
|
||||
ViewWidth, 0.0f, TileWidth, TileHeight,
|
||||
0.0f, 0.0f, 0.0f, TileHeight
|
||||
};
|
||||
|
||||
glVertexPointer(2, GL_FLOAT, 4 * sizeof(float), Verts);
|
||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
glTexCoordPointer(2, GL_FLOAT, 4 * sizeof(float), Verts + 2);
|
||||
|
||||
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
|
||||
|
||||
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
}
|
||||
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glDepthMask(GL_TRUE);
|
||||
}
|
||||
|
||||
void Project::RenderScenePieces(View* view, bool DrawInterface)
|
||||
{
|
||||
const lcPreferences& Preferences = lcGetPreferences();
|
||||
|
@ -1585,7 +1501,7 @@ void Project::ExportHTML()
|
|||
}
|
||||
|
||||
float aspect = (float)Width/(float)Height;
|
||||
glViewport(0, 0, Width, Height);
|
||||
Context->SetViewport(0, 0, Width, Height);
|
||||
|
||||
for (int PieceIdx = 0; PieceIdx < mPieces.GetSize(); PieceIdx++)
|
||||
{
|
||||
|
|
|
@ -73,19 +73,12 @@ public:
|
|||
CalculateStep();
|
||||
}
|
||||
|
||||
float* GetBackgroundColor() // todo: remove
|
||||
{
|
||||
return mProperties.mBackgroundSolidColor;
|
||||
}
|
||||
|
||||
int GetGroupIndex(lcGroup* Group) const
|
||||
{
|
||||
return mGroups.FindIndex(Group);
|
||||
}
|
||||
|
||||
void UpdateInterface();
|
||||
|
||||
public:
|
||||
void LoadDefaults();
|
||||
void SaveImage();
|
||||
void SaveStepImages(const QString& BaseName, int Width, int Height, lcStep Start, lcStep End);
|
||||
|
@ -104,7 +97,6 @@ protected:
|
|||
|
||||
static int InstanceOfName(const String& existingString, const String& candidateString, String& baseNameOut);
|
||||
|
||||
void RenderBackground(View* view);
|
||||
void RenderScenePieces(View* view, bool DrawInterface);
|
||||
void RenderSceneObjects(View* view);
|
||||
|
||||
|
|
Loading…
Reference in a new issue