本文整理汇总了C++中Terrain::Draw方法的典型用法代码示例。如果您正苦于以下问题:C++ Terrain::Draw方法的具体用法?C++ Terrain::Draw怎么用?C++ Terrain::Draw使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Terrain
的用法示例。
在下文中一共展示了Terrain::Draw方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: draw
void Viewer::draw()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClearColor(backgroundCol.x(), backgroundCol.y(), backgroundCol.z(), 1.0f);
if (mySky.wantSky())
mySky.Render( );
glEnable(GL_LIGHTING);
if (applyGLSL)
{
glEnable(GL_VERTEX_PROGRAM_ARB);
glEnable(GL_FRAGMENT_PROGRAM_ARB);
light.position[3] = 1;
light.setLight();
}
else{
light.position[3] = 0;
light.setLight();
}
QVector4D ltmp(light.position[0],light.position[1],light.position[2],light.position[3]);
ltmp.normalize();
GLfloat lpos[4] = {ltmp.x(),ltmp.y(),ltmp.z(),ltmp.w()};
glProgramEnvParameter4fvARB(GL_FRAGMENT_PROGRAM_ARB, 1, lpos);
// Draws a terrain
if (curTerr>=0 && curTerr<terrains.size()){
Terrain * terrain = terrains[curTerr];
if (applyTexture) glBindTexture( GL_TEXTURE_2D, terrain->texid );
else glBindTexture( GL_TEXTURE_2D, 0);
terrain->Draw();
//glLineWidth(10.0);
//glPointSize(10.0);
//glColor3f(1.0f,0.0f,0.0f);
for (int i=0; i<terrain->artifacts.size(); i++){
glColor3f(terrain->severity[i]/2.2f, 0.0f, 0.0f);
drawFlag(terrain->artifacts[i]);
}
}
glDisable(GL_VERTEX_PROGRAM_ARB);
glDisable(GL_FRAGMENT_PROGRAM_ARB);
glDisable(GL_LIGHTING);
//glLineWidth(1.0);
//glPointSize(1.0);
}
示例2: main
//.........这里部分代码省略.........
exit(1);
}
shader.setParameter("sea", sea);
shader.setParameter("sand", sand);
shader.setParameter("grass", grass);
shader.setParameter("rock", rock);
shader.setParameter("snowrock", snowrock);
//Create our Terrain
Terrain terrain;
terrain.Init();
// Start game loop
while (App.isOpen())
{
// Process events
sf::Event Event;
while (App.pollEvent(Event))
{
// Close window : exit
if (Event.type == sf::Event::Closed)
App.close();
// Escape key : exit
if ((Event.type == sf::Event::KeyPressed) && (Event.key.code == sf::Keyboard::Escape))
App.close();
if ((Event.type == sf::Event::KeyPressed) && (Event.key.code == sf::Keyboard::O))
{
// select the projection matrix and clear it out
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
// set up an orthographic projection with the same near clip plane
glOrtho(-16.0, 16.0, -10.0, 16.0, 1.f, 300.0f);
// select modelview matrix and clear it out
glMatrixMode(GL_MODELVIEW);
}
else if ((Event.type == sf::Event::KeyPressed) && (Event.key.code == sf::Keyboard::P))
{
// select the projection matrix and clear it out
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum(-5.0, 5.0, -5.0, 5.0, 5, 100);
// select modelview matrix and clear it out
glMatrixMode(GL_MODELVIEW);
}
if ((Event.type == sf::Event::KeyPressed) && (Event.key.code == sf::Keyboard::I))
{
wireframe = !wireframe;
if (wireframe == true)
{
glPolygonMode(GL_FRONT, GL_FILL);
glPolygonMode(GL_BACK, GL_FILL);
}
else
{
glPolygonMode(GL_FRONT, GL_LINE);
glPolygonMode(GL_BACK, GL_LINE);
}
}
//update the camera
camera.Update(Event);
}
//Prepare for drawing
// Clear color and depth buffer
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
sf::Shader::bind(&shader);
GLfloat light_position[] = { 5.0, 2, 0.5, 0.1 };
glLightfv(GL_LIGHT0, GL_POSITION, light_position); // set position
// Apply some transformations
//initialise the worldview matrix
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
//get the viewing transform from the camera
camera.ViewingTransform();
//make the world spin
//TODO:probably should remove this in final
//static float ang=0.0;
//ang+=0.01f;
//glRotatef(ang*2,0,1,0);//spin about y-axis
//draw the world
terrain.Draw();
// Finally, display rendered frame on screen
App.display();
}
return EXIT_SUCCESS;
}
示例3: main
//.........这里部分代码省略.........
skaybox.SetShader(skaybox_shader);
skaybox.AtachCamera(camera);
skaybox.SetBack("./res/skybox2/skybox_back.bmp");
skaybox.SetFront("./res/skybox2/skybox_front.bmp");
skaybox.SetLeft("./res/skybox2/skybox_left.bmp");
skaybox.SetRight("./res/skybox2/skybox_right.bmp");
skaybox.SetBotom("./res/skybox2/skybox_bottom.bmp");
skaybox.SetTop("./res/skybox2/skybox_top.bmp");
skaybox.SetSize(1000);
skaybox.Init();
Terrain terrain;
terrain.LoadFromFile("./res/height_maps/TestMap.png");
terrain.SetTexture("./res/texture/grass_m.jpg");
terrain.SetShader(terrain_shader);
terrain.AtachCamera(camera);
terrain.SetHeight(25);
terrain.Init();
Mesh Grass[100];
Mesh Tree[25];
for (int i = 0; i < 100; i++) {
Grass[i].LoadMesh("./res/models/Grass pack/Grass_02.obj");
Grass[i].SetShader(grass_shader);
Grass[i].AtachCamera(camera);
int x = 0 + rand() % (int)terrain.GetSize().x ;
int y = 0 + rand() % (int)terrain.GetSize().y ;
Grass[i].SetPosition(x,terrain.GetHeightOnPoint(x,y)-0.4,y);
}
for (int i = 0; i < 25; i++) {
Tree[i].LoadMesh("./res/models/Tree/Tree.obj");
Tree[i].SetShader(model_shader);
Tree[i].AtachCamera(camera);
int x = 0 + rand() % (int)terrain.GetSize().x;
int y = 0 + rand() % (int)terrain.GetSize().y;
Tree[i].SetPosition(x, terrain.GetHeightOnPoint(x, y) - 0.4, y);
}
sf::Clock clock;
float speed;
camera.setPosition(glm::vec3(terrain.GetSize().x / 2, 8, terrain.GetSize().y / 2-3));
while (window.GetHandle()->isOpen())
{
speed = clock.getElapsedTime().asSeconds()*70;
clock.restart();
sf::Event event;
while (window.GetHandle()->pollEvent(event))
{
//debug.Event(event, window.GetReference());
if (event.type == sf::Event::Closed) {
window.GetHandle()->close();
return EXIT_SUCCESS;
}
if (event.type == sf::Event::Resized) {
camera.forResize((float)window.GetReference().getSize().x / (float)window.GetReference().getSize().y);
window.Resize();
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Escape)) {
window.GetHandle()->close();
return EXIT_SUCCESS;
}
}
if (window.GetReference().hasFocus() && !sf::Keyboard::isKeyPressed(sf::Keyboard::LControl)) {
camera.Update(window.GetReference(),speed);
}
else {
ShowCursor(true);
}
// camera.setPosition(glm::vec3(camera.getPosition().x, terrain.GetHeightOnPoint(camera.getPosition().x, camera.getPosition().z)+3,camera.getPosition().z));
window.Clear();
skaybox.Draw();
terrain.Draw();
for (int i = 0; i < 100 ; i++) {
Grass[i].Draw();
}
for (int i = 0; i < 25; i++) {
Tree[i].Draw();
}
window.Update();
}
return EXIT_SUCCESS;
}
示例4: DrawScene
void DuckHuntMain::DrawScene()
{
//
// Render the scene to the shadow map.
//
mSmap->BindDsvAndSetNullRenderTarget(md3dImmediateContext);
md3dImmediateContext->RSSetState(0);
md3dImmediateContext->ClearDepthStencilView(mDepthStencilView, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0);
md3dImmediateContext->RSSetViewports(1, &mScreenViewport);
mSsao->SetNormalDepthRenderTarget(mDepthStencilView);
//
// Restore the back and depth buffer and viewport to the OM stage.
//
ID3D11RenderTargetView* renderTargets[1] = { mRenderTargetView };
md3dImmediateContext->OMSetRenderTargets(1, renderTargets, mDepthStencilView);
md3dImmediateContext->ClearRenderTargetView(mRenderTargetView, reinterpret_cast<const float*>(&Colors::Silver));
XMMATRIX view = mCam.View();
XMMATRIX proj = mCam.Proj();
XMMATRIX viewProj = mCam.ViewProj();
float blendFactor[] = { 0.0f, 0.0f, 0.0f, 0.0f };
// Set per frame constants.
Effects::BasicFX->SetDirLights(mDirLights);
Effects::BasicFX->SetEyePosW(mCam.GetPosition());
Effects::BasicFX->SetCubeMap(mSky->CubeMapSRV());
Effects::BasicFX->SetShadowMap(mSmap->DepthMapSRV());
Effects::BasicFX->SetSsaoMap(mSsao->AmbientSRV());
ID3DX11EffectTechnique* tech = Effects::BasicFX->Light3TexTech;
md3dImmediateContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
XMMATRIX world;
XMMATRIX worldInvTranspose;
XMMATRIX worldViewProj;
// Transform NDC space [-1,+1]^2 to texture space [0,1]^2
XMMATRIX toTexSpace(
0.5f, 0.0f, 0.0f, 0.0f,
0.0f, -0.5f, 0.0f, 0.0f,
0.0f, 0.0f, 1.0f, 0.0f,
0.5f, 0.5f, 0.0f, 1.0f);
XMMATRIX shadowTransform = XMLoadFloat4x4(&mShadowTransform);
UINT stride = sizeof(Vertex::PosNormalTexTan);
UINT offset = 0;
md3dImmediateContext->IASetInputLayout(InputLayouts::Basic32);
if (GetAsyncKeyState('1') & 0x8000)
md3dImmediateContext->RSSetState(RenderStates::WireframeRS);
mTerrain.Draw(md3dImmediateContext, mCam, mDirLights);
//
// Draw opaque objects.
//
D3DX11_TECHNIQUE_DESC techDesc;
tech->GetDesc(&techDesc);
for (UINT p = 0; p < techDesc.Passes; ++p)
{
for (UINT modelIndex = 0; modelIndex < mModelInstances.size(); ++modelIndex)
{
world = XMLoadFloat4x4(&mModelInstances[modelIndex].World);
worldInvTranspose = MathHelper::InverseTranspose(world);
worldViewProj = world*view*proj;
Effects::BasicFX->SetWorld(world);
Effects::BasicFX->SetWorldInvTranspose(worldInvTranspose);
Effects::BasicFX->SetWorldViewProj(worldViewProj);
Effects::BasicFX->SetWorldViewProjTex(worldViewProj*toTexSpace);
Effects::BasicFX->SetShadowTransform(world*shadowTransform);
Effects::BasicFX->SetTexTransform(XMMatrixScaling(1.0f, 1.0f, 1.0f));
for (UINT subset = 0; subset < mModelInstances[modelIndex].Model->SubsetCount; ++subset)
{
Effects::BasicFX->SetMaterial(mModelInstances[modelIndex].Model->Mat[subset]);
Effects::BasicFX->SetDiffuseMap(mModelInstances[modelIndex].Model->DiffuseMapSRV[subset]);
//Effects::BasicFX->SetNormalMap(mModelInstances[modelIndex].Model->NormalMapSRV[subset]);
tech->GetPassByIndex(p)->Apply(0, md3dImmediateContext);
mModelInstances[modelIndex].Model->ModelMesh.Draw(md3dImmediateContext, subset);
}
}
}
// Turn off wireframe.
md3dImmediateContext->RSSetState(0);
// Restore from RenderStates::EqualsDSS
md3dImmediateContext->OMSetDepthStencilState(0, 0);
// Debug view SSAO map.
//DrawScreenQuad(mSsao->AmbientSRV());
//.........这里部分代码省略.........
示例5: main
//.........这里部分代码省略.........
glMaterialfv(GL_FRONT, GL_SPECULAR, materialSpecular); // set the colour of specular reflection
glMaterialfv(GL_FRONT, GL_SHININESS, materialShininess); // set shininess of the material
glLoadIdentity();
//set up a 3D Perspective View volume
gluPerspective(90.f, (float)width / height, 1.f, 300.0f);//fov, aspect, zNear, zFar
//load in different textures
sf::Texture seaTexture;
seaTexture.loadFromFile("sea.png");
sf::Texture grassTexture;
grassTexture.loadFromFile("grass.png");
sf::Texture rockTexture;
rockTexture.loadFromFile("rock.png");
//load the shader
sf::Shader shader;
//all the lighting & texture blending code should be put in 'fragment.glsl'
if (!shader.loadFromFile("vertex.glsl", "fragment.glsl")){
exit(1);
}
//set textures in the shader
shader.setParameter("seaTexture", seaTexture);
shader.setParameter("grassTexture", grassTexture);
shader.setParameter("rockTexture", rockTexture);
//load the height map image
sf::Image heightMap;
heightMap.loadFromFile("heightmap.png");
//Create our Terrain
Terrain terrain;
terrain.Init(heightMap); //create from height map
shader.setParameter("heightScale", terrain.getHeightScale()); //set the height scaler in the shader
// Start game loop
while (App.isOpen())
{
// Process events
sf::Event Event;
while (App.pollEvent(Event))
{
// Close window : exit
if (Event.type == sf::Event::Closed)
App.close();
// Escape key : exit
if ((Event.type == sf::Event::KeyPressed) && (Event.key.code == sf::Keyboard::Escape))
App.close();
//update the camera
if ((Event.type == sf::Event::KeyPressed) && (Event.key.code == sf::Keyboard::I))
wireFrame = !wireFrame;
//update the camera
camera.Update(Event);
}
//Prepare for drawing
// Clear color and depth buffer
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
sf::Shader::bind(&shader); //shader has to be binded here to allow changing textures
//glEnable(GL_TEXTURE_2D);
if (wireFrame)
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
else
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
glLightfv(GL_LIGHT0, GL_POSITION, light_position); // set position
// Apply some transformations
//initialise the worldview matrix
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE);
//get the viewing transform from the camera
camera.ViewingTransform();
//make the world spin
//TODO:probably should remove this in final
//static float ang=0.0;
//ang+=0.01f;
//glRotatef(ang*2,0,1,0);//spin about y-axis
//draw the world
terrain.Draw();
// Finally, display rendered frame on screen
App.display();
}
return EXIT_SUCCESS;
}
示例6: main
//.........这里部分代码省略.........
exit(1);
}
#pragma region Textures
// Textures
sf::Texture waterTexture;
if (!waterTexture.loadFromFile("water.png")) { std::cout << "Could not load water image"; }
sf::Texture grassTexture;
if (!grassTexture.loadFromFile("grass.png")){ std::cout << "Could not load grass image"; }
sf::Texture snowTexture;
if (!snowTexture.loadFromFile("snowy rock.png")) { std::cout << "Could not load rock image"; }
#pragma endregion
shader.setParameter("waterTex", waterTexture);
shader.setParameter("grassTex", grassTexture);
shader.setParameter("snowTex", snowTexture);
//Create our Terrain
Terrain terrain;
terrain.InitWithFileName("heightmap.bmp");
shader.setParameter("tallestPoint", terrain.tallestPoint);
// Start game loop
while (App.isOpen())
{
// Process events
sf::Event Event;
while (App.pollEvent(Event))
{
// Close window : exit
if (Event.type == sf::Event::Closed)
App.close();
// Escape key : exit
if ((Event.type == sf::Event::KeyPressed) && (Event.key.code == sf::Keyboard::Escape))
App.close();
if ((Event.type == sf::Event::KeyPressed) && (Event.key.code == sf::Keyboard::I))
{
terrain.swapWireFrame();
}
//update the camera
camera.Update(Event, &App);
}
camera.UpdatePosition();
// Clear color and depth buffer
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// Apply some transformations
//initialise the worldview matrix
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
//get the viewing transform from the camera
camera.ViewingTransform();
//make the world spin
//TODO:probably should remove this in final
static float ang = 0.0;
ang += 0.01f;
glRotatef(ang * 2, 0, 1, 0);//spin about y-axis
sf::Shader::bind(&shader);
glLightfv(GL_LIGHT0, GL_AMBIENT, light_amb); // set color of diffuse component
glLightfv(GL_LIGHT0, GL_DIFFUSE, light_color); // set color of diffuse component
glLightfv(GL_LIGHT0, GL_SPECULAR, light_color); // set color of specular component
glLightfv(GL_LIGHT0, GL_POSITION, light_position); // set position
//make the world spin
//TODO:probably should remove this in final
//static float ang=0.0;
//ang+=0.01f;
//glRotatef(ang*2,0,1,0);//spin about y-axis
//draw the world
terrain.Draw();
// Finally, display rendered frame on screen
App.display();
}
return EXIT_SUCCESS;
}