You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
77 lines
1.6 KiB
77 lines
1.6 KiB
#include <stdio.h>
|
|
#include <glew.h>
|
|
#include "../common/base.h"
|
|
#include "../common/CELLMath.hpp"
|
|
#include "../common/GlewOpenGL.h"
|
|
#include "tiny_obj_loader.h"
|
|
|
|
using namespace std;
|
|
using namespace CELL;
|
|
|
|
class Viewer : public GlewOpenGL {
|
|
public:
|
|
|
|
struct Vertex {
|
|
float x, y, z;
|
|
float u, v;
|
|
};
|
|
|
|
Viewer(int width, int height, const string& title) : GlewOpenGL(width, height, title) {
|
|
|
|
}
|
|
|
|
void init() {
|
|
_texture = createTexture("/home/blobt/Documents/dev/cpp/opengl2/models/chair/cloth.jpg");
|
|
}
|
|
|
|
void render() {
|
|
glMatrixMode(GL_PROJECTION);
|
|
glLoadIdentity();
|
|
gluPerspective(100, double(_width) / double(_height), 0.1, 1000);
|
|
|
|
Vertex vertex[] = {
|
|
{-1, -1.5, 0, 0, 0},
|
|
{1, -1.5, 0, 1, 0},
|
|
{1, 1.5, 0, 1, 1},
|
|
{-1, 1.5, 0, 0, 1},
|
|
};
|
|
|
|
glMatrixMode(GL_MODELVIEW);
|
|
glLoadIdentity();
|
|
glTranslatef(0, 0, -2);
|
|
|
|
|
|
//开始深度测试,后面绘制的面就不会遮挡前面绘制的面
|
|
glEnable(GL_DEPTH_TEST);
|
|
|
|
//设置顶点
|
|
glEnableClientState(GL_VERTEX_ARRAY);
|
|
glVertexPointer(3, GL_FLOAT, sizeof (Vertex), &vertex[0].x);
|
|
|
|
//设置贴图
|
|
glBindTexture(GL_TEXTURE_2D, _texture);
|
|
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
|
glTexCoordPointer(2, GL_FLOAT, sizeof (Vertex), &vertex[0].u);
|
|
|
|
glDrawArrays(GL_QUADS, 0, 4);
|
|
}
|
|
|
|
~Viewer() {
|
|
|
|
}
|
|
|
|
private:
|
|
GLuint _texture;
|
|
};
|
|
|
|
int main(int argc, char** argv) {
|
|
|
|
if (argc < 2) {
|
|
|
|
}
|
|
|
|
Viewer viewer(1024, 768, "Viewer");
|
|
viewer.loop();
|
|
|
|
return 0;
|
|
}
|