Skip to content

Commit

Permalink
Merge pull request #268 from kimkulling/doc/add_samples_link
Browse files Browse the repository at this point in the history
Update README.md
  • Loading branch information
kimkulling authored Jan 14, 2025
2 parents cfd6e7e + a327dba commit 870dfd6
Showing 1 changed file with 2 additions and 112 deletions.
114 changes: 2 additions & 112 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,118 +60,8 @@ We have a discord server at [Discord](https://discord.gg/kqJQW5dQ)
- GCC
- Clang

# Quick Start

```cpp
#include <osre/App/App.h>
#include <osre/Common/Logger.h>
#include <osre/RenderBackend/RenderBackendService.h>
#include <osre/Scene/MeshBuilder.h>
#include <osre/Scene/Camera.h>
#include <osre/Platform/AbstractWindow.h>
#include <osre/RenderBackend/glm_common.h>

using namespace ::OSRE;
using namespace ::OSRE::App;
using namespace ::OSRE::RenderBackend;

class QuickStartApp : public AppBase {
/// The transform block, contains the model-, view- and projection-matrix
TransformMatrixBlock m_transformMatrix;
/// The entity to render
Entity *mEntity;

public:
/// The class constructor with the incoming arguments from the command line.
QuickStartApp(int argc, char *argv[]) :
AppBase(argc, (const char **)argv),
m_transformMatrix(),
mEntity(nullptr) {
// empty
}

/// The class destructor, default impl.
~QuickStartApp() override = default;

protected:
/// The creation callback, will get called on system startup.
bool onCreate() override {
if (!AppBase::onCreate()) {
return false;
}

// The window
AppBase::setWindowsTitle("Quickstart! Rotate with wasd, scroll with qe");
// The world to work in
World *world = getActiveWorld();
// The entity for your triangle
mEntity = new Entity("entity", *AppBase::getIdContainer(), world);
// The camera to watch the scene
Scene::Camera *camera = world->addCamera("camera_1");
ui32 w, h;
AppBase::getResolution(w, h);
camera->setProjectionParameters(60.f, (f32)w, (f32)h, 0.001f, 1000.f);

// Create and add the triangle
Scene::MeshBuilder meshBuilder;
RenderBackend::Mesh *mesh = meshBuilder.allocTriangles(VertexType::ColorVertex, BufferAccessType::ReadOnly).getMesh();
if (nullptr != mesh) {
mEntity->addStaticMesh(mesh);
world->addEntity(mEntity);
// And observer the triangle
camera->observeBoundingBox(mEntity->getAABB());
}

return true;
}

/// The update, will be called for each render frame
void onUpdate() override {
glm::mat4 rot(1.0);
if (AppBase::isKeyPressed(Platform::KEY_A)) {
m_transformMatrix.m_model *= glm::rotate(rot, 0.01f, glm::vec3(1, 0, 0));
}
if (AppBase::isKeyPressed(Platform::KEY_D)) {
m_transformMatrix.m_model *= glm::rotate(rot, -0.01f, glm::vec3(1, 0, 0));
}

if (AppBase::isKeyPressed(Platform::KEY_W)) {
m_transformMatrix.m_model *= glm::rotate(rot, 0.01f, glm::vec3(0, 1, 0));
}

if (AppBase::isKeyPressed(Platform::KEY_S)) {
m_transformMatrix.m_model *= glm::rotate(rot, -0.01f, glm::vec3(0, 1, 0));
}

if (AppBase::isKeyPressed(Platform::KEY_Q)) {
m_transformMatrix.m_model *= glm::scale(rot, glm::vec3(1.01f, 1.01, 1.01f));
}

if (AppBase::isKeyPressed(Platform::KEY_E)) {
m_transformMatrix.m_model *= glm::scale(rot, glm::vec3(0.99f, 0.99f, 0.99f));
}

// Set the model-matrix in the renderpass
RenderBackendService *rbSrv = getRenderBackendService();

rbSrv->beginPass(PipelinePass::getPassNameById(RenderPassId));
rbSrv->beginRenderBatch("b1");

rbSrv->setMatrix(MatrixType::Model, m_transformMatrix.m_model);

rbSrv->endRenderBatch();
rbSrv->endPass();

AppBase::onUpdate();
}
};

OSRE_MAIN(QuickStartdApp)
```
# Samples
Check the [Samples](samples) page.

# OSRE-Ed

Expand Down

0 comments on commit 870dfd6

Please sign in to comment.