Skip to content

Commit

Permalink
Remove glBegin/glEnd from World.cxx, Octree.cxx & Occluder.cxx
Browse files Browse the repository at this point in the history
  • Loading branch information
atupone committed Dec 14, 2023
1 parent 024279d commit e100f21
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 74 deletions.
2 changes: 1 addition & 1 deletion include/CollisionManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ typedef struct

// well you know my name is Simon, and I like to do drawings
typedef void (*DrawLinesFunc)
(int pointCount, float (*points)[3], int color);
(int pointCount, const glm::vec3 points[], int color);


class CollisionManager
Expand Down
74 changes: 39 additions & 35 deletions src/bzflag/World.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1247,7 +1247,7 @@ bool World::writeWorld(const std::string& filename, std::string& fullname)
return true;
}

static void drawLines (int count, float (*vertices)[3], int color)
static void drawLines (int count, const glm::vec3 vertices[], int color)
{
const float colors[][4] =
{
Expand All @@ -1267,19 +1267,20 @@ static void drawLines (int count, float (*vertices)[3], int color)
colors[color][2],
colors[color][3]);

glBegin (GL_LINE_STRIP);
for (int i = 0; i < count; i++)
glVertex3fv (vertices[i]);
glEnd ();
Vertex_Chunk chunk(Vertex_Chunk::V, count);
chunk.vertexData(vertices);
chunk.draw(GL_LINE_STRIP);

return;
}


static void drawInsideOutsidePoints()
{
std::vector<const float*> insides;
std::vector<const float*> outsides;
std::vector<glm::vec3> insides;
std::vector<glm::vec3> outsides;
std::vector<glm::vec3> insidesLine;
std::vector<glm::vec3> outsidesLine;

const ObstacleList& meshes = OBSTACLEMGR.getMeshes();
for (unsigned int i = 0; i < meshes.size(); i++)
Expand All @@ -1290,16 +1291,28 @@ static void drawInsideOutsidePoints()
const afvec3* checkPoints = mesh->getCheckPoints();
for (int c = 0; c < checkCount; c++)
{
const glm::vec3 point = glm::vec3(
checkPoints[c][0],
checkPoints[c][1],
checkPoints[c][2]);
const glm::vec3 point0 = glm::vec3(
checkPoints[c][0],
checkPoints[c][1],
0.0f);
switch (checkTypes[c])
{
case MeshObstacle::CheckInside:
{
insides.push_back(checkPoints[c]);
insides.push_back(point);
insidesLine.push_back(point0);
insidesLine.push_back(point);
break;
}
case MeshObstacle::CheckOutside:
{
outsides.push_back(checkPoints[c]);
outsides.push_back(point);
outsidesLine.push_back(point0);
outsidesLine.push_back(point);
break;
}
default:
Expand All @@ -1309,6 +1322,15 @@ static void drawInsideOutsidePoints()
}
}
}
Vertex_Chunk vboInside(Vertex_Chunk::V, insides.size());
Vertex_Chunk vboOutside(Vertex_Chunk::V, outsides.size());
Vertex_Chunk vboInsideLine(Vertex_Chunk::V, insidesLine.size());
Vertex_Chunk vboOutsideLine(Vertex_Chunk::V, outsidesLine.size());
vboInside.vertexData(insides);
vboOutside.vertexData(outsides);
vboInsideLine.vertexData(insidesLine);
vboOutsideLine.vertexData(outsidesLine);


glPushAttrib(GL_DEPTH_BUFFER_BIT | GL_POINT_BIT | GL_LINE_BIT);

Expand All @@ -1318,33 +1340,15 @@ static void drawInsideOutsidePoints()
glLineWidth(1.49f);
glPointSize(4.49f);

glBegin(GL_POINTS);
{
glColor4f(0.0f, 1.0f, 0.0f, 0.8f);
for (size_t i = 0; i < insides.size(); i++)
glVertex3fv(insides[i]);
glColor4f(1.0f, 0.0f, 0.0f, 0.8f);
for (size_t i = 0; i < outsides.size(); i++)
glVertex3fv(outsides[i]);
}
glEnd();
glColor4f(0.0f, 1.0f, 0.0f, 0.8f);
vboInside.draw(GL_POINTS);
glColor4f(1.0f, 0.0f, 0.0f, 0.8f);
vboOutside.draw(GL_POINTS);

glBegin(GL_LINES);
{
glColor4f(0.0f, 1.0f, 0.0f, 0.2f);
for (size_t i = 0; i < insides.size(); i++)
{
glVertex3f(insides[i][0], insides[i][1], 0.0f);
glVertex3fv(insides[i]);
}
glColor4f(1.0f, 0.0f, 0.0f, 0.2f);
for (size_t i = 0; i < outsides.size(); i++)
{
glVertex3f(outsides[i][0], outsides[i][1], 0.0f);
glVertex3fv(outsides[i]);
}
}
glEnd();
glColor4f(0.0f, 1.0f, 0.0f, 0.2f);
vboInsideLine.draw(GL_LINES);
glColor4f(1.0f, 0.0f, 0.0f, 0.2f);
vboOutsideLine.draw(GL_LINES);

glPopAttrib();
}
Expand Down
4 changes: 2 additions & 2 deletions src/game/CollisionManager.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -942,7 +942,7 @@ void ColDetNode::tallyStats()
void ColDetNode::draw(DrawLinesFunc drawLinesFunc)
{
int x, y, z, c;
float points[5][3];
glm::vec3 points[5];
const glm::vec3 exts[2] = { extents.mins, extents.maxs };

// pick a color
Expand All @@ -968,7 +968,7 @@ void ColDetNode::draw(DrawLinesFunc drawLinesFunc)
points[c][1] = exts[y][1];
points[c][2] = exts[z][2];
}
memcpy (points[4], points[0], sizeof (points[4]));
points[4] = points[0];
drawLinesFunc (5, points, color);
}

