source: nanovis/tags/1.2.3/graphics/Geometry.cpp @ 6369

Last change on this file since 6369 was 3465, checked in by ldelgass, 11 years ago

Rename R2 library to nv::graphics and nv::util.

  • Property svn:eol-style set to native
File size: 1.8 KB
Line 
1/* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2/*
3 *  Copyright (c) 2004-2013  HUBzero Foundation, LLC
4 */
5
6#include <GL/glew.h>
7#include <GL/gl.h>
8
9#include "Geometry.h"
10
11using namespace nv::graphics;
12
13Geometry::Geometry(int primitive,
14                   VertexBuffer *vertexBuffer,
15                   IndexBuffer *indexBuffer) :
16    _vertexBuffer(vertexBuffer),
17    _colorBuffer(0),
18    _indexBuffer(indexBuffer),
19    _primitiveType(primitive)
20{
21}
22
23Geometry::Geometry(int primitive,
24                   VertexBuffer *vertexBuffer,
25                   VertexBuffer *colorBuffer,
26                   IndexBuffer *indexBuffer) :
27    _vertexBuffer(vertexBuffer),
28    _colorBuffer(colorBuffer),
29    _indexBuffer(indexBuffer),
30    _primitiveType(primitive)
31{
32}
33
34Geometry::~Geometry()
35{
36}
37
38void
39Geometry::render()
40{
41    //glDisableClientState(GL_NORMAL_ARRAY);
42    //glDisableClientState(GL_TEXTURE_COORD_ARRAY);
43    glEnableClientState(GL_VERTEX_ARRAY);
44    glBindBuffer(GL_ARRAY_BUFFER, _vertexBuffer->getGraphicObjectID());
45    glVertexPointer(3, GL_FLOAT, 0, 0);
46
47    if (_colorBuffer) {
48        glEnableClientState(GL_COLOR_ARRAY);
49        glBindBuffer(GL_ARRAY_BUFFER, _colorBuffer->getGraphicObjectID());
50        glColorPointer(3, GL_FLOAT, 0, 0);
51    } else {
52        glDisableClientState(GL_COLOR_ARRAY);
53    }
54    glBindBuffer(GL_ARRAY_BUFFER, 0);
55
56    if (_indexBuffer) {
57        glDrawElements(GL_QUADS, _indexBuffer->getIndexCount(), GL_UNSIGNED_INT,
58                       _indexBuffer->getData());
59    } else {
60        glBindBuffer(GL_ARRAY_BUFFER, 0);
61        glDrawArrays(_primitiveType, 0, _vertexBuffer->getVertexCount());
62    }
63
64    glDisableClientState(GL_VERTEX_ARRAY);
65    if (_colorBuffer) {
66        glDisableClientState(GL_COLOR_ARRAY);
67    }
68}
Note: See TracBrowser for help on using the repository browser.