Created
August 14, 2012 16:08
-
-
Save notanumber/3350538 to your computer and use it in GitHub Desktop.
Simple Quad
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef TEMPLATEGAME_H_ | |
#define TEMPLATEGAME_H_ | |
#include "gameplay.h" | |
using namespace gameplay; | |
class TestApp : public Game | |
{ | |
public: | |
TestApp(); | |
void keyEvent(Keyboard::KeyEvent evt, int key); | |
protected: | |
void initialize(); | |
void finalize(); | |
void update(float elapsedTime); | |
void render(float elapsedTime); | |
private: | |
Scene* _scene; | |
bool drawScene(Node* node); | |
}; | |
#endif | |
/*========================================================================*/ | |
#include "TestApp.h" | |
// Declare our game instance | |
TestApp game; | |
TestApp::TestApp() | |
: _scene(NULL) | |
{ | |
} | |
void TestApp::initialize() | |
{ | |
Camera* camera = Camera::createPerspective(60.0f, (float)getWidth() / (float)getHeight(), 1.0f, 100.0f); | |
Mesh *mesh = Mesh::createQuad( | |
Vector3(-1.0f, 1.0f, 0.0f), | |
Vector3(-1.0f, -1.0f, 0.0f), | |
Vector3( 1.0f, 1.0f, 0.0f), | |
Vector3( 1.0f, -1.0f, 0.0f) | |
); | |
Model* model = Model::create(mesh); | |
model->setMaterial("res/shaders/colored-unlit.vert", "res/shaders/colored-unlit.frag"); | |
model->getMaterial()->getParameter("u_diffuseColor")->setValue(Vector4(1.0f, 0.0f, 0.0f, 1.0f)); | |
model->getMaterial()->setParameterAutoBinding("u_worldViewProjectionMatrix", Material::WORLD_VIEW_PROJECTION_MATRIX); | |
_scene = Scene::createScene(); | |
_scene->addNode("camera")->setCamera(camera); | |
_scene->addNode("model")->setModel(model); | |
_scene->setActiveCamera(camera); | |
_scene->findNode("camera")->translateZ(4.0f); | |
SAFE_RELEASE(mesh); | |
SAFE_RELEASE(model); | |
} | |
void TestApp::finalize() | |
{ | |
SAFE_RELEASE(_scene); | |
} | |
void TestApp::update(float elapsedTime) | |
{ | |
} | |
void TestApp::render(float elapsedTime) | |
{ | |
clear(CLEAR_COLOR_DEPTH, Vector4::zero(), 1.0f, 0); | |
_scene->visit(this, &TestApp::drawScene); | |
} | |
bool TestApp::drawScene(Node* node) | |
{ | |
Model* model = node->getModel(); | |
if (model) | |
model->draw(); | |
return true; | |
} | |
void TestApp::keyEvent(Keyboard::KeyEvent evt, int key) | |
{ | |
if (evt == Keyboard::KEY_PRESS) | |
{ | |
switch (key) | |
{ | |
case Keyboard::KEY_ESCAPE: | |
exit(); | |
break; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment