-
Notifications
You must be signed in to change notification settings - Fork 4
/
display_main.cpp
102 lines (85 loc) · 2.75 KB
/
display_main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <GLUT/GLUT.h>
#include "GL/GLProgram.h"
#include "GL/GLLightScene.h"
#include "GL/GLBasic3DObject.h"
#include "GL/GLvboBuffer.h"
#include "GL/GLTexture.h"
#include "GL/GLCurveObject.h"
#include "GL/GLLightCurveObj.h"
#include "GL/GLBezier.h"
#include "BasicFunctionDeter.h"
#include "vertex/GL_position.h"
#include "vertex/GL_texcord.h"
#include "vertex/GL_Normal.h"
#include "math/GLMatrix4.h"
#include "math/GLSphere.h"
#include "core/GLRasterization.h"
#include "utils/GLDebug.h"
#include "core/GLBmp.h"
#include <fstream>
#include <sstream>
#include "3d/CCBundle3D.h"
#define PI 3.141592654
using namespace std;
static GLObject* gObj = NULL;
GLObject* initObject()
{
GPPtr<Bundle3D::Buffer> buffer;
std::ifstream inputc3d("/Users/jiangxiaotang/fbx/NIAO/NIAO.c3b");
std::ostringstream output3d;
output3d << inputc3d.rdbuf();
buffer = new Bundle3D::Buffer(output3d.str().c_str(), output3d.str().size());
auto bundle3D = Bundle3D::createBundle();
bundle3D->load(buffer.get());
MeshDatas rmeshDatas;
bundle3D->loadMeshDatas(rmeshDatas);
MaterialDatas rmaterialDatas;
bundle3D->loadMaterials(rmaterialDatas);
NodeDatas nodeDatas;
bundle3D->loadNodes(nodeDatas);
auto obj = new GLBasic3DObject(nodeDatas, rmeshDatas, rmaterialDatas);
Bundle3D::destroyBundle(bundle3D);
obj->onPrepare();
return obj;
}
static void init()
{
gObj = initObject();
}
static void display(void)
{
//glDisable(GL_DEPTH_TEST);
glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
glCullFace(GL_FRONT);
glClearDepth(1.0);
glDepthFunc(GL_LESS);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
//GLMatrix4 projection;
GLMatrix4 projection = GLMatrix4::projection(-30, 30, -30, 30, 40, 1000, 1);
GLMatrix4 V;
GLMatrix4 model;
static float a = 0.01;
//model.setRotate(-a,0.1*a,0.3*a,a);
model.setRotate(0.0,1.0,0.0,a);
a+=0.01;
V.setTranslate(0, 0, -100);
gObj->onDraw(model, V, projection);
glutSwapBuffers();
}
int main(int argc, char* argv[])
{
glutInit(&argc, argv); // Initialize GLUT
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB|GLUT_DEPTH); // Set display mode
glutInitWindowPosition(50,100); // Set top-left display window position
glutInitWindowSize(500, 500); // set display window width and height
glutCreateWindow("An Example OpenGL Program"); // Create display window
init();
glutDisplayFunc(display); // Send graphics to display window
glutIdleFunc(display);
glutMainLoop(); // Display everything and wait
return 1;
}