//--------------------------------------------------------------
void ofVboByteColor::setMesh(const ofMesh & mesh, int usage){
	setVertexData(mesh.getVerticesPointer(),mesh.getNumVertices(),usage);
	setColorData(mesh.getColorsPointer(),mesh.getNumColors(),usage);
	setNormalData(mesh.getNormalsPointer(),mesh.getNumNormals(),usage);
	setTexCoordData(mesh.getTexCoordsPointer(),mesh.getNumTexCoords(),usage);
	setIndexData(mesh.getIndexPointer(), mesh.getNumIndices(), usage);
}
Example #2
0
void Sphere::setupGLBuffers() {
    if(Sphere::initialized) { // no need to resetup
        return;
    }
    setVertexData(); // set the vertex data before using
    size_t dataSize = Sphere::numVert * 4 * sizeof(GLfloat);
    
    // vertex data
    glGenBuffers(1, &Sphere::vBuffer);
    glBindBuffer(GL_ARRAY_BUFFER, Sphere::vBuffer);
    glBufferData(GL_ARRAY_BUFFER, dataSize, Sphere::vertexData, GL_STATIC_DRAW);
    
    glGenBuffers(1, &Sphere::eBuffer);
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, Sphere::eBuffer);
    glBufferData(GL_ELEMENT_ARRAY_BUFFER, Sphere::numVert * sizeof(GLushort), Sphere::elemData, GL_STATIC_DRAW);
    
    glBindBuffer(GL_ARRAY_BUFFER, 0);
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
    
    // shader program
    Sphere::shaderPrg = shaderSetup("Sphere.vert", "Sphere.frag");
    // TODO SETUP VERTEX POSITIONAL DATA AND STUFF
    Sphere::vPosition = glGetAttribLocation(Sphere::shaderPrg, "vPosition" );
    Sphere::transLoc = glGetUniformLocation(Sphere::shaderPrg, "trans");
    
    Sphere::initialized = true;
}
Example #3
0
//--------------------------------------------------------------
void ofVbo::setMesh(const ofMesh & mesh, int usage, bool useColors, bool useTextures, bool useNormals){
	if(mesh.getVertices().empty()){
		ofLogWarning("ofVbo") << "setMesh(): ignoring mesh with no vertices";
		return;
	}
	setVertexData(mesh.getVerticesPointer(),mesh.getNumVertices(),usage);
	if(mesh.hasColors() && useColors){
		setColorData(mesh.getColorsPointer(),mesh.getNumColors(),usage);
		enableColors();
	}else{
		disableColors();
	}
	if(mesh.hasNormals() && useNormals){
		setNormalData(mesh.getNormalsPointer(),mesh.getNumNormals(),usage);
		enableNormals();
	}else{
		disableNormals();
	}
	if(mesh.hasTexCoords() && useTextures){
		setTexCoordData(mesh.getTexCoordsPointer(),mesh.getNumTexCoords(),usage);
		enableTexCoords();
	}else{
		disableTexCoords();
	}
	if(mesh.hasIndices()){
		setIndexData(mesh.getIndexPointer(), mesh.getNumIndices(), usage);
		enableIndices();
	}else{
		disableIndices();
	}
}
Example #4
0
void AceMaskRgbRect::draw(AceProgram* prog, AceTexture* mask, int left, int top, int w, int h, glm::mat4* Projection, float* alphas, float *reds, float *greens, float *blues) {
	prog->activate();

	mask->activate();

	setVertexData(left, top, w, h, alphas, reds, greens, blues);

	glUniformMatrix4fv(prog->uProjection, 1, GL_FALSE, glm::value_ptr((*Projection)));

	glBindBuffer(GL_ARRAY_BUFFER, vid);

	glEnableVertexAttribArray(0);
	glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, 0);

	glEnableVertexAttribArray(1);
	glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, 0, (void*)32);

	glEnableVertexAttribArray(2);
	glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, 0, (void*)96);

	glDrawArrays(GL_TRIANGLE_FAN, 0, 4);

	glDisableVertexAttribArray(0);
	glDisableVertexAttribArray(1);
	glDisableVertexAttribArray(2);

	mask->deactivate();
}
Example #5
0
RenderMesh::RenderMesh(OBJ* o) : Shape()
{
    GLfloat* vertices = new GLfloat[o->vboData.size()];
    for (int i = 0; i < o->vboData.size(); i++) {
        vertices[i] = o->vboData.at(i);
    }
    setVertexData(vertices, sizeof(GLfloat)*o->vboData.size(), o->vertexCount);
    setAttribute(0, 3, GL_FLOAT, GL_FALSE, 8 * sizeof(GLfloat), 0);
    setAttribute(1, 3, GL_FLOAT, GL_TRUE, 8 * sizeof(GLfloat), (3 * sizeof(GLfloat)));
    setAttribute(2, 2, GL_FLOAT, GL_FALSE, 8 * sizeof(GLfloat), (6 * sizeof(GLfloat)));
    delete[] vertices;
}
Example #6
0
// THIS NEEDS TO BE COMPLETED FOR TASK 1
// Reads in data from the file with the given filename and creates a newGraph
// The file must be of the format
// numVertices
// v0 v1 v2 v3
// v1 v2 v4
Graph readGraph(char * filename) {
   FILE *fp;
   fp = fopen (filename, "r"); // open data file
   assert (fp != NULL);
  
   int city = 0;
   int dest = 0;
   char c = 0;
   // First line of file has the number of vertices
   int numV;
   fscanf(fp, "%d", &numV);
   Graph g = newGraph(numV);   
   
   // scan through file and insert edges into graph
   int counter = 0;   
   while (counter < numV) {
     fscanf(fp, "%d", &city);
     counter++;
     while (c != '\n') {
          fscanf (fp, "%d", &dest);
          insertE(g, mkEdge(city, dest));
          c = getc(fp);
     }
     c = 0;
   }   

   int v;
   char name[100];
   char capital[100];
   long population;  
     
   while(fscanf(fp, "%d %s %s %ld", &v, name, capital, &population) == 4) {
      setVertexData(g, v, name, capital, population);
   }
   fclose(fp);
   return g;
}
//--------------------------------------------------------------
void ofVboByteColor::setVertexData(const ofVec2f * verts, int total, int usage) {
	setVertexData(&verts[0].x,2,total,usage,sizeof(ofVec2f));
}
Example #8
0
//--------------------------------------------------------------
void ofVbo::setVertexData(const ofVec3f * verts, int total, int usage) {
	setVertexData(&verts[0].x,3,total,usage,sizeof(ofVec3f));
}
Example #9
0
//--------------------------------------------------------------
void ofVbo::setMesh(const ofMesh & mesh, int usage){
	setVertexData(mesh.getVerticesPointer(),mesh.getNumVertices(),usage,sizeof(ofVec3f));
	setColorData(mesh.getColorsPointer(),mesh.getNumColors(),usage,sizeof(ofColor));
	setNormalData(mesh.getNormalsPointer(),mesh.getNumNormals(),usage,sizeof(ofVec3f));
	setTexCoordData(mesh.getTexCoordsPointer(),mesh.getNumTexCoords(),usage,sizeof(ofVec2f));
}