本文整理汇总了C++中SkyBox类的典型用法代码示例。如果您正苦于以下问题:C++ SkyBox类的具体用法?C++ SkyBox怎么用?C++ SkyBox使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SkyBox类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
osg::ref_ptr<osg::Node> CoreGraph::createSkyBox(){
if (appConf->getValue("Viewer.SkyBox.Noise").toInt() == 0) {
SkyBox * skyBox = new SkyBox;
return skyBox->createSkyBox();
} else {
unsigned char red = (unsigned char) appConf->getValue("Viewer.Display.BackGround.R").toInt();
unsigned char green = (unsigned char) appConf->getValue("Viewer.Display.BackGround.G").toInt();
unsigned char blue =(unsigned char) appConf->getValue("Viewer.Display.BackGround.B").toInt() ;
osg::ref_ptr<osg::Texture2D> skymap =
PerlinNoiseTextureGenerator::getCoudTexture(2048, 1024,
red,
green,
blue,
255);
skymap->setDataVariance(osg::Object::DYNAMIC);
skymap->setFilter(osg::Texture::MIN_FILTER, osg::Texture::LINEAR_MIPMAP_LINEAR);
skymap->setFilter(osg::Texture::MAG_FILTER, osg::Texture::LINEAR);
skymap->setWrap(osg::Texture::WRAP_S, osg::Texture::CLAMP_TO_EDGE);
skymap->setWrap(osg::Texture::WRAP_T, osg::Texture::CLAMP_TO_EDGE);
osg::ref_ptr<osg::StateSet> stateset = new osg::StateSet();
stateset->setTextureAttributeAndModes(0, skymap, osg::StateAttribute::ON);
stateset->setMode( GL_LIGHTING, osg::StateAttribute::OFF );
stateset->setMode( GL_CULL_FACE, osg::StateAttribute::OFF );
stateset->setRenderBinDetails(-1,"RenderBin");
osg::ref_ptr<osg::Depth> depth = new osg::Depth;
depth->setFunction(osg::Depth::ALWAYS);
depth->setRange(1, 1);
stateset->setAttributeAndModes(depth, osg::StateAttribute::ON );
osg::ref_ptr<osg::Drawable> drawable = new osg::ShapeDrawable(new osg::Sphere(osg::Vec3(0.0f,0.0f,0.0f), 1));
osg::ref_ptr<osg::Geode> geode = new osg::Geode;
geode->setCullingActive(false);
geode->setStateSet(stateset);
geode->addDrawable(drawable);
osg::ref_ptr<osg::Transform> transform = new SkyTransform;
transform->setCullingActive(false);
transform->addChild(geode);
osg::ref_ptr<osg::ClearNode> clearNode = new osg::ClearNode;
clearNode->setRequiresClear(false);
clearNode->addChild(transform);
return clearNode;
}
}
示例2: Initialize
bool Main::Initialize()
{
// Initialize window settings first, since later classes will be using these
if(!Settings->Initialize())
{
cout << "Failed to initialize SettingsClass." << endl;
return false;
}
// D3D11App initialized
if(!D3D11App::Initialize())
{
cout << "Failed to initialize app." << endl;
return false;
}
Text->Initialize(mDirect3D->GetDevice(), mDirect3D->GetDevCon());
Texture->Initialize(mDirect3D->GetDevice());
Effects::Initialize(mDirect3D->GetDevice());
InputLayouts::Initialize(mDirect3D->GetDevice());
Loader->Initialize(mDirect3D->GetDevice());
mSkyBox->Initialize(mDirect3D->GetDevice(), 5000.0f);
mGame->Initialize();
// Last part of the initialize of main
D3D11App::ShowWindow();
OnResize();
return S_OK;
}
示例3: WASDCamera
void myApp::init_graphics() {
m_d3ddev = m_pD3D->getDevice();
m_d3ddev->SetRenderState(D3DRS_LIGHTING, false);
m_d3ddev->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);
// creating cameras
isWASDCameraActive = true;
wasdCamera = new WASDCamera();
camera = new Camera();
float initPos = 500.0f;
wasdCamera->setPosition({ initPos, -initPos, initPos });
wasdCamera->setUpDirection({ 0.0f, 1.0f, 0.0f });
wasdCamera->setLookAt(worldCenter);
m_d3ddev->SetTransform(D3DTS_VIEW, wasdCamera->getViewMatrix()); // set the view transform to matView
D3DXMatrixPerspectiveFovLH(&m_matProj,
D3DXToRadian(45), // the horizontal field of view
(FLOAT)SCREEN_WIDTH / (FLOAT)SCREEN_HEIGHT, // aspect ratio
1.0f, // the near view-plane
20000.0f); // the far view-plane
m_d3ddev->SetTransform(D3DTS_PROJECTION, &m_matProj); // set the projection
ZeroMemory(&globalMaterial, sizeof(D3DMATERIAL9)); // clear out the struct for use
globalMaterial.Diffuse = hexToColor(0xffffff);
globalMaterial.Ambient = hexToColor(0xffffff);
globalMaterial.Emissive = hexToColor(0x000010);
globalMaterial.Specular = hexToColor(0);
m_nClearColor = 0xFF111111;
SkyBox *box = new SkyBox(m_d3ddev);
box->scale(10000.0f, 10000.0f, 10000.0f);
objects.push_back(box);
aroundCubeObjects.push_back(box);
reflectingCube = new ReflectingCube(m_d3ddev);
objects.push_back(reflectingCube);
reflectingCube->scale(200.0f, 200.0f, 200.0f);
}
示例4: renderSkyBox
//Calls the Skybox render function to render the skybox which is set up to render the skybox in a specific way
//then gets uniforms so that it knows what variables it's accessing the appropriate shader file.
//then passes values to the shader for it to calculate texture coordinates and such then proceeds
//to draw the cube mesh to screen.
void SplashScreen::renderSkyBox()
{
skyBoxObject->render();
Mesh * currentMesh = skyBoxObject->getMesh();
SkyBox * currentMaterial = (SkyBox*)skyBoxObject->getMaterial();
if (currentMesh && currentMaterial)
{
Camera * cam = mainCamera->getCamera();
currentMaterial->bind();
currentMesh->bind();
GLint cameraLocation = currentMaterial->getUniformLocation("cameraPos");
GLint viewLocation = currentMaterial->getUniformLocation("view");
GLint projectionLocation = currentMaterial->getUniformLocation("projection");
GLint cubeTextureLocation = currentMaterial->getUniformLocation("cubeTexture");
glUniformMatrix4fv(projectionLocation, 1, GL_FALSE, glm::value_ptr(cam->getProjection()));
glUniformMatrix4fv(viewLocation, 1, GL_FALSE, glm::value_ptr(cam->getView()));
glUniform4fv(cameraLocation, 1, glm::value_ptr(cam->getPosition()));
glUniform1i(cubeTextureLocation, 0);
glDrawElements(GL_TRIANGLES, currentMesh->getIndexCount(), GL_UNSIGNED_INT, 0);
currentMaterial->unbind();
}
//CheckForErrors();
GLenum error;
do{
error = glGetError();
} while (error != GL_NO_ERROR);
}
示例5: init
void SSAODemo::init()
{
scene = engine->createScene();
FixedArray<std::string, 6> skyBoxTextureFileNames = { Engine::getAssetPath() + "Textures/Skybox/miramar_ft.tga", Engine::getAssetPath() + "Textures/Skybox/miramar_bk.tga",
Engine::getAssetPath() + "Textures/Skybox/miramar_up.tga", Engine::getAssetPath() + "Textures/Skybox/miramar_dn.tga",
Engine::getAssetPath() + "Textures/Skybox/miramar_rt.tga", Engine::getAssetPath() + "Textures/Skybox/miramar_lf.tga" };
scene->setGlobalAmbientLight(Vector3(1.0f, 1.0f, 1.0f));
SkyBox* skyBox = (SkyBox*)scene->createSceneItem("SkyBox");
skyBox->setTextureFiles(skyBoxTextureFileNames);
Mesh* sponza = scene->createSceneItem<Mesh>();
engine->getSceneImporter().importMesh(Engine::getAssetPath() + "Models/Sponza/sponza.obj", sponza);
sponza->scale(0.05f);
float width = static_cast<float>(engine->getRenderer().getScreenViewPort().width);
float height = static_cast<float>(engine->getRenderer().getScreenViewPort().height);
scene->getMainCamera()->setAspectRatio((float)width / (float)height);
camera = scene->getMainCamera();
camera->translate(Vector3(20.0f, 5.0f, 0.0f), FrameOfReference::World);
camera->setRotation(Quaternion(-90.0f, Vector3::UNIT_Y));
}
示例6: Draw
// Draw function, I don't know or care that much about what's going on here, as long as it works
void Main::Draw()
{
mDirect3D->GetDevCon()->ClearRenderTargetView(mDirect3D->GetRTView(), reinterpret_cast<const float*>(&Colors::Cyan));
mDirect3D->GetDevCon()->ClearDepthStencilView(mDirect3D->GetDSView(), D3D11_CLEAR_DEPTH|D3D11_CLEAR_STENCIL, 1.0f, 0);
float blendFactor[] = {0.0f, 0.0f, 0.0f, 0.0f};
mDirect3D->GetDevCon()->RSSetState(0);
mDirect3D->GetDevCon()->OMSetDepthStencilState(0, 0);
mDirect3D->GetDevCon()->OMSetBlendState(0, blendFactor, 0xffffffff);
mGame->Draw(mDirect3D->GetDevCon());
mSkyBox->Draw(mDirect3D->GetDevCon(), mGame->GetPlayerCam());
// If the text isn't drawn last, objects in the world might hide it
Text->Draw();
mDirect3D->GetSwapChain()->Present(1, 0);
}
示例7: SetupScene
void SetupScene() {
//hField.Create(heightmapFile, heightmapTexture, 256, 256);
hField.Create(heightmapTexture);
char* SkyBoxTextures[6] = {"Data/textures/skybox/front.tga", "Data/textures/skybox/back.tga", "Data/textures/skybox/left.tga", "Data/textures/skybox/right.tga", "Data/textures/skybox/up.tga", "Data/textures/skybox/down.tga" };
sbox.Create(SkyBoxTextures);
camera = OpenGLCamera(real3(50,10,10), real3(50, 1, 20), real3(0, 1, 0),0.5);
//create enemy tanks
for (int i = 0; i < 4; i++) {
tanks[i] = new Tank(turretmodelFile, turrettextureFile, 2, Vec3(30+(10*i), 0, 50));
tanks[i]->setRotation(Vec3(0, 270, 0));
scene->AddObject(tanks[i]);
}
Crate *crates[50];
for (int i = 0; i < 15; i++) {
crates[i] = new Crate(Vec3(65, 1, 30+(2*i)), Vec3(0, 0, 0));
scene->AddObject(crates[i]);
}
for (int i = 15; i < 30; i++) {
crates[i] = new Crate(Vec3(25, 1, (2*i)), Vec3(0, 0, 0));
scene->AddObject(crates[i]);
}
for (int i = 30; i < 50; i++) {
crates[i] = new Crate(Vec3((2*i)-34, 1, 61), Vec3(0, 0, 0));
scene->AddObject(crates[i]);
}
//player setup
player = new Tank(tankmodelFile, tanktextureFile, 2, Vec3(50, 0, 25));
player->setPlayer();
player->initKeyboard();
scene->AddObject(player);
//setup hud
text[0] = new Font("Health: ", Vec3(50, 20, 0));
text[1] = new Font("Score: ", Vec3(650, 20, 0));
text[2] = new Font("FPS: ", Vec3(50, 550, 0));
glClearColor( 0.0f, 0.0f, 0.0f, 0.0f );
}
示例8: WinMain
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
XEngine *engine = XEngine::GetInstance();
if( engine->Init(hInstance) == FALSE )
{
return -1;
}
Rect rec(Position(-10000.0, 10000.0), Position(10000.0, -10000.0));
TestScene *scene = new TestScene;
scene->SetTime(0);
//Scene *scene = new Scene;
scene->Init(rec);
scene->camera->MoveForwardBy(-40);
scene->camera->MoveUpBy(18);
scene->camera->Pitch(-XM_PI / 10);
Material material;
material.ambient = XMFLOAT4(1.0f, 1.0f, 1.0f, 1.0f);
material.diffuse = XMFLOAT4(1.0f, 1.0f, 1.0f, 1.0f);
material.specular = XMFLOAT4(1.0f, 1.0f, 1.0f, 1.0f);
material.power = 9.0f;
//material.texture = SRVBatch::GetInstance()->LoadSRV("media/", "cup.jpg");
Particle *fire = new Particle;
fire->Init("media/","fire.png");
fire->SetPosition(0, 0, 10);
//scene->AddRenderableThing(*fire);
SkyBox *sky = new SkyBox;
//sky->Init("textures/", "skymap.dds");
sky->Init("textures/", "Above_The_Sea.dds");
//sky->Init("textures/", "desert_skymap.dds");
scene->AddSky(sky);
Terrain *terrain = new Terrain;
//terrain->Init("terrain/testHight.bmp", "terrain/", "dirt01.dds");
terrain->Init("terrain/heightmap01.bmp", "terrain/", "grass.jpg");
scene->AddTerrain(terrain);
Wall *wall = new Wall;
wall->Init(30, 30, 0.3);
wall->Pitch(XM_PI / 2);
wall->SetPosition(0, -3, 0);
//scene->AddRenderableThing(*wall);
//¿É¼ûÐÔ²âÊÔ
Wall *wall0 = new Wall;
wall0->Init(30, 30, 0.3);
wall0->Pitch(XM_PI / 2);
wall0->SetPosition(1000, -3, 0);
//scene->AddRenderableThing(*wall0);
Obj *obj = new Obj;
obj->CreateBox(1, 3, 2, material);
obj->SetPosition(5, 1, 12);
obj->Yaw(XM_PI / 3);
obj->Roll(XM_PI / 3);
obj->SetScale(1.3);
//scene->AddRenderableThing(*obj);
Cube *cube = new Cube;
cube->Init(2);
cube->Pitch(XM_PI / 3);
cube->Roll(XM_PI / 3);
cube->SetMaterial(material);
//scene->AddRenderableThing(*cube);
Ball *ball = new Ball;
ball->Init(1);
ball->SetPosition(0, 0, 6);
Obj *objInWall = new Obj;
objInWall->CreateBox(1, 1, 1, material);
objInWall->SetPosition(0, 1, 0);
ball->AddChild(objInWall);
//scene->AddRenderableThing(*ball);
Ship *ship = new Ship;
//ship->Init();
//ship->SetPosition(-10, 0, 0);
//scene->AddRenderableThing(*ship);
Model *test = new Model;
test->LoadModel("media/", "chair.obj");
test->SetScale(1.7);
test->SetPosition(-15, 0, 0);
test->Pitch(-1.2);
test->Yaw(-1.5);
//scene->AddRenderableThing(*test);
//SmileBoy *smileBoy= new SmileBoy;
//smileBoy->Init();
//smileBoy->SetHandleInput(FALSE);
//.........这里部分代码省略.........
示例9: sultan
bool myWorld::Init(int perso)
{
cont_cond_t cond;
uint8 c;
GLboolean xp = GL_FALSE;
GLboolean yp = GL_FALSE;
Vehicle *vehicle;
int i;
int f=NEG;
float d=0.0;
int ft=f;
int throttle=0;
int brake=0;
int ang=0;
ogg sultan("/rd/sons/ogg/sultanTribes.ogg");
init();
//speed tabulation
for(i=-NEG;i<0;i++)
aSpeed[i+NEG]=-(0.24*(float)7*i/(PLUS+NEG)+2)* log((float) -10*(float)7*i/(PLUS+NEG)+1)*3.6;
for(i=NEG;i<PLUS+NEG;i++)
aSpeed[i]=(-0.11*(float)(7*(i-NEG))/(PLUS+NEG)+2)*5* log((float) 3*(float)7*(i-NEG)/(PLUS+NEG)+1)*3.6;
/* Declaration des objets */
SkyBox *skyBox = new SkyBox(0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f);
Landscape *cliff = new Landscape(JPEG, "/rd/terrain.jpg", "/rd/terrain.pcx", 256.0f, 32, 1, 1, 0);
Landscape *sand = new Landscape(JPEG, "/rd/circuit.jpg", "/rd/circuit.pcx", 450.0f, 30, 4, 1/3.0f, -12.0f);
PalmTree *palmier = new PalmTree("/rd/palmier.png", 69.0f, (sand->getYFromXZ(69,12)) + 10, 12.0f, 20.0f, 20.0f, 20.0f);
PalmTree *cactus= new PalmTree("/rd/cactus.png", 10.0f, sand->getYFromXZ(10, 30) + 10, 30.0f, 40.0f, 40.0f, 40.0f);
Landscape *sea = new Landscape(NJPEG, NULL, "/rd/eau.pcx", 700.0f, 7, 4, 0.0f, 3.0f, 0.5f, 0.6f, 0.8f);
TheLittleHouseOnThePrairie *house = new TheLittleHouseOnThePrairie(-170.0f, 4.5f, -140.0f, 4.0f, 4.0f, 4.0f);
StartPane *startPane = new StartPane(-155.0f,sand->getYFromXZ(69,12) , 35.0f, 25.0f, 50.0f, 50.0f);
Caisse *caisse1 = new Caisse("/rd/decor/caisses/caisseGrande.png", -320.0f, -5.0f, -280.0f, 15.0f, 15.0f, 15.0f);
Caisse *caisse2 = new Caisse("/rd/decor/caisses/caisseCroix.png", 80.0f, 2.0f, -280.0f, 15.0f, 15.0f, 15.0f);
/*Caisse *caisse3 = new Caisse("/cd/decor/caisses/explosif.png", 280.0f, 2.0f, -220.0f, 15.0f, 15.0f, 15.0f);*/
/* Character creation */
switch(perso + 2)
{
case 2:
vehicle = new OisisVehicle(-155.0f, (sand->getYFromXZ (-155, 35)) + 1.25, 35.0f,
-155.0f, (sand->getYFromXZ (-155, 34.9)) + 1.25, 34.9f,
6.25f, 2.5f, 2.5f,
1.5);
break;
case 3:
vehicle = new MomoVehicle(-155.0f, sand->getYFromXZ (-155, 35) + 1.25, 35.0f,
-155.0f, sand->getYFromXZ (-155, 34.9) + 1.25 - 0.5, 34.9f,
2.5f , 5.0f, 2.5f,
0.5);
break;
case 4:
vehicle = new NoelVehicle(-155.0f, sand->getYFromXZ (-155, 35) + 7.5, 35.0f,
-155.0f, sand->getYFromXZ (-155, 34.9) + 7.5 - 10, 34.9f,
3.25f , 15.0f, 13.0f,
10);
break;
default:
vehicle = new NoelVehicle(-155.0f, sand->getYFromXZ (-155, 35) + 7.5, 35.0f,
-155.0f, sand->getYFromXZ (-155, 34.9) + 7.5, 34.9f,
3.25f , 15.0f, 13.0f,
10);
break;
}
sultan.play(1);
//vehicle->updateSlope(sand);
//Vector3D tmp1= (vehicle->getPosition()) + (Vector3D (0, 10,17.5));
/*Vector3D tmp1= (vehicle->getPosition()) + (Vector3D (0, 10 - vehicle->getOffset(), 17.5));
Vector3D tmp2= Vector3D (0,1,0);
Camera cam(tmp1, vehicle->getPosition(), tmp2);*/
Vector3D tmp1= (vehicle->getPosition()) + (Vector3D (0, 10 - vehicle->getOffset(), 17.5));
Vector3D tmp3= Vector3D (0,1,0);
Vector3D tmp2 = vehicle->getPosition();
tmp2.y -= vehicle->getOffset();
Camera cam(tmp1, tmp2, tmp3);
palmier->shape();
cactus->setColor(0.0f, 0.6f, 0.2f);
cactus->shape();
cliff->shape();
sand->shape();
sea->shape();
startPane->shape();
house->shape();
vehicle->shape();
caisse1->shape();
//.........这里部分代码省略.........
示例10: SkyBox
void DxManager::CreateSkyBox(string texture)
{
if(this->skybox)
delete this->skybox;
SkyBox* sb = new SkyBox(this->camera->getPosition(), 10, 10);
MeshStrip* strip = sb->GetStrips()->get(0);
// Create the desc for the buffer
BUFFER_INIT_DESC BufferDesc;
BufferDesc.ElementSize = sizeof(Vertex);
BufferDesc.InitData = strip->getVerts();
BufferDesc.NumElements = strip->getNrOfVerts();
BufferDesc.Type = VERTEX_BUFFER;
BufferDesc.Usage = BUFFER_DEFAULT;
// Create the buffer
Buffer* VertexBuffer = new Buffer();
if(FAILED(VertexBuffer->Init(this->Dx_Device, this->Dx_DeviceContext, BufferDesc)))
MaloW::Debug("Failed to init skybox");
BUFFER_INIT_DESC indiceBufferDesc;
indiceBufferDesc.ElementSize = sizeof(int);
indiceBufferDesc.InitData = strip->getIndicies();
indiceBufferDesc.NumElements = strip->getNrOfIndicies();
indiceBufferDesc.Type = INDEX_BUFFER;
indiceBufferDesc.Usage = BUFFER_DEFAULT;
Buffer* IndexBuffer = new Buffer();
if(FAILED(IndexBuffer->Init(this->Dx_Device, this->Dx_DeviceContext, indiceBufferDesc)))
MaloW::Debug("Failed to init skybox");
D3DX11_IMAGE_LOAD_INFO loadSMInfo;
loadSMInfo.MiscFlags = D3D11_RESOURCE_MISC_TEXTURECUBE;
ID3D11Texture2D* SMTexture = 0;
D3DX11CreateTextureFromFile(this->Dx_Device, texture.c_str(),
&loadSMInfo, 0, (ID3D11Resource**)&SMTexture, 0);
D3D11_TEXTURE2D_DESC SMTextureDesc;
SMTexture->GetDesc(&SMTextureDesc);
D3D11_SHADER_RESOURCE_VIEW_DESC SMViewDesc;
SMViewDesc.Format = SMTextureDesc.Format;
SMViewDesc.ViewDimension = D3D10_SRV_DIMENSION_TEXTURECUBE;
SMViewDesc.TextureCube.MipLevels = SMTextureDesc.MipLevels;
SMViewDesc.TextureCube.MostDetailedMip = 0;
ID3D11ShaderResourceView* text;
this->Dx_Device->CreateShaderResourceView(SMTexture, &SMViewDesc, &text);
SMTexture->Release();
Object3D* ro = new Object3D(VertexBuffer, IndexBuffer, text, sb->GetTopology());
strip->SetRenderObject(ro);
this->skybox = sb;
}
示例11: PRINT_GL_ERROR
Scene *SceneBuilder::build() {
PRINT_GL_ERROR();
Camera *camera = new Camera();
PRINT_GL_ERROR();
// camera->setMouse(QCursor::pos().x(), QCursor::pos().y());
camera->setMouse(0, 0);
camera->reset();
PRINT_GL_ERROR();
SkyBox *skyBox = new SkyBox(
new MaterialSkyBox(new TextureCube("data/resources/cubemaps/miramar/")));
PRINT_GL_ERROR();
skyBox->setPosition(camera->getPosition());
PRINT_GL_ERROR();
// SUN
Texture::resetUnit();
PRINT_GL_ERROR();
Texture *sunDiffuse = Texture::newFromNextUnit();
PRINT_GL_ERROR();
Texture *sunAlpha = Texture::newFromNextUnit();
PRINT_GL_ERROR();
sunDiffuse->load("data/resources/maps/sun/sun_1k.png");
PRINT_GL_ERROR();
sunDiffuse->setFilters(GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR);
PRINT_GL_ERROR();
sunDiffuse->init();
PRINT_GL_ERROR();
sunAlpha->load("data/resources/maps/sun/sun_1k_alpha.png");
PRINT_GL_ERROR();
sunAlpha->setFilters(GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR);
PRINT_GL_ERROR();
sunAlpha->init();
PRINT_GL_ERROR();
MaterialSun *sunMat = new MaterialSun(sunDiffuse, sunAlpha);
PRINT_GL_ERROR();
Sun *sun = new Sun(sunMat);
PRINT_GL_ERROR();
// GROUND
Texture::resetUnit();
// diffuses
Texture *groundMoss = Texture::newFromNextUnit();
Texture *groundEarth = Texture::newFromNextUnit();
Texture *groundShatter = Texture::newFromNextUnit();
groundMoss->load("data/resources/maps/ground/moss.png");
groundMoss->setFilters(GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR);
groundMoss->init();
groundEarth->load("data/resources/maps/ground/earth.png");
groundEarth->setFilters(GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR);
groundEarth->init();
groundShatter->load("data/resources/maps/ground/shatter.png");
groundShatter->setFilters(GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR);
groundShatter->init();
PRINT_GL_ERROR();
// normals
Texture *groundNormalMoss = Texture::newFromNextUnit();
Texture *groundNormalEarth = Texture::newFromNextUnit();
Texture *groundNormalShatter = Texture::newFromNextUnit();
groundNormalMoss->load("data/resources/maps/ground/moss_normal.png");
groundNormalMoss->setFilters(GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR);
groundNormalMoss->init();
groundNormalEarth->load("data/resources/maps/ground/earth_normal.png");
groundNormalEarth->setFilters(GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR);
groundNormalEarth->init();
groundNormalShatter->load("data/resources/maps/ground/shatter_normal.png");
groundNormalShatter->setFilters(GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR);
groundNormalShatter->init();
PRINT_GL_ERROR();
// init
MaterialGround *groundMat = new MaterialGround(
groundMoss, groundEarth, groundShatter, groundNormalMoss,
groundNormalEarth, groundNormalShatter);
Ground *ground =
new Ground("data/resources/heightmaps/heightmap.png", groundMat);
PRINT_GL_ERROR();
// ROCK 1
Texture::resetUnit();
PRINT_GL_ERROR();
Texture *rock1Diffuse = Texture::newFromNextUnit();
Texture *rock1Alpha = Texture::newFromNextUnit();
Mesh *rock1 = ObjLoader::loadObj("data/resources/meshes/rock1/rock1.obj");
rock1Diffuse->load("data/resources/maps/rock1/rock1_1k.png");
rock1Diffuse->setFilters(GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR);
rock1Diffuse->init();
rock1Alpha->load("data/resources/maps/noalpha.png");
rock1Alpha->setFilters(GL_NEAREST, GL_NEAREST);
rock1Alpha->init();
((MaterialBasic *)(rock1->getMaterial()))->setDiffuse(rock1Diffuse);
((MaterialBasic *)(rock1->getMaterial()))->setAlpha(rock1Alpha);
rock1->setPosition(Vector3(-3, 0.5, 0));
rock1->setScale(Vector3(0.6, 0.6, 0.6));
rock1->setScale(Vector3(0.0, 0.0, 0.0));
rock1->setScaleRdn(0.2);
rock1->setHeightRdn(0.5);
rock1->setPourcentage(0.2);
rock1->setInstanceType(Mesh::INSTANCE_ROCK);
rock1->setRangeScale(0.4);
createInstances(rock1, ground, NB_INSTANCE * rock1->getPourcentage());
//.........这里部分代码省略.........
示例12: main
int main(int , char**)
{
int width = 1280, height = 760;
Display mainWindow(width, height, "DEngine");
//mainWindow.ShowCursor(false);
mainWindow.WrapMouse(false);
glm::vec3 lightPosition(-4.0f, 8.0f, -6.0f);
Light sun(lightPosition, glm::vec3(1.0f, 1.0f, 1.0f), DIRECTIONAL_LIGHT);
Camera camera(glm::vec3(0.0f, 2.0f, 1.0f));
camera.SetCameraMode(FLY);
Shader simpleProgram;
simpleProgram.LoadShaders("./SHADERS/SOURCE/NoNormal_vs.glsl",
"./SHADERS/SOURCE/NoNormal_fs.glsl");
Shader skyBoxShaders;
skyBoxShaders.LoadShaders("./SHADERS/SOURCE/skyBox_vs.glsl",
"./SHADERS/SOURCE/skyBox_fs.glsl");
Shader shadowShaders;
shadowShaders.LoadShaders("./SHADERS/SOURCE/ShadowDepth_vs.glsl",
"./SHADERS/SOURCE/ShadowDepth_fs.glsl");
EventListener eventListener(&mainWindow, &camera, &simpleProgram);
SkyBox sky;
sky.LoadCubeMap("./Models/skybox");
Model box;
box.LoadModelFromFile(".\\Models\\Box.obj");
box.TranslateModel(glm::vec3(0.0f, 2.0f, 0.0f));
box.meshes[0].AddTexture("./Models/textures/154.png", textureType::DIFFUSE_MAP);
box.meshes[0].AddTexture("./Models/textures/154_norm.png", textureType::NORMAL_MAP);
box.meshes[0].AddTexture("./Models/textures/154s.png", textureType::SPECULAR_MAP);
box.TranslateModel(glm::vec3(0.0f, -0.5f, -2.0f));
Model floor;
floor.LoadModelFromFile("./Models/Plane/plane.obj");
floor.meshes[0].AddTexture("./Models/textures/196.png", textureType::DIFFUSE_MAP);
floor.meshes[0].AddTexture("./Models/textures/196_norm.png", textureType::NORMAL_MAP);
floor.meshes[0].AddTexture("./Models/textures/196s.png", textureType::SPECULAR_MAP);
floor.TranslateModel(glm::vec3(0.0f, -2.0f, 0.0f));
Clock clock;
while (!mainWindow.isClosed)
{
eventListener.Listen();
clock.NewFrame();
//DRAWING SCENE TO SHADOWMAP
//sun.StartDrawingShadows(shadowShaders.programID);
//
//glCullFace(GL_FRONT);
////nanosuit.Draw(&mainWindow, camera, &sun, shadowShaders);
//box.Draw(&mainWindow, camera, &sun, shadowShaders);
//floor.Draw(&mainWindow, camera, &sun, shadowShaders);
//
//sun.StopDrawingShadows();
//
//glCullFace(GL_BACK);
//glViewport(0, 0, width, height);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
//NORMAL DRAWING SCENE
simpleProgram.UseProgram();
glUniformMatrix4fv(glGetUniformLocation(simpleProgram.programID, "lightSpaceMatrix"), 1, GL_FALSE, glm::value_ptr(sun.shadowMatrix));
glUniform1f(glGetUniformLocation(simpleProgram.programID, "time"), clock.time);
//glActiveTexture(GL_TEXTURE15);
//glBindTexture(GL_TEXTURE_2D, sun.shadowTexture.textureID);
//glUniform1i(glGetUniformLocation(simpleProgram.programID, "depth_map"), 15);
floor.Draw(&mainWindow, camera, &sun, simpleProgram);
box.Draw(&mainWindow, camera, &sun, simpleProgram);
//sky.Draw(&mainWindow, camera, skyBoxShaders);
camera.Update(clock.deltaTime);
mainWindow.Update();
}
return 0;
}
示例13: main
int main(int argc, char** argv)
{
if (!glfwInit()) // 初始化glfw库
{
std::cout << "Error::GLFW could not initialize GLFW!" << std::endl;
return -1;
}
// 开启OpenGL 3.3 core profile
std::cout << "Start OpenGL core profile version 3.3" << std::endl;
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);
// 创建窗口
GLFWwindow* window = glfwCreateWindow(WINDOW_WIDTH, WINDOW_HEIGHT,
"Demo of EnviromentMapping(reflection)", NULL, NULL);
if (!window)
{
std::cout << "Error::GLFW could not create winddow!" << std::endl;
glfwTerminate();
std::system("pause");
return -1;
}
// 创建的窗口的context指定为当前context
glfwMakeContextCurrent(window);
// 注册窗口键盘事件回调函数
glfwSetKeyCallback(window, key_callback);
// 注册鼠标事件回调函数
glfwSetCursorPosCallback(window, mouse_move_callback);
// 注册鼠标滚轮事件回调函数
glfwSetScrollCallback(window, mouse_scroll_callback);
// 鼠标捕获 停留在程序内
glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
// 初始化GLEW 获取OpenGL函数
glewExperimental = GL_TRUE; // 让glew获取所有拓展函数
GLenum status = glewInit();
if (status != GLEW_OK)
{
std::cout << "Error::GLEW glew version:" << glewGetString(GLEW_VERSION)
<< " error string:" << glewGetErrorString(status) << std::endl;
glfwTerminate();
std::system("pause");
return -1;
}
// 设置视口参数
glViewport(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT);
//Section1 加载模型数据
Model objModel;
if (!objModel.loadModel("../../resources/models/sphere/sphere.obj"))
{
glfwTerminate();
std::system("pause");
return -1;
}
// Section2 创建Skybox
std::vector<const char*> faces;
faces.push_back("../../resources/skyboxes/sky/sky_rt.jpg");
faces.push_back("../../resources/skyboxes/sky/sky_lf.jpg");
faces.push_back("../../resources/skyboxes/sky/sky_up.jpg");
faces.push_back("../../resources/skyboxes/sky/sky_dn.jpg");
faces.push_back("../../resources/skyboxes/sky/sky_bk.jpg");
faces.push_back("../../resources/skyboxes/sky/sky_ft.jpg");
SkyBox skybox;
skybox.init(faces);
// Section3 准备着色器程序
Shader shader("scene.vertex", "scene.frag");
Shader skyBoxShader("skybox.vertex", "skybox.frag");
glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
glDepthFunc(GL_LESS);
// 开始游戏主循环
while (!glfwWindowShouldClose(window))
{
GLfloat currentFrame = (GLfloat)glfwGetTime();
deltaTime = currentFrame - lastFrame;
lastFrame = currentFrame;
glfwPollEvents(); // 处理例如鼠标 键盘等事件
do_movement(); // 根据用户操作情况 更新相机属性
// 设置colorBuffer颜色
glClearColor(0.18f, 0.04f, 0.14f, 1.0f);
// 清除colorBuffer
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// 先绘制场景
shader.use();
glm::mat4 projection = glm::perspective(camera.mouse_zoom,
(GLfloat)(WINDOW_WIDTH) / WINDOW_HEIGHT, 0.1f, 100.0f); // 投影矩阵
glUniformMatrix4fv(glGetUniformLocation(shader.programId, "projection"),
1, GL_FALSE, glm::value_ptr(projection));
glm::mat4 view = camera.getViewMatrix(); // 视变换矩阵
//.........这里部分代码省略.........
示例14: loadTextures
// loading a texture
void loadTextures() {
char *sbTextureNameSunnyDay[6] ={
"TropicalSunnyDayLeft2048.png",
"TropicalSunnyDayRight2048.png",
"TropicalSunnyDayUp2048.png",
"TropicalSunnyDayDown2048.png",
"TropicalSunnyDayFront2048.png",
"TropicalSunnyDayBack2048.png"
};
char *sbTextureNight[6] ={
"right.jpg",
"left.jpg",
"top.jpg",
"bottom.jpg",
"front.jpg",
"back.jpg"
};
char *texFileName = "sample.png";
// NOT USED IN THIS EXAMPLE. LEFT HERE TO SHOW HOW TO LOAD A TEXTURE
// loadTexture(&tex, GL_TEXTURE_2D, texFileName);
// in case one would like to load a colour skybox:
// front (posZ) is purple (magenta),
// back (negZ) is yellow,
// left (negX) is green
// right (posX) is red
// top (posY) is blue)
// bottom (negY) is cyan
//skybox.loadColourTexture();
skybox.loadSkybox(sbTextureNameSunnyDay);
skybox2.loadSkybox(sbTextureNight);
}
示例15: renderFun
// this is the render function. It contains flags to set up the differnt shaders and what
// to draw. One can remove most of is not all of theem
void renderFun() {
// DEBUGGING FLAGS
static int drawTri = 1;
static int drawSkybox = 1;
static int drawLines = 0;
static Vector3f pos=Vector3f(0,0,100);
static Vector3f lookat=Vector3f(0 ,0 ,0);
static Vector3f up=Vector3f(0,1,0);
static int zoom = -70;
static int camZoom = 1;
static int setCam = 0;
// setting up the camera manually if needed
// can be remved
if (setCam) {
cam.setCamera(pos, lookat, up);
setCam = 0;
}
// setting up the camera zoom manually if needed
// can be remved
if (camZoom) {
cam.zoomIn(zoom);
camZoom = 0;
}
// setting opengl - clearing the buffers
glEnable(GL_DEPTH_TEST); // need depth test to correctly draw 3D objects
glClearColor(1.0,1.0,1.0,1);
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
if (drawSkybox) {
skybox.displaySkybox(cam);
}
if (drawTri) {
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
displayBoxFun(sphereBoxProg);
}
// if (drawLines) {
// glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
// displayBoxFun(sphereLinesBoxProg);
// }
glutSwapBuffers();
}