mirror of https://github.com/mosra/magnum.git
22 changed files with 2 additions and 628 deletions
@ -1,2 +0,0 @@ |
|||||||
add_subdirectory(texturedTriangle) |
|
||||||
add_subdirectory(triangle) |
|
||||||
@ -1,2 +0,0 @@ |
|||||||
add_executable(texturedTriangleExample main.cpp TexturedIdentityShader.cpp TexturedTriangle.cpp TGATexture.cpp) |
|
||||||
target_link_libraries(texturedTriangleExample Magnum ${GLUT_LIBRARY}) |
|
||||||
@ -1,64 +0,0 @@ |
|||||||
/*
|
|
||||||
Copyright © 2010, 2011 Vladimír Vondruš <mosra@centrum.cz> |
|
||||||
|
|
||||||
This file is part of Magnum. |
|
||||||
|
|
||||||
Magnum is free software: you can redistribute it and/or modify |
|
||||||
it under the terms of the GNU Lesser General Public License version 3 |
|
||||||
only, as published by the Free Software Foundation. |
|
||||||
|
|
||||||
Magnum is distributed in the hope that it will be useful, |
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
||||||
GNU Lesser General Public License version 3 for more details. |
|
||||||
*/ |
|
||||||
|
|
||||||
#include "TGATexture.h" |
|
||||||
|
|
||||||
#include <iostream> |
|
||||||
#include <fstream> |
|
||||||
|
|
||||||
using namespace std; |
|
||||||
using namespace Magnum::Math; |
|
||||||
|
|
||||||
namespace Magnum { namespace Examples { |
|
||||||
|
|
||||||
TGATexture::TGATexture(const std::string& filename) { |
|
||||||
ifstream image(filename.c_str(), ifstream::binary); |
|
||||||
if(!image.good()) { |
|
||||||
image.close(); |
|
||||||
return; |
|
||||||
} |
|
||||||
|
|
||||||
Header header; |
|
||||||
image.read(reinterpret_cast<char*>(&header), sizeof(Header)); |
|
||||||
|
|
||||||
ColorFormat colorFormat; |
|
||||||
int internalFormat; |
|
||||||
|
|
||||||
switch(header.bpp) { |
|
||||||
case 24: |
|
||||||
colorFormat = BGR; |
|
||||||
internalFormat = RGB; |
|
||||||
break; |
|
||||||
case 32: |
|
||||||
colorFormat = BGRA; |
|
||||||
internalFormat = RGBA; |
|
||||||
break; |
|
||||||
default: |
|
||||||
cerr << (int) header.bpp << endl; |
|
||||||
return; |
|
||||||
} |
|
||||||
|
|
||||||
size_t size = header.width*header.height*header.bpp/8; |
|
||||||
GLubyte* buffer = new GLubyte[size]; |
|
||||||
image.read(reinterpret_cast<char*>(buffer), size); |
|
||||||
image.close(); |
|
||||||
|
|
||||||
GLsizei dimensions[] = {header.width, header.height}; |
|
||||||
|
|
||||||
setData(0, internalFormat, dimensions, colorFormat, buffer); |
|
||||||
delete[] buffer; |
|
||||||
} |
|
||||||
|
|
||||||
}} |
|
||||||
@ -1,49 +0,0 @@ |
|||||||
#ifndef Magnum_Examples_TGATexture_h |
|
||||||
#define Magnum_Examples_TGATexture_h |
|
||||||
/*
|
|
||||||
Copyright © 2010, 2011 Vladimír Vondruš <mosra@centrum.cz> |
|
||||||
|
|
||||||
This file is part of Magnum. |
|
||||||
|
|
||||||
Magnum is free software: you can redistribute it and/or modify |
|
||||||
it under the terms of the GNU Lesser General Public License version 3 |
|
||||||
only, as published by the Free Software Foundation. |
|
||||||
|
|
||||||
Magnum is distributed in the hope that it will be useful, |
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
||||||
GNU Lesser General Public License version 3 for more details. |
|
||||||
*/ |
|
||||||
|
|
||||||
#include "Texture.h" |
|
||||||
|
|
||||||
#include <string> |
|
||||||
|
|
||||||
namespace Magnum { namespace Examples { |
|
||||||
|
|
||||||
class TGATexture: public Texture2D { |
|
||||||
public: |
|
||||||
TGATexture(const std::string& filename); |
|
||||||
|
|
||||||
private: |
|
||||||
#pragma pack(1) |
|
||||||
struct Header { |
|
||||||
GLbyte identsize; /**< @brief Size of ID field that follows header (0) */ |
|
||||||
GLbyte colorMapType; /**< @brief 0 = None, 1 = paletted */ |
|
||||||
GLbyte imageType; /**< @brief 0 = none, 1 = indexed, 2 = rgb, 3 = grey, +8=rle */ |
|
||||||
unsigned short colorMapStart; /**< @brief First color map entry */ |
|
||||||
unsigned short colorMapLength; /**< @brief Number of colors */ |
|
||||||
unsigned char colorMapBpp; /**< @brief Bits per palette entry */ |
|
||||||
unsigned short beginX; /**< @brief Image x origin */ |
|
||||||
unsigned short beginY; /**< @brief Image y origin */ |
|
||||||
unsigned short width; /**< @brief Image width */ |
|
||||||
unsigned short height; /**< @brief Image height */ |
|
||||||
GLbyte bpp; /**< @brief Bits per pixel (8 16, 24, 32) */ |
|
||||||
GLbyte descriptor; /**< @brief Image descriptor */ |
|
||||||
}; |
|
||||||
#pragma pack(8) |
|
||||||
}; |
|
||||||
|
|
||||||
}} |
|
||||||
|
|
||||||
#endif |
|
||||||
@ -1,38 +0,0 @@ |
|||||||
/*
|
|
||||||
Copyright © 2010, 2011 Vladimír Vondruš <mosra@centrum.cz> |
|
||||||
|
|
||||||
This file is part of Magnum. |
|
||||||
|
|
||||||
Magnum is free software: you can redistribute it and/or modify |
|
||||||
it under the terms of the GNU Lesser General Public License version 3 |
|
||||||
only, as published by the Free Software Foundation. |
|
||||||
|
|
||||||
Magnum is distributed in the hope that it will be useful, |
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
||||||
GNU Lesser General Public License version 3 for more details. |
|
||||||
*/ |
|
||||||
|
|
||||||
#include "TexturedIdentityShader.h" |
|
||||||
|
|
||||||
namespace Magnum { namespace Examples { |
|
||||||
|
|
||||||
TexturedIdentityShader::TexturedIdentityShader() { |
|
||||||
Shader* vertexShader = Shader::fromFile(Shader::Vertex, "TexturedIdentityShader.vert"); |
|
||||||
Shader* fragmentShader = Shader::fromFile(Shader::Fragment, "TexturedIdentityShader.frag"); |
|
||||||
|
|
||||||
attachShader(vertexShader); |
|
||||||
attachShader(fragmentShader); |
|
||||||
|
|
||||||
bindAttribute(Vertex, "vertex"); |
|
||||||
bindAttribute(TextureCoordinates, "textureCoordinates"); |
|
||||||
|
|
||||||
link(); |
|
||||||
|
|
||||||
textureUniform = uniformLocation("textureData"); |
|
||||||
|
|
||||||
delete vertexShader; |
|
||||||
delete fragmentShader; |
|
||||||
} |
|
||||||
|
|
||||||
}} |
|
||||||
@ -1,11 +0,0 @@ |
|||||||
#version 330 |
|
||||||
|
|
||||||
uniform sampler2D textureData; |
|
||||||
|
|
||||||
in vec2 varyingTextureCoordinates; |
|
||||||
|
|
||||||
out vec4 fragmentColor; |
|
||||||
|
|
||||||
void main() { |
|
||||||
fragmentColor = texture(textureData, varyingTextureCoordinates); |
|
||||||
} |
|
||||||
@ -1,41 +0,0 @@ |
|||||||
#ifndef Magnum_Examples_TexturedIdentityShader_h |
|
||||||
#define Magnum_Examples_TexturedIdentityShader_h |
|
||||||
/*
|
|
||||||
Copyright © 2010, 2011 Vladimír Vondruš <mosra@centrum.cz> |
|
||||||
|
|
||||||
This file is part of Magnum. |
|
||||||
|
|
||||||
Magnum is free software: you can redistribute it and/or modify |
|
||||||
it under the terms of the GNU Lesser General Public License version 3 |
|
||||||
only, as published by the Free Software Foundation. |
|
||||||
|
|
||||||
Magnum is distributed in the hope that it will be useful, |
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
||||||
GNU Lesser General Public License version 3 for more details. |
|
||||||
*/ |
|
||||||
|
|
||||||
#include "AbstractShaderProgram.h" |
|
||||||
|
|
||||||
namespace Magnum { namespace Examples { |
|
||||||
|
|
||||||
class TexturedIdentityShader: public AbstractShaderProgram { |
|
||||||
public: |
|
||||||
enum Attributes { |
|
||||||
Vertex = 1, |
|
||||||
TextureCoordinates = 2 |
|
||||||
}; |
|
||||||
|
|
||||||
TexturedIdentityShader(); |
|
||||||
|
|
||||||
inline void setTextureUniform(GLuint level) { |
|
||||||
setUniform(textureUniform, level); |
|
||||||
} |
|
||||||
|
|
||||||
private: |
|
||||||
GLint textureUniform; |
|
||||||
}; |
|
||||||
|
|
||||||
}} |
|
||||||
|
|
||||||
#endif |
|
||||||
@ -1,12 +0,0 @@ |
|||||||
#version 330 |
|
||||||
|
|
||||||
in vec4 vertex; |
|
||||||
in vec2 textureCoordinates; |
|
||||||
|
|
||||||
out vec2 varyingTextureCoordinates; |
|
||||||
|
|
||||||
void main() { |
|
||||||
varyingTextureCoordinates = textureCoordinates; |
|
||||||
|
|
||||||
gl_Position = vertex; |
|
||||||
} |
|
||||||
@ -1,51 +0,0 @@ |
|||||||
/*
|
|
||||||
Copyright © 2010, 2011 Vladimír Vondruš <mosra@centrum.cz> |
|
||||||
|
|
||||||
This file is part of Magnum. |
|
||||||
|
|
||||||
Magnum is free software: you can redistribute it and/or modify |
|
||||||
it under the terms of the GNU Lesser General Public License version 3 |
|
||||||
only, as published by the Free Software Foundation. |
|
||||||
|
|
||||||
Magnum is distributed in the hope that it will be useful, |
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
||||||
GNU Lesser General Public License version 3 for more details. |
|
||||||
*/ |
|
||||||
|
|
||||||
#include "TexturedTriangle.h" |
|
||||||
|
|
||||||
#include "Buffer.h" |
|
||||||
|
|
||||||
namespace Magnum { namespace Examples { |
|
||||||
|
|
||||||
TexturedTriangle::TexturedTriangle(const std::string& textureFilename, Object* parent): Object(parent), mesh(Mesh::Triangles, 3), texture(textureFilename) { |
|
||||||
/* Vertices and texture coordinates, interleaved */ |
|
||||||
GLfloat data[] = { |
|
||||||
-0.5f, -0.5f, 0.0f, 1.0f, 0.0f, 0.0f, /* Lower left vertex */ |
|
||||||
0.5f, -0.5f, 0.0f, 1.0f, 1.0f, 0.0f, /* Lower right vertex */ |
|
||||||
0.0f, 0.5f, 0.0f, 1.0f, 0.5f, 1.0f, /* Top vertex */ |
|
||||||
}; |
|
||||||
|
|
||||||
/* Fill the mesh with data */ |
|
||||||
Buffer* buffer = mesh.addBuffer(true); |
|
||||||
buffer->setData(sizeof(data), data, Buffer::DrawStatic); |
|
||||||
|
|
||||||
/* Bind attributes (first vertex data, then color data) */ |
|
||||||
mesh.bindAttribute<Vector4>(buffer, TexturedIdentityShader::Vertex); |
|
||||||
mesh.bindAttribute<Vector2>(buffer, TexturedIdentityShader::TextureCoordinates); |
|
||||||
|
|
||||||
/* Texture */ |
|
||||||
texture.setMagnificationFilter(TGATexture::Linear); |
|
||||||
texture.setMinificationFilter(TGATexture::Linear); |
|
||||||
texture.setWrapping(Math::Vector2<TGATexture::Wrapping>(TGATexture::ClampToEdge, TGATexture::ClampToEdge)); |
|
||||||
} |
|
||||||
|
|
||||||
void TexturedTriangle::draw(const Matrix4& transformationMatrix, const Matrix4& projectionMatrix) { |
|
||||||
texture.bind(); |
|
||||||
shader.use(); |
|
||||||
shader.setTextureUniform(0); |
|
||||||
mesh.draw(); |
|
||||||
} |
|
||||||
|
|
||||||
}} |
|
||||||
@ -1,39 +0,0 @@ |
|||||||
#ifndef Magnum_Examples_TexturedTriangle_h |
|
||||||
#define Magnum_Examples_TexturedTriangle_h |
|
||||||
/*
|
|
||||||
Copyright © 2010, 2011 Vladimír Vondruš <mosra@centrum.cz> |
|
||||||
|
|
||||||
This file is part of Magnum. |
|
||||||
|
|
||||||
Magnum is free software: you can redistribute it and/or modify |
|
||||||
it under the terms of the GNU Lesser General Public License version 3 |
|
||||||
only, as published by the Free Software Foundation. |
|
||||||
|
|
||||||
Magnum is distributed in the hope that it will be useful, |
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
||||||
GNU Lesser General Public License version 3 for more details. |
|
||||||
*/ |
|
||||||
|
|
||||||
#include "Object.h" |
|
||||||
#include "Mesh.h" |
|
||||||
#include "TexturedIdentityShader.h" |
|
||||||
#include "TGATexture.h" |
|
||||||
|
|
||||||
namespace Magnum { namespace Examples { |
|
||||||
|
|
||||||
class TexturedTriangle: public Object { |
|
||||||
public: |
|
||||||
TexturedTriangle(const std::string& textureFilename, Object* parent = 0); |
|
||||||
|
|
||||||
virtual void draw(const Matrix4& transformationMatrix, const Matrix4& projectionMatrix); |
|
||||||
|
|
||||||
private: |
|
||||||
Mesh mesh; |
|
||||||
TexturedIdentityShader shader; |
|
||||||
TGATexture texture; |
|
||||||
}; |
|
||||||
|
|
||||||
}} |
|
||||||
|
|
||||||
#endif |
|
||||||
@ -1,63 +0,0 @@ |
|||||||
/*
|
|
||||||
Copyright © 2010, 2011 Vladimír Vondruš <mosra@centrum.cz> |
|
||||||
|
|
||||||
This file is part of Magnum. |
|
||||||
|
|
||||||
Magnum is free software: you can redistribute it and/or modify |
|
||||||
it under the terms of the GNU Lesser General Public License version 3 |
|
||||||
only, as published by the Free Software Foundation. |
|
||||||
|
|
||||||
Magnum is distributed in the hope that it will be useful, |
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
||||||
GNU Lesser General Public License version 3 for more details. |
|
||||||
*/ |
|
||||||
|
|
||||||
#include <iostream> |
|
||||||
#include <GL/glew.h> |
|
||||||
#include <GL/freeglut.h> |
|
||||||
|
|
||||||
#include "Scene.h" |
|
||||||
#include "TexturedTriangle.h" |
|
||||||
|
|
||||||
Magnum::Scene* s; |
|
||||||
|
|
||||||
/* Wrapper functions so GLUT can handle that */ |
|
||||||
void setViewport(int w, int h) { |
|
||||||
s->setViewport(w, h); |
|
||||||
} |
|
||||||
void draw() { |
|
||||||
s->draw(); |
|
||||||
glutSwapBuffers(); |
|
||||||
} |
|
||||||
|
|
||||||
int main(int argc, char** argv) { |
|
||||||
/* Init GLUT */ |
|
||||||
glutInit(&argc, argv); |
|
||||||
glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGBA|GLUT_DEPTH|GLUT_STENCIL); |
|
||||||
glutInitWindowSize(800, 600); |
|
||||||
glutCreateWindow("Shaded TexturedTriangle example"); |
|
||||||
glutReshapeFunc(setViewport); |
|
||||||
glutDisplayFunc(draw); |
|
||||||
|
|
||||||
/* Init GLEW */ |
|
||||||
GLenum err = glewInit(); |
|
||||||
if(err != GLEW_OK) { |
|
||||||
std::cerr << "GLEW error:" << glewGetErrorString(err) << std::endl; |
|
||||||
return 1; |
|
||||||
} |
|
||||||
|
|
||||||
/* Initialize scene */ |
|
||||||
Magnum::Scene scene; |
|
||||||
s = &scene; |
|
||||||
|
|
||||||
/* Every scene needs a camera */ |
|
||||||
scene.setCamera(new Magnum::Camera(&scene)); |
|
||||||
|
|
||||||
/* Add triangle to the scene */ |
|
||||||
new Magnum::Examples::TexturedTriangle("stone.tga", &scene); |
|
||||||
|
|
||||||
/* Main loop calls draw() periodically and setViewport() on window size change */ |
|
||||||
glutMainLoop(); |
|
||||||
return 0; |
|
||||||
} |
|
||||||
|
Before Width: | Height: | Size: 192 KiB |
@ -1,2 +0,0 @@ |
|||||||
add_executable(triangleExample main.cpp IdentityShader.cpp Triangle.cpp) |
|
||||||
target_link_libraries(triangleExample Magnum ${GLUT_LIBRARY}) |
|
||||||
@ -1,36 +0,0 @@ |
|||||||
/*
|
|
||||||
Copyright © 2010, 2011 Vladimír Vondruš <mosra@centrum.cz> |
|
||||||
|
|
||||||
This file is part of Magnum. |
|
||||||
|
|
||||||
Magnum is free software: you can redistribute it and/or modify |
|
||||||
it under the terms of the GNU Lesser General Public License version 3 |
|
||||||
only, as published by the Free Software Foundation. |
|
||||||
|
|
||||||
Magnum is distributed in the hope that it will be useful, |
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
||||||
GNU Lesser General Public License version 3 for more details. |
|
||||||
*/ |
|
||||||
|
|
||||||
#include "IdentityShader.h" |
|
||||||
|
|
||||||
namespace Magnum { namespace Examples { |
|
||||||
|
|
||||||
IdentityShader::IdentityShader() { |
|
||||||
Shader* vertexShader = Shader::fromFile(Shader::Vertex, "IdentityShader.vert"); |
|
||||||
Shader* fragmentShader = Shader::fromFile(Shader::Fragment, "IdentityShader.frag"); |
|
||||||
|
|
||||||
attachShader(vertexShader); |
|
||||||
attachShader(fragmentShader); |
|
||||||
|
|
||||||
bindAttribute(Vertex, "vertex"); |
|
||||||
bindAttribute(Color, "color"); |
|
||||||
|
|
||||||
link(); |
|
||||||
|
|
||||||
delete vertexShader; |
|
||||||
delete fragmentShader; |
|
||||||
} |
|
||||||
|
|
||||||
}} |
|
||||||
@ -1,9 +0,0 @@ |
|||||||
#version 330 |
|
||||||
|
|
||||||
in vec4 varyingColor; |
|
||||||
|
|
||||||
out vec4 fragmentColor; |
|
||||||
|
|
||||||
void main() { |
|
||||||
fragmentColor = varyingColor; |
|
||||||
} |
|
||||||
@ -1,34 +0,0 @@ |
|||||||
#ifndef Magnum_Examples_IdentityShader_h |
|
||||||
#define Magnum_Examples_IdentityShader_h |
|
||||||
/*
|
|
||||||
Copyright © 2010, 2011 Vladimír Vondruš <mosra@centrum.cz> |
|
||||||
|
|
||||||
This file is part of Magnum. |
|
||||||
|
|
||||||
Magnum is free software: you can redistribute it and/or modify |
|
||||||
it under the terms of the GNU Lesser General Public License version 3 |
|
||||||
only, as published by the Free Software Foundation. |
|
||||||
|
|
||||||
Magnum is distributed in the hope that it will be useful, |
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
||||||
GNU Lesser General Public License version 3 for more details. |
|
||||||
*/ |
|
||||||
|
|
||||||
#include "AbstractShaderProgram.h" |
|
||||||
|
|
||||||
namespace Magnum { namespace Examples { |
|
||||||
|
|
||||||
class IdentityShader: public AbstractShaderProgram { |
|
||||||
public: |
|
||||||
enum Attributes { |
|
||||||
Vertex = 1, |
|
||||||
Color = 2 |
|
||||||
}; |
|
||||||
|
|
||||||
IdentityShader(); |
|
||||||
}; |
|
||||||
|
|
||||||
}} |
|
||||||
|
|
||||||
#endif |
|
||||||
@ -1,12 +0,0 @@ |
|||||||
#version 330 |
|
||||||
|
|
||||||
in vec4 vertex; |
|
||||||
in vec4 color; |
|
||||||
|
|
||||||
out vec4 varyingColor; |
|
||||||
|
|
||||||
void main() { |
|
||||||
varyingColor = color; |
|
||||||
|
|
||||||
gl_Position = vertex; |
|
||||||
} |
|
||||||
@ -1,44 +0,0 @@ |
|||||||
/*
|
|
||||||
Copyright © 2010, 2011 Vladimír Vondruš <mosra@centrum.cz> |
|
||||||
|
|
||||||
This file is part of Magnum. |
|
||||||
|
|
||||||
Magnum is free software: you can redistribute it and/or modify |
|
||||||
it under the terms of the GNU Lesser General Public License version 3 |
|
||||||
only, as published by the Free Software Foundation. |
|
||||||
|
|
||||||
Magnum is distributed in the hope that it will be useful, |
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
||||||
GNU Lesser General Public License version 3 for more details. |
|
||||||
*/ |
|
||||||
|
|
||||||
#include "Triangle.h" |
|
||||||
|
|
||||||
#include "Buffer.h" |
|
||||||
|
|
||||||
namespace Magnum { namespace Examples { |
|
||||||
|
|
||||||
Triangle::Triangle(Object* parent): Object(parent), mesh(Mesh::Triangles, 3) { |
|
||||||
/* Vertices and colors, interleaved */ |
|
||||||
Vector4 data[] = { |
|
||||||
Vector4(-0.5f, -0.5f, 0.0f), Vector4(1.0f, 0.0f, 0.0f), /* Red lower left vertex */ |
|
||||||
Vector4(0.5f, -0.5f, 0.0f), Vector4(0.0f, 1.0f, 0.0f), /* Green lower right vertex */ |
|
||||||
Vector4(0.0f, 0.5f, 0.0f), Vector4(0.0f, 0.0f, 1.0f) /* Blue top vertex */ |
|
||||||
}; |
|
||||||
|
|
||||||
/* Fill the mesh with data */ |
|
||||||
Buffer* buffer = mesh.addBuffer(true); |
|
||||||
buffer->setData(sizeof(data), data, Buffer::DrawStatic); |
|
||||||
|
|
||||||
/* Bind attributes (first vertex data, then color data) */ |
|
||||||
mesh.bindAttribute<Vector4>(buffer, IdentityShader::Vertex); |
|
||||||
mesh.bindAttribute<Vector4>(buffer, IdentityShader::Color); |
|
||||||
} |
|
||||||
|
|
||||||
void Triangle::draw(const Matrix4& transformationMatrix, const Matrix4& projectionMatrix) { |
|
||||||
shader.use(); |
|
||||||
mesh.draw(); |
|
||||||
} |
|
||||||
|
|
||||||
}} |
|
||||||
@ -1,37 +0,0 @@ |
|||||||
#ifndef Magnum_Examples_Triangle_h |
|
||||||
#define Magnum_Examples_Triangle_h |
|
||||||
/*
|
|
||||||
Copyright © 2010, 2011 Vladimír Vondruš <mosra@centrum.cz> |
|
||||||
|
|
||||||
This file is part of Magnum. |
|
||||||
|
|
||||||
Magnum is free software: you can redistribute it and/or modify |
|
||||||
it under the terms of the GNU Lesser General Public License version 3 |
|
||||||
only, as published by the Free Software Foundation. |
|
||||||
|
|
||||||
Magnum is distributed in the hope that it will be useful, |
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
||||||
GNU Lesser General Public License version 3 for more details. |
|
||||||
*/ |
|
||||||
|
|
||||||
#include "Object.h" |
|
||||||
#include "Mesh.h" |
|
||||||
#include "IdentityShader.h" |
|
||||||
|
|
||||||
namespace Magnum { namespace Examples { |
|
||||||
|
|
||||||
class Triangle: public Object { |
|
||||||
public: |
|
||||||
Triangle(Object* parent = 0); |
|
||||||
|
|
||||||
virtual void draw(const Matrix4& transformationMatrix, const Matrix4& projectionMatrix); |
|
||||||
|
|
||||||
private: |
|
||||||
Mesh mesh; |
|
||||||
IdentityShader shader; |
|
||||||
}; |
|
||||||
|
|
||||||
}} |
|
||||||
|
|
||||||
#endif |
|
||||||
@ -1,63 +0,0 @@ |
|||||||
/*
|
|
||||||
Copyright © 2010, 2011 Vladimír Vondruš <mosra@centrum.cz> |
|
||||||
|
|
||||||
This file is part of Magnum. |
|
||||||
|
|
||||||
Magnum is free software: you can redistribute it and/or modify |
|
||||||
it under the terms of the GNU Lesser General Public License version 3 |
|
||||||
only, as published by the Free Software Foundation. |
|
||||||
|
|
||||||
Magnum is distributed in the hope that it will be useful, |
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
||||||
GNU Lesser General Public License version 3 for more details. |
|
||||||
*/ |
|
||||||
|
|
||||||
#include <iostream> |
|
||||||
#include <GL/glew.h> |
|
||||||
#include <GL/freeglut.h> |
|
||||||
|
|
||||||
#include "Scene.h" |
|
||||||
#include "Triangle.h" |
|
||||||
|
|
||||||
Magnum::Scene* s; |
|
||||||
|
|
||||||
/* Wrapper functions so GLUT can handle that */ |
|
||||||
void setViewport(int w, int h) { |
|
||||||
s->setViewport(w, h); |
|
||||||
} |
|
||||||
void draw() { |
|
||||||
s->draw(); |
|
||||||
glutSwapBuffers(); |
|
||||||
} |
|
||||||
|
|
||||||
int main(int argc, char** argv) { |
|
||||||
/* Init GLUT */ |
|
||||||
glutInit(&argc, argv); |
|
||||||
glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGBA|GLUT_DEPTH|GLUT_STENCIL); |
|
||||||
glutInitWindowSize(800, 600); |
|
||||||
glutCreateWindow("Shaded Triangle example"); |
|
||||||
glutReshapeFunc(setViewport); |
|
||||||
glutDisplayFunc(draw); |
|
||||||
|
|
||||||
/* Init GLEW */ |
|
||||||
GLenum err = glewInit(); |
|
||||||
if(err != GLEW_OK) { |
|
||||||
std::cerr << "GLEW error:" << glewGetErrorString(err) << std::endl; |
|
||||||
return 1; |
|
||||||
} |
|
||||||
|
|
||||||
/* Initialize scene */ |
|
||||||
Magnum::Scene scene; |
|
||||||
s = &scene; |
|
||||||
|
|
||||||
/* Every scene needs a camera */ |
|
||||||
scene.setCamera(new Magnum::Camera(&scene)); |
|
||||||
|
|
||||||
/* Add triangle to the scene */ |
|
||||||
new Magnum::Examples::Triangle(&scene); |
|
||||||
|
|
||||||
/* Main loop calls draw() periodically and setViewport() on window size change */ |
|
||||||
glutMainLoop(); |
|
||||||
return 0; |
|
||||||
} |
|
||||||
Loading…
Reference in new issue