void Model::draw(int ranges) const { if (!vbuffer) read_file(); glBindBuffer(GL_ARRAY_BUFFER, vbuffer); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibuffer); const junk::element& vertex = data_set->get_element("vertex"); bool vertex_array = false; bool normal_array = false; bool color_array = false; BOOST_FOREACH(const junk::attribute& attr, vertex.attributes) { if (attr.name == "position") { vertex_array = true; glEnableClientState(GL_VERTEX_ARRAY); glVertexPointer(attr.size, gl_type(attr.type), size_in_bytes(vertex), (const GLvoid*) attr.offset); } else if (attr.name == "normal") { normal_array = true; glEnableClientState(GL_NORMAL_ARRAY); glNormalPointer(gl_type(attr.type), size_in_bytes(vertex), (const GLvoid*) attr.offset); } else if (attr.name == "color") { color_array = true; glEnableClientState(GL_COLOR_ARRAY); glColorPointer(attr.size, gl_type(attr.type), size_in_bytes(vertex), (const GLvoid*) attr.offset); } } std::size_t faces = data_set->get_size("face"); for (int i = 0; i < ranges; ++i) { int frag = faces / ranges; int size = ((i + 1) * (frag + 1) * 3) - (i * frag * 3); GLvoid* index = (char*) NULL + (i * frag * 3 * sizeof(unsigned int)); set_color(float(i) / float(ranges)); glDrawElements(GL_TRIANGLES, size, GL_UNSIGNED_INT, index); } if (vertex_array) glDisableClientState(GL_VERTEX_ARRAY); if (normal_array) glDisableClientState(GL_NORMAL_ARRAY); if (color_array) glDisableClientState(GL_COLOR_ARRAY); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); glBindBuffer(GL_ARRAY_BUFFER, 0); }
Texture::Texture(uint32_t id, const Texture_description& description) : OpenGL_object(id), description_(description), internal_type_(gl_type(description)) { description_.dimensions.z = std::max(description.dimensions.z, uint32_t(1)); }
ogl_abstract_texture2d::ogl_abstract_texture2d(unsigned nrows, unsigned ncols, char* buffer) : nrows_(nrows), ncols_(ncols), buffer_(buffer) { // Init resource, create texture glGenTextures(1, &gl_id_); check_gl_error(); assert(gl_id_); glBindTexture(GL_TEXTURE_2D, gl_id_); glPixelStorei(GL_UNPACK_ALIGNMENT,1); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, ncols_, nrows_, 0, gl_format(), gl_type(), buffer_); check_gl_error(); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glBindTexture(GL_TEXTURE_2D, 0); load(); }
virtual texture ogl_abstract_texture2d::to_texture() { assert(gl_id_); return texture(ncols_, nrows_, gl_type(), gl_format(), GL_NEAREST, gl_id_); }
inline GLenum gl_type(ArrayFixed<Image::SampleType,4> x) {return gl_type(half{});}