From 8091564a731f3ea08a275197b3935ce0e5078ae2 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Thu, 18 Dec 2014 16:12:30 -0800 Subject: [PATCH] remove all glut --- interface/src/Application.cpp | 2 - interface/src/Util.cpp | 6 -- libraries/gpu/src/gpu/GLUTConfig.h | 25 ------ libraries/render-utils/src/GeometryCache.cpp | 95 +++++++++++++++++++- 4 files changed, 91 insertions(+), 37 deletions(-) delete mode 100644 libraries/gpu/src/gpu/GLUTConfig.h diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index d502e380b5..a7b91db315 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -537,8 +537,6 @@ void Application::initializeGL() { } else { isInitialized = true; } - int argc = 0; - glutInit(&argc, 0); #endif #ifdef WIN32 diff --git a/interface/src/Util.cpp b/interface/src/Util.cpp index 38f18e96d9..d795964c5c 100644 --- a/interface/src/Util.cpp +++ b/interface/src/Util.cpp @@ -33,12 +33,6 @@ using namespace std; -// no clue which versions are affected... -#define WORKAROUND_BROKEN_GLUT_STROKES -// see http://www.opengl.org/resources/libraries/glut/spec3/node78.html - - - void renderWorldBox() { // Show edge of world float red[] = {1, 0, 0}; diff --git a/libraries/gpu/src/gpu/GLUTConfig.h b/libraries/gpu/src/gpu/GLUTConfig.h deleted file mode 100644 index 214f2bb2b0..0000000000 --- a/libraries/gpu/src/gpu/GLUTConfig.h +++ /dev/null @@ -1,25 +0,0 @@ -// -// GPUConfig.h -// libraries/gpu/src/gpu -// -// Created by Brad Hefta-Gaub on 12/17/14. -// Copyright 2014 High Fidelity, Inc. -// -// Distributed under the Apache License, Version 2.0. -// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -// - -#ifndef gpu__GLUTConfig__ -#define gpu__GLUTConfig__ - -// TODO: remove these once we migrate away from GLUT calls -#if defined(__APPLE__) -#include -#elif defined(WIN32) -#include -#else -#include -#endif - - -#endif // gpu__GLUTConfig__ diff --git a/libraries/render-utils/src/GeometryCache.cpp b/libraries/render-utils/src/GeometryCache.cpp index d28702fa20..2837568ef5 100644 --- a/libraries/render-utils/src/GeometryCache.cpp +++ b/libraries/render-utils/src/GeometryCache.cpp @@ -11,7 +11,6 @@ // include this before QOpenGLBuffer, which includes an earlier version of OpenGL #include -#include // TODO - we need to get rid of this ASAP #include @@ -509,7 +508,97 @@ void GeometryCache::renderGrid(int xDivisions, int yDivisions) { } void GeometryCache::renderSolidCube(float size) { - glutSolidCube(size); + VerticesIndices& vbo = _solidCubeVBOs[size]; + const int FLOATS_PER_VERTEX = 3; + const int VERTICES_PER_FACE = 4; + const int NUMBER_OF_FACES = 6; + const int TRIANGLES_PER_FACE = 2; + const int VERTICES_PER_TRIANGLE = 3; + const int vertices = NUMBER_OF_FACES * VERTICES_PER_FACE * FLOATS_PER_VERTEX; + const int indices = NUMBER_OF_FACES * TRIANGLES_PER_FACE * VERTICES_PER_TRIANGLE; + const int vertexPoints = vertices * FLOATS_PER_VERTEX; + if (vbo.first == 0) { + GLfloat* vertexData = new GLfloat[vertexPoints * 2]; // vertices and normals + GLfloat* vertex = vertexData; + float halfSize = size / 2.0f; + + static GLfloat cannonicalVertices[vertexPoints] = + { 1, 1, 1, -1, 1, 1, -1,-1, 1, 1,-1, 1, // v0,v1,v2,v3 (front) + 1, 1, 1, 1,-1, 1, 1,-1,-1, 1, 1,-1, // v0,v3,v4,v5 (right) + 1, 1, 1, 1, 1,-1, -1, 1,-1, -1, 1, 1, // v0,v5,v6,v1 (top) + -1, 1, 1, -1, 1,-1, -1,-1,-1, -1,-1, 1, // v1,v6,v7,v2 (left) + -1,-1,-1, 1,-1,-1, 1,-1, 1, -1,-1, 1, // v7,v4,v3,v2 (bottom) + 1,-1,-1, -1,-1,-1, -1, 1,-1, 1, 1,-1 }; // v4,v7,v6,v5 (back) + + // normal array + static GLfloat cannonicalNormals[vertexPoints] = + { 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, // v0,v1,v2,v3 (front) + 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, // v0,v3,v4,v5 (right) + 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, // v0,v5,v6,v1 (top) + -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, // v1,v6,v7,v2 (left) + 0,-1, 0, 0,-1, 0, 0,-1, 0, 0,-1, 0, // v7,v4,v3,v2 (bottom) + 0, 0,-1, 0, 0,-1, 0, 0,-1, 0, 0,-1 }; // v4,v7,v6,v5 (back) + + // index array of vertex array for glDrawElements() & glDrawRangeElement() + static GLubyte cannonicalIndices[indices] = + { 0, 1, 2, 2, 3, 0, // front + 4, 5, 6, 6, 7, 4, // right + 8, 9,10, 10,11, 8, // top + 12,13,14, 14,15,12, // left + 16,17,18, 18,19,16, // bottom + 20,21,22, 22,23,20 }; // back + + + + GLfloat* cannonicalVertex = &cannonicalVertices[0]; + GLfloat* cannonicalNormal = &cannonicalNormals[0]; + + for (int i = 0; i < vertices; i++) { + //normals + *(vertex++) = *cannonicalNormal++; + *(vertex++) = *cannonicalNormal++; + *(vertex++) = *cannonicalNormal++; + + // vertices + *(vertex++) = halfSize * *cannonicalVertex++; + *(vertex++) = halfSize * *cannonicalVertex++; + *(vertex++) = halfSize * *cannonicalVertex++; + + } + + glGenBuffers(1, &vbo.first); + glBindBuffer(GL_ARRAY_BUFFER, vbo.first); + glBufferData(GL_ARRAY_BUFFER, vertices * NUM_BYTES_PER_VERTEX, vertexData, GL_STATIC_DRAW); + delete[] vertexData; + + GLushort* indexData = new GLushort[indices]; + GLushort* index = indexData; + for (int i = 0; i < indices; i++) { + index[i] = cannonicalIndices[i]; + } + + glGenBuffers(1, &vbo.second); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo.second); + glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices * NUM_BYTES_PER_INDEX, indexData, GL_STATIC_DRAW); + delete[] indexData; + + } else { + glBindBuffer(GL_ARRAY_BUFFER, vbo.first); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo.second); + } + glEnableClientState(GL_VERTEX_ARRAY); + glEnableClientState(GL_NORMAL_ARRAY); + + glNormalPointer(GL_FLOAT, 6 * sizeof(float), 0); + glVertexPointer(3, GL_FLOAT, (6 * sizeof(float)), (const void *)(3 * sizeof(float))); + + glDrawRangeElementsEXT(GL_TRIANGLES, 0, vertices - 1, indices, GL_UNSIGNED_SHORT, 0); + + glDisableClientState(GL_VERTEX_ARRAY); + glDisableClientState(GL_NORMAL_ARRAY); + + glBindBuffer(GL_ARRAY_BUFFER, 0); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); } void GeometryCache::renderWireCube(float size) { @@ -533,7 +622,6 @@ void GeometryCache::renderWireCube(float size) { }; // index array of vertex array for glDrawRangeElement() as a GL_LINES for each edge - const GLubyte LINE_BREAK = static_cast(-1); static GLubyte cannonicalIndices[indices] = { 0, 1, 1, 2, 2, 3, 3, 0, // (top) 4, 5, 5, 6, 6, 7, 7, 4, // (bottom) @@ -571,7 +659,6 @@ void GeometryCache::renderWireCube(float size) { glBindBuffer(GL_ARRAY_BUFFER, 0); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); - }