00001
00002 #include "CVert.h"
00003 #include "CTexCoord.h"
00004 #include "common.h"
00005 #include <string>
00006
00010 enum CMeshObjectTyp{
00011 CRectangle,
00012 CCube
00013 };
00014
00016
00021 class CMesh
00022 {
00023 public:
00024
00025 int m_nVertexCount;
00026 CVert* m_pVertices;
00027 CVert* m_pColors;
00028 CTexCoord* m_pTextures;
00029
00030
00031 unsigned int m_nVBOVertices;
00032 unsigned int m_nVBOColors;
00033 unsigned int m_nVBOTextures;
00034
00035 public:
00040 CMesh(CMeshObjectTyp type )
00041 {
00042 typ = type;
00043 switch(typ)
00044 {
00045 case CCube:
00046 m_nVertexCount = 24;
00047 m_pVertices = new CVert[m_nVertexCount];
00048 m_pColors = new CVert[m_nVertexCount];
00049
00050 setVertex(0, 1.0f, 1.0f,0.0f);
00051 setVertex(1, 0.0f, 1.0f,0.0f);
00052 setVertex(2, 0.0f, 1.0f,1.0f);
00053 setVertex(3, 1.0f, 1.0f,1.0f);
00054
00055 setVertex(4, 1.0f,0.0f, 1.0f);
00056 setVertex(5, 0.0f,0.0f, 1.0f);
00057 setVertex(6, 0.0f,0.0f, 0.0f);
00058 setVertex(7, 1.0f,0.0f, 0.0f);
00059
00060 setVertex(8, 1.0f, 1.0f, 1.0f);
00061 setVertex(9, 0.0f, 1.0f, 1.0f);
00062 setVertex(10,0.0f,0.0f, 1.0f);
00063 setVertex(11,1.0f,0.0f, 1.0f);
00064
00065 setVertex(12,1.0f,0.0f,0.0f);
00066 setVertex(13,0.0f,0.0f,0.0f);
00067 setVertex(14,0.0f, 1.0f,0.0f);
00068 setVertex(15,1.0f, 1.0f,0.0f);
00069
00070 setVertex(16,0.0f, 1.0f, 1.0f);
00071 setVertex(17,0.0f, 1.0f,0.0f);
00072 setVertex(18,0.0f,0.0f,0.0f);
00073 setVertex(19,0.0f,0.0f, 1.0f);
00074
00075 setVertex(20,1.0f, 1.0f,0.0f);
00076 setVertex(21,1.0f, 1.0f, 1.0f);
00077 setVertex(22,1.0f,0.0f, 1.0f);
00078 setVertex(23,1.0f,0.0f,0.0f);
00079 break;
00080 case CRectangle:
00081 m_nVertexCount = 4;
00082 m_pVertices = new CVert[m_nVertexCount];
00083 m_pTextures = new CTexCoord[m_nVertexCount];
00084 setVertex(0, 0.0, 0.0,-1,0.0f, 0.0f);
00085 setVertex(1, 1.0, 0.0,-1, 1.0f, 0.0f);
00086 setVertex(2, 1.0, 1.0,-1,1.0f, 1.0f);
00087 setVertex(3, 0.0, 1.0,-1,0.0f, 1.0f);
00088 break;
00089 }
00090 };
00094 ~CMesh();
00095
00103 void setVertex(int i, float x,float y, float z)
00104 {
00105 m_pVertices[i].x =x;
00106 m_pVertices[i].y =y;
00107 m_pVertices[i].z =z;
00108 m_pColors[i].x =x;
00109 m_pColors[i].y =y;
00110 m_pColors[i].z =z;
00111 };
00112
00122 void setVertex(int i, float x,float y, float z, float u, float v)
00123 {
00124 m_pVertices[i].x =x;
00125 m_pVertices[i].y =y;
00126 m_pVertices[i].z =z;
00127 m_pTextures[i].u =u;
00128 m_pTextures[i].v =v;
00129 };
00130
00134 void BuildVBOs()
00135 {
00136 switch(typ)
00137 {
00138 case CCube:
00139 glEnableClientState( GL_VERTEX_ARRAY );
00140 glEnableClientState( GL_COLOR_ARRAY );
00141
00142
00143 glGenBuffersARB( 1, &m_nVBOVertices );
00144 glBindBufferARB( GL_ARRAY_BUFFER_ARB, m_nVBOVertices );
00145
00146 glBufferDataARB( GL_ARRAY_BUFFER_ARB, m_nVertexCount*3*sizeof(float), m_pVertices, GL_STATIC_DRAW_ARB );
00147
00148
00149 glGenBuffersARB( 1, &m_nVBOColors );
00150 glBindBufferARB( GL_ARRAY_BUFFER_ARB, m_nVBOColors );
00151
00152 glBufferDataARB( GL_ARRAY_BUFFER_ARB, m_nVertexCount*3*sizeof(float), m_pColors, GL_STATIC_DRAW_ARB );
00153
00154
00155
00156
00157
00158 std::cout << "VBOs Vertex " << m_nVBOVertices << std::endl;
00159 std::cout << "VBOs Color " << m_nVBOColors << std::endl;
00160 std::cout << "VBOs BUILDED" << std::endl;
00161
00162
00163
00164 break;
00165 case CRectangle:
00166 glEnableClientState( GL_VERTEX_ARRAY );
00167 glEnableClientState( GL_TEXTURE_COORD_ARRAY );
00168
00169
00170 glGenBuffersARB( 1, &m_nVBOVertices );
00171 glBindBufferARB( GL_ARRAY_BUFFER_ARB, m_nVBOVertices );
00172
00173 glBufferDataARB( GL_ARRAY_BUFFER_ARB, m_nVertexCount*3*sizeof(float), m_pVertices, GL_STATIC_DRAW_ARB );
00174
00175 glClientActiveTexture(GL_TEXTURE1);
00176
00177 glGenBuffersARB( 1, &m_nVBOTextures );
00178 glBindBufferARB( GL_ARRAY_BUFFER_ARB, m_nVBOTextures );
00179
00180 glBufferDataARB( GL_ARRAY_BUFFER_ARB, m_nVertexCount*2*sizeof(float), m_pTextures, GL_STATIC_DRAW_ARB );
00181
00182
00183
00184
00185
00186 std::cout << "VBOs Vertex " << m_nVBOVertices << std::endl;
00187 std::cout << "VBOs Color " << m_nVBOColors << std::endl;
00188 std::cout << "VBOs BUILDED" << std::endl;
00189
00190
00191
00192 break;
00193 }
00194 };
00195
00196 private:
00197 CMeshObjectTyp typ;
00198 };