Advertisement
Guest User

Untitled

a guest
May 31st, 2012
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.99 KB | None | 0 0
  1. #include <iostream>
  2. #include "IImage.h"
  3. #include "ITexture.h"
  4. #include "IAnimation.h"
  5. #include "IWindow.h"
  6. #include "ISceneGraph.h"
  7. #include "OpenGL.h"
  8.  
  9. Resource<IMesh> rectangle()
  10. {
  11.     static const float location[] = {0, 0, 100, 0, 0, 100, 100, 100};
  12.     static unsigned short index[] = {0, 1, 3, 3, 2, 4};
  13.  
  14.     std::vector<SMeshVertex> vertices(4);
  15.     for(unsigned int i = 0; i < 4; i++)
  16.         vertices[i] = SMeshVertex(location[i*2], location[i*2+1], location[i*2] > 0, location[i*2+1] > 0);
  17.  
  18.     std::vector<unsigned short> indices(index, &index[6]);
  19.  
  20.     Resource<IMesh> mesh = IMesh::create();
  21.     mesh->fillVertices(vertices);
  22.     mesh->fillIndices(indices);
  23.  
  24.     return mesh;
  25. }
  26.  
  27. int main()
  28. {
  29.     Resource<IWindow> window = IWindow::create();
  30.     window->open();
  31.  
  32.     Resource<IMesh> mesh = rectangle();
  33.  
  34.     Resource<IImage> image = IImage::get("data/images/sprite1.png");
  35.  
  36.     Resource<ITexture> texture = ITexture::create();
  37.     texture->fromImage(image);
  38.  
  39.     Resource<IShader> shader = IShader::create();
  40.     std::string error;
  41.     if(!shader->addSource(EShaderType_Fragment, "data/shaders/shader.frag", error))
  42.         std::cout << error;
  43.  
  44.     if(!shader->addSource(EShaderType_Vertex, "data/shaders/shader.vert", error))
  45.         std::cout << error;
  46.  
  47.     shader->link();
  48.  
  49.     Resource<IAnimation> anim = IAnimation::create();
  50.     anim->fromFile("data/animations/rotate.anim");
  51.  
  52.     Resource<ISceneNode> body = ISceneNode::create();
  53.     body->setMesh(mesh);
  54.     body->setTexture(texture);
  55.     body->setShader(shader);
  56.     body->setName("mainBone");
  57.  
  58.     Resource<ISceneNode> left = ISceneNode::create();
  59.     left->setMesh(mesh);
  60.     left->setName("leftArm");
  61.  
  62.     Resource<ISceneNode> right = ISceneNode::create();
  63.     right->setMesh(mesh);
  64.     right->setName("rightArm");
  65.  
  66.     Resource<ISceneNode> root = ISceneNode::create();
  67.     root->addNode(body);
  68.     body->addNode(right);
  69.     body->addNode(left);
  70.    
  71.     float t = 0.0f;
  72.     while(t += 0.01f)
  73.     {
  74.        
  75.         anim->apply(body, t);
  76.                            
  77.         glClear(GL_COLOR_BUFFER_BIT);
  78.         root->render();
  79.         window->pollEvents();
  80.     }
  81.  
  82.     return 0;
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement