XtreemNodes/include/NodeRenderer.h

146 lines
4.2 KiB
C
Raw Normal View History

2022-10-22 17:03:43 +02:00
#ifndef NODERENDERER_H
#define NODERENDERER_H
#include "Base.h"
#include "MapBlock.h"
#include <GL/glut.h>
class NodeRenderer
{
public:
NodeRenderer()
{
}
virtual ~NodeRenderer()
{
}
int renderNode(int x, int y, int z)
2022-10-22 17:03:43 +02:00
{
//Position2D block = BlockUtilities::getBlockFromNodeCoordinates(x, z); // The block the node at (x, y, z) is in
2022-10-30 16:53:41 +01:00
glColor3f(1.0F, 1.0F, 1.0F);
2022-10-22 17:03:43 +02:00
glBegin(GL_QUADS);
// Front
if(blockManager.getNodeAt(x, y, z - 1))
2022-10-22 17:03:43 +02:00
{
2022-10-23 23:44:58 +02:00
glTexCoord2f(.0F, .0F);
2022-10-22 17:03:43 +02:00
glVertex3f(x + .0F, y + 1.0F, z + .0F);
2022-10-23 23:44:58 +02:00
glTexCoord2f(1.0F, .0F);
2022-10-22 17:03:43 +02:00
glVertex3f(x + 1.0F, y + 1.0F, z + .0F);
glColor3f(.6F, .6F, .6F); // Bottom vertices
2022-10-23 23:44:58 +02:00
glTexCoord2f(1.0F, 1.0F);
2022-10-22 17:03:43 +02:00
glVertex3f(x + 1.0F, y + .0F, z + .0F);
2022-10-23 23:44:58 +02:00
glTexCoord2f(.0F, 1.0F);
2022-10-22 17:03:43 +02:00
glVertex3f(x + .0F, y + .0F, z + .0F);
glColor3f(1.0F, 1.0F, 1.0F);
2022-10-22 17:03:43 +02:00
}
2022-10-30 16:53:41 +01:00
2022-10-22 17:03:43 +02:00
// Back
if(blockManager.getNodeAt(x, y, z + 1))
2022-10-22 17:03:43 +02:00
{
2022-10-23 23:44:58 +02:00
glTexCoord2f(.0F, .0F);
2022-10-22 17:03:43 +02:00
glVertex3f(x + .0F, y + 1.0F, z + 1.0F);
2022-10-23 23:44:58 +02:00
glTexCoord2f(1.0F, .0F);
2022-10-22 17:03:43 +02:00
glVertex3f(x + 1.0F, y + 1.0F, z + 1.0F);
glColor3f(.6F, .6F, .6F);
2022-10-23 23:44:58 +02:00
glTexCoord2f(1.0F, 1.0F);
2022-10-22 17:03:43 +02:00
glVertex3f(x + 1.0F, y + .0F, z + 1.0F);
2022-10-23 23:44:58 +02:00
glTexCoord2f(.0F, 1.0F);
2022-10-22 17:03:43 +02:00
glVertex3f(x + .0F, y + .0F, z + 1.0F);
glColor3f(1.0F, 1.0F, 1.0F);
2022-10-22 17:03:43 +02:00
}
// Right
if(blockManager.getNodeAt(x + 1, y, z));
2022-10-22 17:03:43 +02:00
{
2022-10-23 23:44:58 +02:00
glTexCoord2f(1.0F, .0F);
2022-10-22 17:03:43 +02:00
glVertex3f(x + 1.0F, y + 1.0F, z + .0F);
glColor3f(.6F, .6F, .6F);
2022-10-23 23:44:58 +02:00
glTexCoord2f(1.0F, 1.0F);
2022-10-22 17:03:43 +02:00
glVertex3f(x + 1.0F, y + .0F, z + .0F);
2022-10-23 23:44:58 +02:00
glTexCoord2f(.0F, 1.0F);
2022-10-22 17:03:43 +02:00
glVertex3f(x + 1.0F, y + .0F, z + 1.0F);
glColor3f(1.0F, 1.0F, 1.0F);
2022-10-22 17:03:43 +02:00
2022-10-23 23:44:58 +02:00
glTexCoord2f(.0F, .0F);
2022-10-22 17:03:43 +02:00
glVertex3f(x + 1.0F, y + 1.0F, z + 1.0F);
}
2022-10-22 17:03:43 +02:00
// Left
if(blockManager.getNodeAt(x - 1, y, z));
2022-10-22 17:03:43 +02:00
{
2022-10-23 23:44:58 +02:00
glTexCoord2f(1.0F, .0F);
2022-10-22 17:03:43 +02:00
glVertex3f(x + .0F, y + 1.0F, z + .0F);
glColor3f(.6F, .6F, .6F);
2022-10-23 23:44:58 +02:00
glTexCoord2f(1.0F, 1.0F);
2022-10-22 17:03:43 +02:00
glVertex3f(x + .0F, y + .0F, z + .0F);
2022-10-23 23:44:58 +02:00
glTexCoord2f(.0F, 1.0F);
2022-10-22 17:03:43 +02:00
glVertex3f(x + .0F, y + .0F, z + 1.0F);
glColor3f(1.0F, 1.0F, 1.0F);
2022-10-22 17:03:43 +02:00
2022-10-23 23:44:58 +02:00
glTexCoord2f(.0F, .0F);
2022-10-22 17:03:43 +02:00
glVertex3f(x + .0F, y + 1.0F, z + 1.0F);
}
// Bottom
if(blockManager.getNodeAt(x, y - 1, z));
2022-10-22 17:03:43 +02:00
{
2022-10-23 23:44:58 +02:00
glTexCoord2f(.0F, .0F);
2022-10-22 17:03:43 +02:00
glVertex3f(x + 1.0F, y + .0F, z + .0F);
2022-10-23 23:44:58 +02:00
glTexCoord2f(1.0F, .0F);
2022-10-22 17:03:43 +02:00
glVertex3f(x + .0F, y + .0F, z + .0F);
2022-10-23 23:44:58 +02:00
glTexCoord2f(1.0F, 1.0F);
2022-10-22 17:03:43 +02:00
glVertex3f(x + .0F, y + .0F, z + 1.0F);
2022-10-23 23:44:58 +02:00
glTexCoord2f(.0F, 1.0F);
2022-10-22 17:03:43 +02:00
glVertex3f(x + 1.0F, y + .0F, z + 1.0F);
}
// Top
if(blockManager.getNodeAt(x, y + 1, z));
2022-10-22 17:03:43 +02:00
{
2022-10-23 23:44:58 +02:00
glTexCoord2f(.0F, .0F);
2022-10-22 17:03:43 +02:00
glVertex3f(x + 1.0F, y + 1.0F, z + .0F);
2022-10-23 23:44:58 +02:00
glTexCoord2f(1.0F, .0F);
2022-10-22 17:03:43 +02:00
glVertex3f(x + .0F, y + 1.0F, z + .0F);
2022-10-23 23:44:58 +02:00
glTexCoord2f(1.0F, 1.0F);
2022-10-22 17:03:43 +02:00
glVertex3f(x + .0F, y + 1.0F, z + 1.0F);
2022-10-23 23:44:58 +02:00
glTexCoord2f(.0F, 1.0F);
2022-10-22 17:03:43 +02:00
glVertex3f(x + 1.0F, y + 1.0F, z + 1.0F);
}
glEnd();
return 1;
2022-10-22 17:03:43 +02:00
}
protected:
private:
};
#endif