Expand Down
45 changes: 27 additions & 18 deletions src/scene/Occluder.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "Frustum.h"
#include "Intersect.h"
#include "StateDatabase.h"
#include "Vertex_Chunk.h"


//////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -403,7 +404,7 @@ void Occluder::draw() const
if (DrawNormals)
{
// the tri-wall 'getSphere()' center sucks...
float center[3];
glm::vec3 center;
for (int a = 0; a < 3; a++)
{
center[a] = 0.0f;
Expand All @@ -412,59 +413,67 @@ void Occluder::draw() const
center[a] = center[a] / (float) vertexCount;
}

float outwards[3];
glm::vec3 outwards;
outwards[0] = center[0] - (length * planes[0][0]);
outwards[1] = center[1] - (length * planes[0][1]);
outwards[2] = center[2] - (length * planes[0][2]);

// draw the plane normal
glBegin (GL_LINES);
glm::vec3 ver[2];
ver[0] = center;
ver[1] = outwards;

glColor4f(colors[0][0], colors[0][1], colors[0][2], colors[0][3]);
glVertex3fv (center);
glVertex3fv (outwards);
glEnd ();
// draw the plane normal
Vertex_Chunk vbo(Vertex_Chunk::V, 2);
vbo.vertexData(ver);
vbo.draw(GL_LINES);
}

// drawn the edges and normals
if (DrawEdges || DrawNormals)
{
std::vector<glm::vec3> ver;
for (v = 0; v < vertexCount; v++)
{
float midpoint[3];
float outwards[3];
glm::vec3 midpoint;
glm::vec3 outwards;
int vn = (v + 1) % vertexCount;
for (int a = 0; a < 3; a++)
{
midpoint[a] = 0.5f * (vertices[v][a] + vertices[vn][a]);
outwards[a] = midpoint[a] - (length * planes[vn + 1][a]);
}
int index = (v % 4) + 1;
glBegin (GL_LINES);
glColor4f(colors[index][0], colors[index][1], colors[index][2], colors[index][3]);
ver.clear();
if (DrawEdges)
{
glVertex3fv (vertices[v]);
glVertex3fv (vertices[vn]);
ver.push_back(glm::make_vec3(vertices[v]));
ver.push_back(glm::make_vec3(vertices[vn]));
}
if (DrawNormals)
{
glVertex3fv (midpoint);
glVertex3fv (outwards);
ver.push_back(midpoint);
ver.push_back(outwards);
}
glEnd();
Vertex_Chunk vbo(Vertex_Chunk::V, ver.size());
vbo.vertexData(ver);
vbo.draw(GL_LINES);
}
}

// draw some nice vertex points
if (DrawVertices)
{
glm::vec3 ver[1];
for (v = 0; v < vertexCount; v++)
{
int index = (v % 4) + 1;
glBegin (GL_POINTS);
ver[0] = glm::make_vec3(vertices[v]);
glColor4f(colors[index][0], colors[index][1], colors[index][2], colors[index][3]);
glVertex3fv (vertices[v]);
glEnd();
Vertex_Chunk vbo(Vertex_Chunk::V, 1);
vbo.vertexData(ver);
vbo.draw(GL_POINTS);
}
}

Expand Down
33 changes: 15 additions & 18 deletions src/scene/Octree.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,22 @@
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/

#include "common.h"

// system headers
#include <math.h>

// implementation header
#include "Octree.h"

// local headers
#include "Occluder.h"
// system headers
#include <math.h>

// common headers
#include "Extents.h"
#include "Intersect.h"

#include "StateDatabase.h"
#include "Vertex_Chunk.h"

// local headers
#include "Occluder.h"

static bool F2BSORT = true;//FIXME


Expand Down Expand Up @@ -831,7 +831,7 @@ void OctreeNode::draw()
GLfloat purple[4] = { 1.0f, 0.0f, 1.0f, 0.75f }; // purple
GLfloat *color = purple;
int x, y, z, c;
float points[5][3];
glm::vec3 points[5];
IntersectLevel frustumCull = Contained;
bool occludeCull = false;

Expand Down Expand Up @@ -875,13 +875,11 @@ void OctreeNode::draw()
points[c][1] = exts[y][1];
points[c][2] = exts[z][2];
}
memcpy(points[4], points[0], sizeof(points[4]));
glBegin(GL_LINE_STRIP);

for (int i = 0; i < 5; i++)
glVertex3fv(points[i]);
points[4] = points[0];

glEnd();
Vertex_Chunk vbo(Vertex_Chunk::V, 5);
vbo.vertexData(points);
vbo.draw(GL_LINE_STRIP);
}

// draw the corner edges
Expand All @@ -895,10 +893,9 @@ void OctreeNode::draw()
points[z][1] = exts[y][1];
points[z][2] = exts[z][2];
}
glBegin(GL_LINE_STRIP);
glVertex3fv(points[0]);
glVertex3fv(points[1]);
glEnd();
Vertex_Chunk vbo(Vertex_Chunk::V, 2);
vbo.vertexData(points);
vbo.draw(GL_LINE_STRIP);
}

// draw the kids
Expand Down

0 comments on commit e100f21

Please sign in to comment.