Example #1
0
void render(void) {
    glUseProgram(shader_map1["id"]);
    setUniformVariables();

    setAttribPointers();
    // glDrawArrays(mode, first, count)
    glDrawArrays(GL_TRIANGLES, 0, numElements);

    disableBufObjs();

    glUseProgram(0);

    checkError("render");
}
void MeshObj::render(GLenum mode) {
	setAttribPointers();
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, idxBufObj);

    // render the vertices to screen as triangles
    // glDrawArrays(mode, first, count);
    //glDrawArrays(mode, 0, vertArrObj.size());
    
    // glDrawElements(mode, count, type, idxPtr);
    glDrawElements(mode, idxArrObj.size(), GL_UNSIGNED_INT, 
        bufferObjectPtr(0));
    
    disableBufObjs();
    
    checkError("MeshObj::render");
} // end render
Example #3
0
void render(void) {
	glUseProgram(shader_map1["id"]);
	setUniformVariables();
	
	setAttribPointers();
    // render the vertices to screen as triangles, start index 0
    // glDrawArrays(mode, first, count)
    //glDrawArrays(GL_TRIANGLES, 0, numElements);
    // modified 26 Jan
    // render the vertices to screen as triangles, from 6 vertices
    // glDrawElements(mode, count, type, idxPtr)
    glDrawElements(GL_TRIANGLES, sizeof(idxArr) / sizeof(GLuint), 
    	GL_UNSIGNED_INT, 0);
	
	disableBufObjs();
	
	glUseProgram(0);

	checkError("render");
}
Example #4
0
void Cuboid::create(GLfloat sizeX, GLfloat sizeY, GLfloat sizeZ, const glm::vec4& color) {
	// Vertices
	std::vector<VertexFormat> vertices;
	glm::vec3 normal;
	// Front face
	normal = glm::vec3(0.0, 0.0, 1.0);
	vertices.push_back(VertexFormat(glm::vec3(-sizeX * 0.5f, -sizeY * 0.5f, sizeZ * 0.5f), normal, glm::vec2(0, 0), glm::vec4(color)));
	vertices.push_back(VertexFormat(glm::vec3(sizeX * 0.5f, -sizeY * 0.5f, sizeZ * 0.5f), normal, glm::vec2(1, 0), glm::vec4(color)));
	vertices.push_back(VertexFormat(glm::vec3(sizeX * 0.5f, sizeY * 0.5f, sizeZ * 0.5f), normal, glm::vec2(1, 1), glm::vec4(color)));
	vertices.push_back(VertexFormat(glm::vec3(-sizeX * 0.5f, sizeY * 0.5f, sizeZ * 0.5f), normal, glm::vec2(0, 1), glm::vec4(color)));
	// Right face
	normal = glm::vec3(1.0, 0.0, 0.0);
	vertices.push_back(VertexFormat(glm::vec3(sizeX * 0.5f, sizeY * 0.5f, sizeZ * 0.5f), normal, glm::vec2(0, 0), glm::vec4(color)));
	vertices.push_back(VertexFormat(glm::vec3(sizeX * 0.5f, sizeY * 0.5f, -sizeZ * 0.5f), normal, glm::vec2(1, 0), glm::vec4(color)));
	vertices.push_back(VertexFormat(glm::vec3(sizeX * 0.5f, -sizeY * 0.5f, -sizeZ * 0.5f), normal, glm::vec2(1, 1), glm::vec4(color)));
	vertices.push_back(VertexFormat(glm::vec3(sizeX * 0.5f, -sizeY * 0.5f, sizeZ * 0.5f), normal, glm::vec2(0, 1), glm::vec4(color)));
	// Back face
	normal = glm::vec3(0.0, 0.0, -1.0);
	vertices.push_back(VertexFormat(glm::vec3(-sizeX * 0.5f, -sizeY * 0.5f, -sizeZ * 0.5f), normal, glm::vec2(0, 0), glm::vec4(color)));
	vertices.push_back(VertexFormat(glm::vec3(sizeX * 0.5f, -sizeY * 0.5f, -sizeZ * 0.5f), normal, glm::vec2(1, 0), glm::vec4(color)));
	vertices.push_back(VertexFormat(glm::vec3(sizeX * 0.5f, sizeY * 0.5f, -sizeZ * 0.5f), normal, glm::vec2(1, 1), glm::vec4(color)));
	vertices.push_back(VertexFormat(glm::vec3(-sizeX * 0.5f, sizeY * 0.5f, -sizeZ * 0.5f), normal, glm::vec2(0, 1), glm::vec4(color)));
	// Left face
	normal = glm::vec3(-1.0, 0.0, 0.0);
	vertices.push_back(VertexFormat(glm::vec3(-sizeX * 0.5f, -sizeY * 0.5f, -sizeZ * 0.5f), normal, glm::vec2(0, 0), glm::vec4(color)));
	vertices.push_back(VertexFormat(glm::vec3(-sizeX * 0.5f, -sizeY * 0.5f, sizeZ * 0.5f), normal, glm::vec2(1, 0), glm::vec4(color)));
	vertices.push_back(VertexFormat(glm::vec3(-sizeX * 0.5f, sizeY * 0.5f, sizeZ * 0.5f), normal, glm::vec2(1, 1), glm::vec4(color)));
	vertices.push_back(VertexFormat(glm::vec3(-sizeX * 0.5f, sizeY * 0.5f, -sizeZ * 0.5f), normal, glm::vec2(0, 1), glm::vec4(color)));
	// Top face
	normal = glm::vec3(0.0, 1.0, 0.0);
	vertices.push_back(VertexFormat(glm::vec3(sizeX * 0.5f, sizeY * 0.5f, sizeZ * 0.5f), normal, glm::vec2(0, 0), glm::vec4(color)));
	vertices.push_back(VertexFormat(glm::vec3(-sizeX * 0.5f, sizeY * 0.5f, sizeZ * 0.5f), normal, glm::vec2(1, 0), glm::vec4(color)));
	vertices.push_back(VertexFormat(glm::vec3(-sizeX * 0.5f, sizeY * 0.5f, -sizeZ * 0.5f), normal, glm::vec2(1, 1), glm::vec4(color)));
	vertices.push_back(VertexFormat(glm::vec3(sizeX * 0.5f, sizeY * 0.5f, -sizeZ * 0.5f), normal, glm::vec2(0, 1), glm::vec4(color)));
	// Bottom face
	normal = glm::vec3(0.0, -1.0, 0.0);
	vertices.push_back(VertexFormat(glm::vec3(-sizeX * 0.5f, -sizeY * 0.5f, -sizeZ * 0.5f), normal, glm::vec2(0, 0), glm::vec4(color)));
	vertices.push_back(VertexFormat(glm::vec3(sizeX * 0.5f, -sizeY * 0.5f, -sizeZ * 0.5f), normal, glm::vec2(1, 0), glm::vec4(color)));
	vertices.push_back(VertexFormat(glm::vec3(sizeX * 0.5f, -sizeY * 0.5f, sizeZ * 0.5f), normal, glm::vec2(1, 1), glm::vec4(color)));
	vertices.push_back(VertexFormat(glm::vec3(-sizeX * 0.5f, -sizeY * 0.5f, sizeZ * 0.5f), normal, glm::vec2(0, 1), glm::vec4(color)));

	// Indices
	std::vector<GLuint> indices = {
		0, 1, 2, 0, 2, 3,
		4, 5, 6, 4, 6, 7,
		8, 9, 10, 8, 10, 11,
		12, 13, 14, 12, 14, 15,
		16, 17, 18, 16, 18, 19,
		20, 21, 22, 20, 22, 23
	};

	GLuint vao;
	glGenVertexArrays(1, &vao);
	glBindVertexArray(vao);
	GLuint vbo;
	glGenBuffers(1, &vbo);
	glBindBuffer(GL_ARRAY_BUFFER, vbo);
	glBufferData(GL_ARRAY_BUFFER, vertices.size() * sizeof(VertexFormat), &vertices[0], GL_STATIC_DRAW);
	GLuint ibo;
	glGenBuffers(1, &ibo);
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo);
	glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices.size() * sizeof(GLuint), &indices[0], GL_STATIC_DRAW);

	setAttribPointers();

	this->vao = vao;
	this->vbos.push_back(vbo);
	this->vbos.push_back(ibo);
}