Beispiel #1
0
void        Cube::initWithScale(float  scale)
{
	float     *vertex, *normal, *texCoord,*tangent;
	_numberOfIndice = esGenCube(scale, &vertex, &normal, &texCoord,&tangent ,&_numberOfVertex);
//
	glGenBuffers(1, &_vertexVBO);
	glBindBuffer(GL_ARRAY_BUFFER, _vertexVBO);
	glBufferData(GL_ARRAY_BUFFER, 3 * sizeof(float)*_numberOfVertex,vertex,GL_STATIC_DRAW);
//
	glGenBuffers(1, &_normalVBO);
	glBindBuffer(GL_ARRAY_BUFFER, _normalVBO);
	glBufferData(GL_ARRAY_BUFFER, 3 * sizeof(float)*_numberOfVertex, normal,GL_STATIC_DRAW);
//
	glGenBuffers(1, &_texCoordVBO);
	glBindBuffer(GL_ARRAY_BUFFER, _texCoordVBO);
	glBufferData(GL_ARRAY_BUFFER, 3 * sizeof(float)*_numberOfVertex, texCoord, GL_STATIC_DRAW);
//
	glGenBuffers(1, &_tangentVBO);
	glBindBuffer(GL_ARRAY_BUFFER, _tangentVBO);
	glBufferData(GL_ARRAY_BUFFER, sizeof(float) * 3 * _numberOfVertex, tangent, GL_STATIC_DRAW);
//
//free memory
	delete  vertex;
	delete  normal;
	delete  texCoord;
	delete  tangent;
	vertex = NULL;
	normal = NULL;
	texCoord = NULL;
}
///
// Initialize the shader and program object
//
int Init ( ESContext *esContext )
{
   esContext->userData = malloc(sizeof(UserData));
	
   UserData *userData = esContext->userData;
   GLbyte vShaderStr[] =  
      "uniform mat4 u_mvpMatrix;                   \n"
      "attribute vec4 a_position;                  \n"
      "void main()                                 \n"
      "{                                           \n"
      "   gl_Position = u_mvpMatrix * a_position;  \n"
      "}                                           \n";
   
   GLbyte fShaderStr[] =  
      "precision mediump float;                            \n"
      "void main()                                         \n"
      "{                                                   \n"
      "  gl_FragColor = vec4( 1.0, 0.0, 0.0, 1.0 );        \n"
      "}                                                   \n";

   // Load the shaders and get a linked program object
   userData->programObject = esLoadProgram ( vShaderStr, fShaderStr );

   // Get the attribute locations
   userData->positionLoc = glGetAttribLocation ( userData->programObject, "a_position" );

   // Get the uniform locations
   userData->mvpLoc = glGetUniformLocation( userData->programObject, "u_mvpMatrix" );
   
   // Generate the vertex data
   userData->numIndices = esGenCube( 1.0, &userData->vertices,
                                     NULL, NULL, &userData->indices );
   
   // Starting rotation angle for the cube
   userData->angle = 45.0f;

   glClearColor ( 0.0f, 0.0f, 0.0f, 1.0f );
   return GL_TRUE;
}
Beispiel #3
0
void Mesh::makeMeACube(float size) {
    nbrOfIndices = esGenCube(size, positions, normals, texCoords, triangles);
}