Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include "IImage.h"
- #include "ITexture.h"
- #include "IAnimation.h"
- #include "IWindow.h"
- #include "ISceneGraph.h"
- #include "OpenGL.h"
- Resource<IMesh> rectangle()
- {
- static const float location[] = {0, 0, 100, 0, 0, 100, 100, 100};
- static unsigned short index[] = {0, 1, 3, 3, 2, 4};
- std::vector<SMeshVertex> vertices(4);
- for(unsigned int i = 0; i < 4; i++)
- vertices[i] = SMeshVertex(location[i*2], location[i*2+1], location[i*2] > 0, location[i*2+1] > 0);
- std::vector<unsigned short> indices(index, &index[6]);
- Resource<IMesh> mesh = IMesh::create();
- mesh->fillVertices(vertices);
- mesh->fillIndices(indices);
- return mesh;
- }
- int main()
- {
- Resource<IWindow> window = IWindow::create();
- window->open();
- Resource<IMesh> mesh = rectangle();
- Resource<IImage> image = IImage::get("data/images/sprite1.png");
- Resource<ITexture> texture = ITexture::create();
- texture->fromImage(image);
- Resource<IShader> shader = IShader::create();
- std::string error;
- if(!shader->addSource(EShaderType_Fragment, "data/shaders/shader.frag", error))
- std::cout << error;
- if(!shader->addSource(EShaderType_Vertex, "data/shaders/shader.vert", error))
- std::cout << error;
- shader->link();
- Resource<IAnimation> anim = IAnimation::create();
- anim->fromFile("data/animations/rotate.anim");
- Resource<ISceneNode> body = ISceneNode::create();
- body->setMesh(mesh);
- body->setTexture(texture);
- body->setShader(shader);
- body->setName("mainBone");
- Resource<ISceneNode> left = ISceneNode::create();
- left->setMesh(mesh);
- left->setName("leftArm");
- Resource<ISceneNode> right = ISceneNode::create();
- right->setMesh(mesh);
- right->setName("rightArm");
- Resource<ISceneNode> root = ISceneNode::create();
- root->addNode(body);
- body->addNode(right);
- body->addNode(left);
- float t = 0.0f;
- while(t += 0.01f)
- {
- anim->apply(body, t);
- glClear(GL_COLOR_BUFFER_BIT);
- root->render();
- window->pollEvents();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement