- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我从 OpenGL superbile 第 5 版中获取了这个程序。我按照他们在书中所说的设置了所有内容,包括路径以及项目的现有项目。
然后我在项目中创建了一个新的c++文件并复制了我从官方网站下载的粘贴代码。
// Block.cpp
// OpenGL SuperBible, Chapter 1
// Demonstrates an assortment of basic 3D concepts
// Program by Richard S. Wright Jr.
#include <GLTools.h> // OpenGL toolkit
#include <GLMatrixStack.h>
#include <GLFrame.h>
#include <GLFrustum.h>
#include <GLBatch.h>
#include <GLGeometryTransform.h>
#include <math.h>
#ifdef __APPLE__
#include <glut/glut.h>
#else
#define FREEGLUT_STATIC
#include <GL/glut.h>
#endif
/////////////////////////////////////////////////////////////////////////////////
// An assortment of needed classes
GLShaderManager shaderManager;
GLMatrixStack modelViewMatrix;
GLMatrixStack projectionMatrix;
GLFrame cameraFrame;
GLFrustum viewFrustum;
GLBatch cubeBatch;
GLBatch floorBatch;
GLBatch topBlock;
GLBatch frontBlock;
GLBatch leftBlock;
GLGeometryTransform transformPipeline;
M3DMatrix44f shadowMatrix;
// Keep track of effects step
int nStep = 0;
// Lighting data
GLfloat lightAmbient[] = { 0.2f, 0.2f, 0.2f, 1.0f };
GLfloat lightDiffuse[] = { 0.7f, 0.7f, 0.7f, 1.0f };
GLfloat lightSpecular[] = { 0.9f, 0.9f, 0.9f };
GLfloat vLightPos[] = { -8.0f, 20.0f, 100.0f, 1.0f };
GLuint textures[4];
///////////////////////////////////////////////////////////////////////////////
// Make a cube out of a batch of triangles. Texture coordinates and normals
// are also provided.
void MakeCube(GLBatch& cubeBatch)
{
cubeBatch.Begin(GL_TRIANGLES, 36, 1);
/////////////////////////////////////////////
// Top of cube
cubeBatch.Normal3f(0.0f, 1.0f, 0.0f);
cubeBatch.MultiTexCoord2f(0, 1.0f, 1.0f);
cubeBatch.Vertex3f(1.0f, 1.0f, 1.0f);
cubeBatch.Normal3f(0.0f, 1.0f, 0.0f);
cubeBatch.MultiTexCoord2f(0, 1.0f, 0.0f);
cubeBatch.Vertex3f(1.0f, 1.0f, -1.0f);
cubeBatch.Normal3f(0.0f, 1.0f, 0.0f);
cubeBatch.MultiTexCoord2f(0, 0.0f, 0.0f);
cubeBatch.Vertex3f(-1.0f, 1.0f, -1.0f);
cubeBatch.Normal3f(0.0f, 1.0f, 0.0f);
cubeBatch.MultiTexCoord2f(0, 1.0f, 1.0f);
cubeBatch.Vertex3f(1.0f, 1.0f, 1.0f);
cubeBatch.Normal3f(0.0f, 1.0f, 0.0f);
cubeBatch.MultiTexCoord2f(0, 0.0f, 0.0f);
cubeBatch.Vertex3f(-1.0f, 1.0f, -1.0f);
cubeBatch.Normal3f(0.0f, 1.0f, 0.0f);
cubeBatch.MultiTexCoord2f(0, 0.0f, 1.0f);
cubeBatch.Vertex3f(-1.0f, 1.0f, 1.0f);
////////////////////////////////////////////
// Bottom of cube
cubeBatch.Normal3f(0.0f, -1.0f, 0.0f);
cubeBatch.MultiTexCoord2f(0, 0.0f, 0.0f);
cubeBatch.Vertex3f(-1.0f, -1.0f, -1.0f);
cubeBatch.Normal3f(0.0f, -1.0f, 0.0f);
cubeBatch.MultiTexCoord2f(0, 1.0f, 0.0f);
cubeBatch.Vertex3f(1.0f, -1.0f, -1.0f);
cubeBatch.Normal3f(0.0f, -1.0f, 0.0f);
cubeBatch.MultiTexCoord2f(0, 1.0f, 1.0f);
cubeBatch.Vertex3f(1.0f, -1.0f, 1.0f);
cubeBatch.Normal3f(0.0f, -1.0f, 0.0f);
cubeBatch.MultiTexCoord2f(0, 0.0f, 1.0f);
cubeBatch.Vertex3f(-1.0f, -1.0f, 1.0f);
cubeBatch.Normal3f(0.0f, -1.0f, 0.0f);
cubeBatch.MultiTexCoord2f(0, 0.0f, 0.0f);
cubeBatch.Vertex3f(-1.0f, -1.0f, -1.0f);
cubeBatch.Normal3f(0.0f, -1.0f, 0.0f);
cubeBatch.MultiTexCoord2f(0, 1.0f, 1.0f);
cubeBatch.Vertex3f(1.0f, -1.0f, 1.0f);
///////////////////////////////////////////
// Left side of cube
cubeBatch.Normal3f(-1.0f, 0.0f, 0.0f);
cubeBatch.MultiTexCoord2f(0, 1.0f, 1.0f);
cubeBatch.Vertex3f(-1.0f, 1.0f, 1.0f);
cubeBatch.Normal3f(-1.0f, 0.0f, 0.0f);
cubeBatch.MultiTexCoord2f(0, 1.0f, 0.0f);
cubeBatch.Vertex3f(-1.0f, 1.0f, -1.0f);
cubeBatch.Normal3f(-1.0f, 0.0f, 0.0f);
cubeBatch.MultiTexCoord2f(0, 0.0f, 0.0f);
cubeBatch.Vertex3f(-1.0f, -1.0f, -1.0f);
cubeBatch.Normal3f(-1.0f, 0.0f, 0.0f);
cubeBatch.MultiTexCoord2f(0, 1.0f, 1.0f);
cubeBatch.Vertex3f(-1.0f, 1.0f, 1.0f);
cubeBatch.Normal3f(-1.0f, 0.0f, 0.0f);
cubeBatch.MultiTexCoord2f(0, 0.0f, 0.0f);
cubeBatch.Vertex3f(-1.0f, -1.0f, -1.0f);
cubeBatch.Normal3f(-1.0f, 0.0f, 0.0f);
cubeBatch.MultiTexCoord2f(0, 0.0f, 1.0f);
cubeBatch.Vertex3f(-1.0f, -1.0f, 1.0f);
// Right side of cube
cubeBatch.Normal3f(1.0f, 0.0f, 0.0f);
cubeBatch.MultiTexCoord2f(0, 0.0f, 0.0f);
cubeBatch.Vertex3f(1.0f, -1.0f, -1.0f);
cubeBatch.Normal3f(1.0f, 0.0f, 0.0f);
cubeBatch.MultiTexCoord2f(0, 1.0f, 0.0f);
cubeBatch.Vertex3f(1.0f, 1.0f, -1.0f);
cubeBatch.Normal3f(1.0f, 0.0f, 0.0f);
cubeBatch.MultiTexCoord2f(0, 1.0f, 1.0f);
cubeBatch.Vertex3f(1.0f, 1.0f, 1.0f);
cubeBatch.Normal3f(1.0f, 0.0f, 0.0f);
cubeBatch.MultiTexCoord2f(0, 1.0f, 1.0f);
cubeBatch.Vertex3f(1.0f, 1.0f, 1.0f);
cubeBatch.Normal3f(1.0f, 0.0f, 0.0f);
cubeBatch.MultiTexCoord2f(0, 0.0f, 1.0f);
cubeBatch.Vertex3f(1.0f, -1.0f, 1.0f);
cubeBatch.Normal3f(1.0f, 0.0f, 0.0f);
cubeBatch.MultiTexCoord2f(0, 0.0f, 0.0f);
cubeBatch.Vertex3f(1.0f, -1.0f, -1.0f);
// Front and Back
// Front
cubeBatch.Normal3f(0.0f, 0.0f, 1.0f);
cubeBatch.MultiTexCoord2f(0, 1.0f, 0.0f);
cubeBatch.Vertex3f(1.0f, -1.0f, 1.0f);
cubeBatch.Normal3f(0.0f, 0.0f, 1.0f);
cubeBatch.MultiTexCoord2f(0, 1.0f, 1.0f);
cubeBatch.Vertex3f(1.0f, 1.0f, 1.0f);
cubeBatch.Normal3f(0.0f, 0.0f, 1.0f);
cubeBatch.MultiTexCoord2f(0, 0.0f, 1.0f);
cubeBatch.Vertex3f(-1.0f, 1.0f, 1.0f);
cubeBatch.Normal3f(0.0f, 0.0f, 1.0f);
cubeBatch.MultiTexCoord2f(0, 0.0f, 1.0f);
cubeBatch.Vertex3f(-1.0f, 1.0f, 1.0f);
cubeBatch.Normal3f(0.0f, 0.0f, 1.0f);
cubeBatch.MultiTexCoord2f(0, 0.0f, 0.0f);
cubeBatch.Vertex3f(-1.0f, -1.0f, 1.0f);
cubeBatch.Normal3f(0.0f, 0.0f, 1.0f);
cubeBatch.MultiTexCoord2f(0, 1.0f, 0.0f);
cubeBatch.Vertex3f(1.0f, -1.0f, 1.0f);
// Back
cubeBatch.Normal3f(0.0f, 0.0f, -1.0f);
cubeBatch.MultiTexCoord2f(0, 1.0f, 0.0f);
cubeBatch.Vertex3f(1.0f, -1.0f, -1.0f);
cubeBatch.Normal3f(0.0f, 0.0f, -1.0f);
cubeBatch.MultiTexCoord2f(0, 0.0f, 0.0f);
cubeBatch.Vertex3f(-1.0f, -1.0f, -1.0f);
cubeBatch.Normal3f(0.0f, 0.0f, -1.0f);
cubeBatch.MultiTexCoord2f(0, 0.0f, 1.0f);
cubeBatch.Vertex3f(-1.0f, 1.0f, -1.0f);
cubeBatch.Normal3f(0.0f, 0.0f, -1.0f);
cubeBatch.MultiTexCoord2f(0, 0.0f, 1.0f);
cubeBatch.Vertex3f(-1.0f, 1.0f, -1.0f);
cubeBatch.Normal3f(0.0f, 0.0f, -1.0f);
cubeBatch.MultiTexCoord2f(0, 1.0f, 1.0f);
cubeBatch.Vertex3f(1.0f, 1.0f, -1.0f);
cubeBatch.Normal3f(0.0f, 0.0f, -1.0f);
cubeBatch.MultiTexCoord2f(0, 1.0f, 0.0f);
cubeBatch.Vertex3f(1.0f, -1.0f, -1.0f);
cubeBatch.End();
}
/////////////////////////////////////////////////////////////////////////////
// Make the floor, just the verts and texture coordinates, no normals
void MakeFloor(GLBatch& floorBatch)
{
GLfloat x = 5.0f;
GLfloat y = -1.0f;
floorBatch.Begin(GL_TRIANGLE_FAN, 4, 1);
floorBatch.MultiTexCoord2f(0, 0.0f, 0.0f);
floorBatch.Vertex3f(-x, y, x);
floorBatch.MultiTexCoord2f(0, 1.0f, 0.0f);
floorBatch.Vertex3f(x, y, x);
floorBatch.MultiTexCoord2f(0, 1.0f, 1.0f);
floorBatch.Vertex3f(x, y, -x);
floorBatch.MultiTexCoord2f(0, 0.0f, 1.0f);
floorBatch.Vertex3f(-x, y, -x);
floorBatch.End();
}
///////////////////////////////////////////////////////////////////////////////
// This function does any needed initialization on the rendering context.
// This is the first opportunity to do any OpenGL related tasks.
void SetupRC()
{
GLbyte *pBytes;
GLint nWidth, nHeight, nComponents;
GLenum format;
shaderManager.InitializeStockShaders();
// Black background
glClearColor(0.0f, 0.0f, 0.0f, 1.0f );
glEnable(GL_DEPTH_TEST);
glLineWidth(2.5f);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
transformPipeline.SetMatrixStacks(modelViewMatrix, projectionMatrix);
cameraFrame.MoveForward(-15.0f);
cameraFrame.MoveUp(6.0f);
cameraFrame.RotateLocalX(float(m3dDegToRad(20.0f)));
MakeCube(cubeBatch);
MakeFloor(floorBatch);
// Make top
topBlock.Begin(GL_TRIANGLE_FAN, 4, 1);
topBlock.Normal3f(0.0f, 1.0f, 0.0f);
topBlock.MultiTexCoord2f(0, 0.0f, 0.0f);
topBlock.Vertex3f(-1.0f, 1.0f, 1.0f);
topBlock.Normal3f(0.0f, 1.0f, 0.0f);
topBlock.MultiTexCoord2f(0, 1.0f, 0.0f);
topBlock.Vertex3f(1.0f, 1.0f, 1.0f);
topBlock.Normal3f(0.0f, 1.0f, 0.0f);
topBlock.MultiTexCoord2f(0, 1.0f, 1.0f);
topBlock.Vertex3f(1.0f, 1.0f, -1.0f);
topBlock.Normal3f(0.0f, 1.0f, 0.0f);
topBlock.MultiTexCoord2f(0, 0.0f, 1.0f);
topBlock.Vertex3f(-1.0f, 1.0f, -1.0f);
topBlock.End();
// Make Front
frontBlock.Begin(GL_TRIANGLE_FAN, 4, 1);
frontBlock.Normal3f(0.0f, 0.0f, 1.0f);
frontBlock.MultiTexCoord2f(0, 0.0f, 0.0f);
frontBlock.Vertex3f(-1.0f, -1.0f, 1.0f);
frontBlock.Normal3f(0.0f, 0.0f, 1.0f);
frontBlock.MultiTexCoord2f(0, 1.0f, 0.0f);
frontBlock.Vertex3f(1.0f, -1.0f, 1.0f);
frontBlock.Normal3f(0.0f, 0.0f, 1.0f);
frontBlock.MultiTexCoord2f(0, 1.0f, 1.0f);
frontBlock.Vertex3f(1.0f, 1.0f, 1.0f);
frontBlock.Normal3f(0.0f, 0.0f, 1.0f);
frontBlock.MultiTexCoord2f(0, 0.0f, 1.0f);
frontBlock.Vertex3f(-1.0f, 1.0f, 1.0f);
frontBlock.End();
// Make left
leftBlock.Begin(GL_TRIANGLE_FAN, 4, 1);
leftBlock.Normal3f(-1.0f, 0.0f, 0.0f);
leftBlock.MultiTexCoord2f(0, 0.0f, 0.0f);
leftBlock.Vertex3f(-1.0f, -1.0f, -1.0f);
leftBlock.Normal3f(-1.0f, 0.0f, 0.0f);
leftBlock.MultiTexCoord2f(0, 1.0f, 0.0f);
leftBlock.Vertex3f(-1.0f, -1.0f, 1.0f);
leftBlock.Normal3f(-1.0f, 0.0f, 0.0f);
leftBlock.MultiTexCoord2f(0, 1.0f, 1.0f);
leftBlock.Vertex3f(-1.0f, 1.0f, 1.0f);
leftBlock.Normal3f(-1.0f, 0.0f, 0.0f);
leftBlock.MultiTexCoord2f(0, 0.0f, 1.0f);
leftBlock.Vertex3f(-1.0f, 1.0f, -1.0f);
leftBlock.End();
// Create shadow projection matrix
GLfloat floorPlane[] = { 0.0f, 1.0f, 0.0f, 1.0f};
m3dMakePlanarShadowMatrix(shadowMatrix, floorPlane, vLightPos);
// Load up four textures
glGenTextures(4, textures);
// Wood floor
pBytes = gltReadTGABits("floor.tga", &nWidth, &nHeight, &nComponents, &format);
glBindTexture(GL_TEXTURE_2D, textures[0]);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexImage2D(GL_TEXTURE_2D,0,nComponents,nWidth, nHeight, 0,
format, GL_UNSIGNED_BYTE, pBytes);
free(pBytes);
// One of the block faces
pBytes = gltReadTGABits("Block4.tga", &nWidth, &nHeight, &nComponents, &format);
glBindTexture(GL_TEXTURE_2D, textures[1]);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexImage2D(GL_TEXTURE_2D,0,nComponents,nWidth, nHeight, 0,
format, GL_UNSIGNED_BYTE, pBytes);
free(pBytes);
// Another block face
pBytes = gltReadTGABits("block5.tga", &nWidth, &nHeight, &nComponents, &format);
glBindTexture(GL_TEXTURE_2D, textures[2]);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexImage2D(GL_TEXTURE_2D,0,nComponents,nWidth, nHeight, 0,
format, GL_UNSIGNED_BYTE, pBytes);
free(pBytes);
// Yet another block face
pBytes = gltReadTGABits("block6.tga", &nWidth, &nHeight, &nComponents, &format);
glBindTexture(GL_TEXTURE_2D, textures[3]);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexImage2D(GL_TEXTURE_2D,0,nComponents,nWidth, nHeight, 0,
format, GL_UNSIGNED_BYTE, pBytes);
free(pBytes);
}
///////////////////////////////////////////////////////////////////////////////
// Render the block
void RenderBlock(void)
{
GLfloat vRed[] = { 1.0f, 0.0f, 0.0f, 1.0f};
GLfloat vWhite[] = { 1.0f, 1.0f, 1.0f, 1.0f };
switch(nStep)
{
// Wire frame
case 0:
glEnable(GL_BLEND);
glEnable(GL_LINE_SMOOTH);
shaderManager.UseStockShader(GLT_SHADER_FLAT, transformPipeline.GetModelViewProjectionMatrix(), vRed);
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
glDisable(GL_CULL_FACE);
// Draw the cube
cubeBatch.Draw();
break;
// Wire frame, but not the back side... we also want the block to be in the stencil buffer
case 1:
shaderManager.UseStockShader(GLT_SHADER_FLAT, transformPipeline.GetModelViewProjectionMatrix(), vRed);
// Draw solid block in stencil buffer
// Back face culling prevents the back sides from showing through
// The stencil pattern is used to mask when we draw the floor under it
// to keep it from showing through.
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
glEnable(GL_STENCIL_TEST);
glStencilFunc(GL_NEVER, 0, 0);
glStencilOp(GL_INCR, GL_INCR, GL_INCR);
cubeBatch.Draw();
glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
glDisable(GL_STENCIL_TEST);
glEnable(GL_BLEND);
glEnable(GL_LINE_SMOOTH);
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
// Draw the front side cube
cubeBatch.Draw();
break;
// Solid
case 2:
shaderManager.UseStockShader(GLT_SHADER_FLAT, transformPipeline.GetModelViewProjectionMatrix(), vRed);
// Draw the cube
cubeBatch.Draw();
break;
// Lit
case 3:
shaderManager.UseStockShader(GLT_SHADER_POINT_LIGHT_DIFF, modelViewMatrix.GetMatrix(),
projectionMatrix.GetMatrix(), vLightPos, vRed);
// Draw the cube
cubeBatch.Draw();
break;
// Textured & Lit
case 4:
case 5:
default:
glBindTexture(GL_TEXTURE_2D, textures[2]);
shaderManager.UseStockShader(GLT_SHADER_TEXTURE_POINT_LIGHT_DIFF, modelViewMatrix.GetMatrix(),
projectionMatrix.GetMatrix(), vLightPos, vWhite, 0);
glBindTexture(GL_TEXTURE_2D, textures[1]);
topBlock.Draw();
glBindTexture(GL_TEXTURE_2D, textures[2]);
frontBlock.Draw();
glBindTexture(GL_TEXTURE_2D, textures[3]);
leftBlock.Draw();
break;
}
// Put everything back
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
glEnable(GL_CULL_FACE);
glDisable(GL_BLEND);
glDisable(GL_LINE_SMOOTH);
glDisable(GL_STENCIL_TEST);
}
///////////////////////////////////////////////////////////////////////////////
// Render the floor
void RenderFloor(void)
{
GLfloat vBrown [] = { 0.55f, 0.292f, 0.09f, 1.0f};
GLfloat vFloor[] = { 1.0f, 1.0f, 1.0f, 0.6f };
switch(nStep)
{
// Wire frame
case 0:
glEnable(GL_BLEND);
glEnable(GL_LINE_SMOOTH);
shaderManager.UseStockShader(GLT_SHADER_FLAT, transformPipeline.GetModelViewProjectionMatrix(), vBrown);
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
glDisable(GL_CULL_FACE);
break;
// Wire frame, but not the back side.. and only where stencil == 0
case 1:
glEnable(GL_BLEND);
glEnable(GL_LINE_SMOOTH);
glEnable(GL_STENCIL_TEST);
glStencilFunc(GL_EQUAL, 0, 0xff);
shaderManager.UseStockShader(GLT_SHADER_FLAT, transformPipeline.GetModelViewProjectionMatrix(), vBrown);
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
break;
// Solid
case 2:
case 3:
shaderManager.UseStockShader(GLT_SHADER_FLAT, transformPipeline.GetModelViewProjectionMatrix(), vBrown);
break;
// Textured
case 4:
case 5:
default:
glBindTexture(GL_TEXTURE_2D, textures[0]);
shaderManager.UseStockShader(GLT_SHADER_TEXTURE_MODULATE, transformPipeline.GetModelViewProjectionMatrix(), vFloor, 0);
break;
}
// Draw the floor
floorBatch.Draw();
// Put everything back
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
glEnable(GL_CULL_FACE);
glDisable(GL_BLEND);
glDisable(GL_LINE_SMOOTH);
glDisable(GL_STENCIL_TEST);
}
///////////////////////////////////////////////////////////////////////////////
// Called to draw scene
void RenderScene(void)
{
// Clear the window with current clearing color
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
modelViewMatrix.PushMatrix();
M3DMatrix44f mCamera;
cameraFrame.GetCameraMatrix(mCamera);
modelViewMatrix.MultMatrix(mCamera);
// Reflection step... draw cube upside down, the floor
// blended on top of it
if(nStep == 5) {
glDisable(GL_CULL_FACE);
modelViewMatrix.PushMatrix();
modelViewMatrix.Scale(1.0f, -1.0f, 1.0f);
modelViewMatrix.Translate(0.0f, 2.0f, 0.0f);
modelViewMatrix.Rotate(35.0f, 0.0f, 1.0f, 0.0f);
RenderBlock();
modelViewMatrix.PopMatrix();
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
RenderFloor();
glDisable(GL_BLEND);
}
modelViewMatrix.PushMatrix();
// Draw normally
modelViewMatrix.Rotate(35.0f, 0.0f, 1.0f, 0.0f);
RenderBlock();
modelViewMatrix.PopMatrix();
// If not the reflection pass, draw floor last
if(nStep != 5)
RenderFloor();
modelViewMatrix.PopMatrix();
// Flush drawing commands
glutSwapBuffers();
}
///////////////////////////////////////////////////////////////////////////////
// A normal ASCII key has been pressed.
// In this case, advance the scene when the space bar is pressed
void KeyPressFunc(unsigned char key, int x, int y)
{
if(key == 32)
{
nStep++;
if(nStep > 5)
nStep = 0;
}
// Refresh the Window
glutPostRedisplay();
}
///////////////////////////////////////////////////////////////////////////////
// Window has changed size, or has just been created. In either case, we need
// to use the window dimensions to set the viewport and the projection matrix.
void ChangeSize(int w, int h)
{
glViewport(0, 0, w, h);
viewFrustum.SetPerspective(35.0f, float(w) / float(h), 1.0f, 500.0f);
projectionMatrix.LoadMatrix(viewFrustum.GetProjectionMatrix());
modelViewMatrix.LoadIdentity();
}
///////////////////////////////////////////////////////////////////////////////
// Main entry point for GLUT based programs
int main(int argc, char* argv[])
{
gltSetWorkingDirectory(argv[0]);
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH | GLUT_STENCIL);
glutInitWindowSize(800, 600);
glutCreateWindow("3D Effects Demo");
GLenum err = glewInit();
if (GLEW_OK != err)
{
/* Problem: glewInit failed, something is seriously wrong. */
fprintf(stderr, "Error: %s\n", glewGetErrorString(err));
return 1;
}
glutReshapeFunc(ChangeSize);
glutKeyboardFunc(KeyPressFunc);
glutDisplayFunc(RenderScene);
SetupRC();
glutMainLoop();
glDeleteTextures(4,textures);
return 0;
}
我调试程序(我使用 visual C++ 2008,我得到以下错误:
1>------ Build started: Project: meow, Configuration: Debug Win32 ------
1>Linking...
1>..\..\..\..\..\SB5\VisualStudio2008\GLTools\gltools.lib : fatal error LNK1107: invalid or corrupt file: cannot read at 0x13B5
1>Build log was saved at "file://c:\Users\sripriya\Downloads\Documents\Visual Studio 2008\Projects\meow\meow\Debug\BuildLog.htm"
1>meow - 1 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
我不明白,因为我很好地链接了 gltools,它出现在项目名称下的子列表中。为什么会这样?
编辑:现在当我运行时我得到了这个
1>------ Build started: Project: meow, Configuration: Debug Win32 ------
1>Linking...
1>LINK : error LNK2001: unresolved external symbol _mainCRTStartup
1>C:\Users\sripriya\Downloads\Documents\Visual Studio 2008\Projects\meow\Debug\meow.exe : fatal error LNK1120: 1 unresolved externals
1>Build log was saved at "file://c:\Users\sripriya\Downloads\Documents\Visual Studio 2008\Projects\meow\meow\Debug\BuildLog.htm"
1>meow - 2 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
我一点头绪都没有!
注意:GlTools 是作为 vc++ 项目而不是库添加的,我应该添加 extension.lib 吗?我试过仍然有同样的错误,未解决我不知道是什么....
1>------ Build started: Project: meow2, Configuration: Debug Win32 ------
1>Compiling...
1>gt.cpp
1>c:\users\sripriya\downloads\documents\visual studio 2008\projects\meow2\meow2\gt.cpp(6) : fatal error C1083: Cannot open include file: 'GLTools.h': No such file or directory
1>Build log was saved at "file://c:\Users\sripriya\Downloads\Documents\Visual Studio 2008\Projects\meow2\meow2\Debug\BuildLog.htm"
1>meow2 - 1 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
最佳答案
您需要从解决方案资源管理器中右键单击您的项目 -> 属性 -> 链接器 -> 系统并确保子系统设置为控制台。
关于c++ - 无法运行 Opengl 程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17632340/
#include using namespace std; class C{ private: int value; public: C(){ value = 0;
这个问题已经有答案了: What is the difference between char a[] = ?string?; and char *p = ?string?;? (8 个回答) 已关闭
关闭。此题需要details or clarity 。目前不接受答案。 想要改进这个问题吗?通过 editing this post 添加详细信息并澄清问题. 已关闭 7 年前。 此帖子已于 8 个月
除了调试之外,是否有任何针对 c、c++ 或 c# 的测试工具,其工作原理类似于将独立函数复制粘贴到某个文本框,然后在其他文本框中输入参数? 最佳答案 也许您会考虑单元测试。我推荐你谷歌测试和谷歌模拟
我想在第二台显示器中移动一个窗口 (HWND)。问题是我尝试了很多方法,例如将分辨率加倍或输入负值,但它永远无法将窗口放在我的第二台显示器上。 关于如何在 C/C++/c# 中执行此操作的任何线索 最
我正在寻找 C/C++/C## 中不同类型 DES 的现有实现。我的运行平台是Windows XP/Vista/7。 我正在尝试编写一个 C# 程序,它将使用 DES 算法进行加密和解密。我需要一些实
很难说出这里要问什么。这个问题模棱两可、含糊不清、不完整、过于宽泛或夸夸其谈,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开,visit the help center . 关闭 1
有没有办法强制将另一个 窗口置于顶部? 不是应用程序的窗口,而是另一个已经在系统上运行的窗口。 (Windows, C/C++/C#) 最佳答案 SetWindowPos(that_window_ha
假设您可以在 C/C++ 或 Csharp 之间做出选择,并且您打算在 Windows 和 Linux 服务器上运行同一服务器的多个实例,那么构建套接字服务器应用程序的最明智选择是什么? 最佳答案 如
你们能告诉我它们之间的区别吗? 顺便问一下,有什么叫C++库或C库的吗? 最佳答案 C++ 标准库 和 C 标准库 是 C++ 和 C 标准定义的库,提供给 C++ 和 C 程序使用。那是那些词的共同
下面的测试代码,我将输出信息放在注释中。我使用的是 gcc 4.8.5 和 Centos 7.2。 #include #include class C { public:
很难说出这里问的是什么。这个问题是含糊的、模糊的、不完整的、过于宽泛的或修辞性的,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开它,visit the help center 。 已关
我的客户将使用名为 annoucement 的结构/类与客户通信。我想我会用 C++ 编写服务器。会有很多不同的类继承annoucement。我的问题是通过网络将这些类发送给客户端 我想也许我应该使用
我在 C# 中有以下函数: public Matrix ConcatDescriptors(IList> descriptors) { int cols = descriptors[0].Co
我有一个项目要编写一个函数来对某些数据执行某些操作。我可以用 C/C++ 编写代码,但我不想与雇主共享该函数的代码。相反,我只想让他有权在他自己的代码中调用该函数。是否可以?我想到了这两种方法 - 在
我使用的是编写糟糕的第 3 方 (C/C++) Api。我从托管代码(C++/CLI)中使用它。有时会出现“访问冲突错误”。这使整个应用程序崩溃。我知道我无法处理这些错误[如果指针访问非法内存位置等,
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 我们不允许提问寻求书籍、工具、软件库等的推荐。您可以编辑问题,以便用事实和引用来回答。 关闭 7 年前。
已关闭。此问题不符合Stack Overflow guidelines 。目前不接受答案。 要求我们推荐或查找工具、库或最喜欢的场外资源的问题对于 Stack Overflow 来说是偏离主题的,因为
我有一些 C 代码,将使用 P/Invoke 从 C# 调用。我正在尝试为这个 C 函数定义一个 C# 等效项。 SomeData* DoSomething(); struct SomeData {
这个问题已经有答案了: Why are these constructs using pre and post-increment undefined behavior? (14 个回答) 已关闭 6
我是一名优秀的程序员,十分优秀!