- moved map render logic into a shared base class

This commit is contained in:
Mark Vejvoda 2010-09-14 06:02:35 +00:00
parent 813076f64b
commit b95e2247cd
8 changed files with 431 additions and 188 deletions

View File

@ -30,6 +30,7 @@
#include "model_renderer.h"
#include "model.h"
#include "graphics_interface.h"
#include "base_renderer.h"
#ifdef DEBUG_RENDERING_ENABLED
# define IF_DEBUG_EDITION(x) x
@ -130,7 +131,7 @@ public:
};
class Renderer : public RendererInterface {
class Renderer : public RendererInterface, public BaseRenderer {
public:
//progress bar
static const int maxProgressBar;

View File

@ -1099,7 +1099,8 @@ void MenuStateCustomGame::render() {
int mouse2dAnim = mainMenu->getMouse2dAnim();
renderer.renderMouse2d(mouseX, mouseY, mouse2dAnim);
renderMap(&mapPreview, 0, 0, (listBoxFogOfWar.getSelectedItemIndex() == 1), 10, 350);
bool renderAll = (listBoxFogOfWar.getSelectedItemIndex() == 1);
renderer.renderMapPreview(&mapPreview, 0, 0, renderAll, 10, 350);
}
}
catch(const std::exception &ex) {
@ -1109,184 +1110,6 @@ void MenuStateCustomGame::render() {
}
}
void MenuStateCustomGame::renderMap(const MapPreview *map, int x, int y,
bool renderAll, int screenX, int screenY) {
float alt=0;
float showWater=0;
int renderMapHeight=128;
int renderMapWidth=128;
float clientW=256;
float clientH=256;
float cellSize=2;
float playerCrossSize=2;
// stretch small maps to 128x128
if(map->getW()<map->getH()){
cellSize=cellSize*renderMapHeight/map->getH();
}
else {
cellSize=cellSize*renderMapWidth/map->getW();
}
assertGl();
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, clientW, 0, clientH, 1, -1);
glViewport(screenX, screenY, renderMapWidth,renderMapHeight);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glPushAttrib(GL_CURRENT_BIT);
glTranslatef(static_cast<float>(x), static_cast<float>(y), 0.0f);
glLineWidth(1);
//glClear(GL_COLOR_BUFFER_BIT);
glColor3f(0, 0, 0);
for (int j = 0; j < map->getH(); j++) {
for (int i = 0; i < map->getW(); i++) {
//surface
alt = map->getHeight(i, j) / 20.f;
showWater = map->getWaterLevel()/ 20.f - alt;
showWater = (showWater > 0)? showWater:0;
Vec3f surfColor;
switch (map->getSurface(i, j)) {
case 1: surfColor = Vec3f(0.0, 0.8f * alt, 0.f + showWater); break;
case 2: surfColor = Vec3f(0.4f * alt, 0.6f * alt, 0.f + showWater); break;
case 3: surfColor = Vec3f(0.6f * alt, 0.3f * alt, 0.f + showWater); break;
case 4: surfColor = Vec3f(0.7f * alt, 0.7f * alt, 0.7f * alt + showWater); break;
case 5: surfColor = Vec3f(0.7f * alt, 0.5f * alt, 0.3f * alt + showWater); break;
}
glColor3fv(surfColor.ptr());
glBegin(GL_TRIANGLE_STRIP);
glVertex2f(i * cellSize, clientH - j * cellSize - cellSize);
glVertex2f(i * cellSize, clientH - j * cellSize);
glVertex2f(i * cellSize + cellSize, clientH - j * cellSize - cellSize);
glVertex2f(i * cellSize + cellSize, clientH - j * cellSize);
glEnd();
//objects
switch (map->getObject(i, j)) {
case 0: glColor3f(0.f, 0.f, 0.f); break;
case 1: glColor3f(1.f, 0.f, 0.f); break;
case 2: glColor3f(1.f, 1.f, 1.f); break;
case 3: glColor3f(0.5f, 0.5f, 1.f); break;
case 4: glColor3f(0.f, 0.f, 1.f); break;
case 5: glColor3f(0.5f, 0.5f, 0.5f); break;
case 6: glColor3f(1.f, 0.8f, 0.5f); break;
case 7: glColor3f(0.f, 1.f, 1.f); break;
case 8: glColor3f(0.7f, 0.1f, 0.3f); break;
case 9: glColor3f(0.5f, 1.f, 0.1f); break;
case 10: glColor3f(1.f, 0.2f, 0.8f); break;// we don't render unvisible blocking objects
}
if ( renderAll && (map->getObject(i, j) != 0) && (map->getObject(i, j) != 10) ){
glPointSize(cellSize / 2.f);
glBegin(GL_POINTS);
glVertex2i(i * cellSize + cellSize / 2, clientH - j * cellSize - cellSize / 2);
glEnd();
}
// bool found = false;
//height lines
// if (!found) {
glColor3fv((surfColor*0.5f).ptr());
//left
if (i > 0 && map->getHeight(i - 1, j) > map->getHeight(i, j)) {
glBegin(GL_LINES);
glVertex2f(i * cellSize, clientH - (j + 1) * cellSize);
glVertex2f(i * cellSize, clientH - j * cellSize);
glEnd();
}
//down
if (j > 0 && map->getHeight(i, j - 1) > map->getHeight(i, j)) {
glBegin(GL_LINES);
glVertex2f(i * cellSize, clientH - j * cellSize);
glVertex2f((i + 1) * cellSize, clientH - j * cellSize);
glEnd();
}
glColor3fv((surfColor*2.f).ptr());
//left
if (i > 0 && map->getHeight(i - 1, j) < map->getHeight(i, j)) {
glBegin(GL_LINES);
glVertex2f(i * cellSize, clientH - (j + 1) * cellSize);
glVertex2f(i * cellSize, clientH - j * cellSize);
glEnd();
}
if (j > 0 && map->getHeight(i, j - 1) < map->getHeight(i, j)) {
glBegin(GL_LINES);
glVertex2f(i * cellSize, clientH - j * cellSize);
glVertex2f((i + 1) * cellSize, clientH - j * cellSize);
glEnd();
}
// }
//resources
switch (map->getResource(i, j)) {
case 1: glColor3f(1.f, 1.f, 0.f); break;
case 2: glColor3f(0.5f, 0.5f, 0.5f); break;
case 3: glColor3f(1.f, 0.f, 0.f); break;
case 4: glColor3f(0.f, 0.f, 1.f); break;
case 5: glColor3f(0.5f, 0.5f, 1.f); break;
}
if (renderAll && map->getResource(i, j) != 0) {
glBegin(GL_LINES);
glVertex2f(i * cellSize, clientH - j * cellSize - cellSize);
glVertex2f(i * cellSize + cellSize, clientH - j * cellSize);
glVertex2f(i * cellSize, clientH - j * cellSize);
glVertex2f(i * cellSize + cellSize, clientH - j * cellSize - cellSize);
glEnd();
}
}
}
//start locations
glLineWidth(3);
// force playerCrossSize to be at least of size 4
if(cellSize<4)
playerCrossSize=4;
else
playerCrossSize=cellSize;
for (int i = 0; i < map->getMaxFactions(); i++) {
switch (i) {
case 0: glColor3f(1.f, 0.f, 0.f); break;
case 1: glColor3f(0.f, 0.f, 1.f); break;
case 2: glColor3f(0.f, 1.f, 0.f); break;
case 3: glColor3f(1.f, 1.f, 0.f); break;
case 4: glColor3f(1.f, 1.f, 1.f); break;
case 5: glColor3f(0.f, 1.f, 0.8f); break;
case 6: glColor3f(1.f, 0.5f, 0.f); break;
case 7: glColor3f(1.f, 0.5f, 1.f); break;
}
glBegin(GL_LINES);
glVertex2f((map->getStartLocationX(i) - 1) * cellSize, clientH - (map->getStartLocationY(i) - 1) * cellSize);
glVertex2f((map->getStartLocationX(i) + 1) * cellSize + playerCrossSize, clientH - (map->getStartLocationY(i) + 1) * cellSize - playerCrossSize);
glVertex2f((map->getStartLocationX(i) - 1) * cellSize, clientH - (map->getStartLocationY(i) + 1) * cellSize - playerCrossSize);
glVertex2f((map->getStartLocationX(i) + 1) * cellSize + playerCrossSize, clientH - (map->getStartLocationY(i) - 1) * cellSize);
glEnd();
}
glPopMatrix();
glPopAttrib();
assertGl();
}
void MenuStateCustomGame::update() {
Chrono chrono;
chrono.start();

View File

@ -171,8 +171,6 @@ private:
void cleanupFactionTexture();
void loadFactionTexture(string filepath);
void renderMap( const MapPreview *map, int x, int y,bool renderAll, int screenX, int screenY);
};
}}//end namespace

View File

@ -148,7 +148,7 @@ Program::Program(int w, int h) {
ofsetX = 0;
ofsetY = 0;
map = new MapPreview();
renderer.init(w, h);
renderer.initMapSurface(w, h);
}
Program::~Program() {

View File

@ -14,12 +14,14 @@
//#include "map.h"
#include "map_preview.h"
#include "renderer.h"
//#include "renderer.h"
#include "base_renderer.h"
#include <stack>
using std::stack;
using namespace Shared::Map;
using namespace Shared::Graphics;
namespace MapEditor {
@ -90,7 +92,8 @@ public:
class Program {
private:
Renderer renderer;
//Renderer renderer;
BaseRenderer renderer;
int ofsetX, ofsetY;
int cellSize;
//static Map *map;

View File

@ -0,0 +1,36 @@
// ==============================================================
// This file is part of Glest (www.glest.org)
//
// Copyright (C) 2001-2010 Mark Vejvoda
//
// You can redistribute this code and/or modify it under
// the terms of the GNU General Public License as published
// by the Free Software Foundation; either version 2 of the
// License, or (at your option) any later version
// ==============================================================
#ifndef _BASE_RENDERER_H_
#define _BASE_RENDERER_H_
#include "graphics_interface.h"
#include "leak_dumper.h"
namespace Shared { namespace Graphics {
// ===============================================
// class BaseRenderer
// ===============================================
class BaseRenderer : public RendererMapInterface {
public:
BaseRenderer() { }
~BaseRenderer() { }
virtual void initMapSurface(int clientW, int clientH);
virtual void renderMap(MapPreview *map, int x, int y, int clientW, int clientH, int cellSize);
virtual void renderMapPreview(const MapPreview *map, int x, int y,bool renderAll, int screenX, int screenY);
};
}} // end namespace
#endif

View File

@ -12,16 +12,19 @@
#ifndef _SHARED_GRAPHICS_GRAPHICSINTERFACE_H_
#define _SHARED_GRAPHICS_GRAPHICSINTERFACE_H_
#include "map_preview.h"
#include "leak_dumper.h"
namespace Shared{ namespace Graphics{
using namespace Shared::Map;
namespace Shared { namespace Graphics {
class GraphicsFactory;
class Context;
class Texture2D;
class Model;
enum ResourceScope{
enum ResourceScope {
rsGlobal,
rsMenu,
rsGame,
@ -35,13 +38,20 @@ public:
virtual Model *newModel(ResourceScope rs) = 0;
};
class RendererMapInterface {
public:
virtual void initMapSurface(int clientW, int clientH) = 0;
virtual void renderMap(MapPreview *map, int x, int y, int clientW, int clientH, int cellSize) = 0;
virtual void renderMapPreview(const MapPreview *map, int x, int y,bool renderAll, int screenX, int screenY) = 0;
};
// =====================================================
// class GraphicsInterface
//
/// Interface for the graphic engine
// =====================================================
class GraphicsInterface{
class GraphicsInterface {
private:
GraphicsFactory *graphicsFactory;
Context *currentContext;

View File

@ -0,0 +1,372 @@
// ==============================================================
// This file is part of Glest (www.glest.org)
//
// Copyright (C) 2001-2010 Mark Vejvoda
//
// You can redistribute this code and/or modify it under
// the terms of the GNU General Public License as published
// by the Free Software Foundation; either version 2 of the
// License, or (at your option) any later version
// ==============================================================
#include "base_renderer.h"
#include <cassert>
#include "opengl.h"
#include "vec.h"
using namespace Shared::Graphics;
using namespace Shared::Graphics::Gl;
namespace Shared { namespace Graphics {
// ===============================================
// class Renderer
// ===============================================
void BaseRenderer::initMapSurface(int clientW, int clientH) {
assertGl();
glFrontFace(GL_CW);
glEnable(GL_CULL_FACE);
glPolygonMode(GL_FRONT, GL_FILL);
glClearColor(0.5, 0.5, 0.5, 1.0);
assertGl();
}
void BaseRenderer::renderMap(MapPreview *map, int x, int y,
int clientW, int clientH, int cellSize) {
float alt=0;
float showWater=0;
assertGl();
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, clientW, 0, clientH, 1, -1);
glViewport(0, 0, clientW, clientH);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glPushAttrib(GL_CURRENT_BIT);
glTranslatef(static_cast<float>(x), static_cast<float>(y), 0.0f);
glLineWidth(1);
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(0, 0, 0);
for (int j = 0; j < map->getH(); j++) {
for (int i = 0; i < map->getW(); i++) {
if (i * cellSize + x > -cellSize
&& i * cellSize + x < clientW
&& clientH - cellSize - j * cellSize + y > -cellSize
&& clientH - cellSize - j * cellSize + y < clientH) {
//surface
alt = map->getHeight(i, j) / 20.f;
showWater = map->getWaterLevel()/ 20.f - alt;
showWater = (showWater > 0)? showWater:0;
Vec3f surfColor;
switch (map->getSurface(i, j)) {
case st_Grass: surfColor = Vec3f(0.0, 0.8f * alt, 0.f + showWater); break;
case st_Secondary_Grass: surfColor = Vec3f(0.4f * alt, 0.6f * alt, 0.f + showWater); break;
case st_Road: surfColor = Vec3f(0.6f * alt, 0.3f * alt, 0.f + showWater); break;
case st_Stone: surfColor = Vec3f(0.7f * alt, 0.7f * alt, 0.7f * alt + showWater); break;
case st_Ground: surfColor = Vec3f(0.7f * alt, 0.5f * alt, 0.3f * alt + showWater); break;
}
glColor3fv(surfColor.ptr());
glBegin(GL_TRIANGLE_STRIP);
glVertex2i(i * cellSize, clientH - j * cellSize - cellSize);
glVertex2i(i * cellSize, clientH - j * cellSize);
glVertex2i(i * cellSize + cellSize, clientH - j * cellSize - cellSize);
glVertex2i(i * cellSize + cellSize, clientH - j * cellSize);
glEnd();
//objects
switch (map->getObject(i, j)) {
case 0: glColor3f(0.f, 0.f, 0.f); break;
case 1: glColor3f(1.f, 0.f, 0.f); break;
case 2: glColor3f(1.f, 1.f, 1.f); break;
case 3: glColor3f(0.5f, 0.5f, 1.f); break;
case 4: glColor3f(0.f, 0.f, 1.f); break;
case 5: glColor3f(0.5f, 0.5f, 0.5f); break;
case 6: glColor3f(1.f, 0.8f, 0.5f); break;
case 7: glColor3f(0.f, 1.f, 1.f); break;
case 8: glColor3f(0.7f, 0.1f, 0.3f); break;
case 9: glColor3f(0.5f, 1.f, 0.1f); break;
case 10: glColor3f(1.f, 0.2f, 0.8f); break;
}
if (map->getObject(i, j) != 0) {
glPointSize(cellSize / 2.f);
glBegin(GL_POINTS);
glVertex2i(i * cellSize + cellSize / 2, clientH - j * cellSize - cellSize / 2);
glEnd();
}
// bool found = false;
//height lines
// if (!found) {
glColor3fv((surfColor*0.5f).ptr());
//left
if (i > 0 && map->getHeight(i - 1, j) > map->getHeight(i, j)) {
glBegin(GL_LINES);
glVertex2i(i * cellSize, clientH - (j + 1) * cellSize);
glVertex2i(i * cellSize, clientH - j * cellSize);
glEnd();
}
//down
if (j > 0 && map->getHeight(i, j - 1) > map->getHeight(i, j)) {
glBegin(GL_LINES);
glVertex2i(i * cellSize, clientH - j * cellSize);
glVertex2i((i + 1) * cellSize, clientH - j * cellSize);
glEnd();
}
glColor3fv((surfColor*2.f).ptr());
//left
if (i > 0 && map->getHeight(i - 1, j) < map->getHeight(i, j)) {
glBegin(GL_LINES);
glVertex2i(i * cellSize, clientH - (j + 1) * cellSize);
glVertex2i(i * cellSize, clientH - j * cellSize);
glEnd();
}
if (j > 0 && map->getHeight(i, j - 1) < map->getHeight(i, j)) {
glBegin(GL_LINES);
glVertex2i(i * cellSize, clientH - j * cellSize);
glVertex2i((i + 1) * cellSize, clientH - j * cellSize);
glEnd();
}
// }
//resources
switch (map->getResource(i, j)) {
case 1: glColor3f(1.f, 1.f, 0.f); break;
case 2: glColor3f(0.5f, 0.5f, 0.5f); break;
case 3: glColor3f(1.f, 0.f, 0.f); break;
case 4: glColor3f(0.f, 0.f, 1.f); break;
case 5: glColor3f(0.5f, 0.5f, 1.f); break;
}
if (map->getResource(i, j) != 0) {
glBegin(GL_LINES);
glVertex2i(i * cellSize, clientH - j * cellSize - cellSize);
glVertex2i(i * cellSize + cellSize, clientH - j * cellSize);
glVertex2i(i * cellSize, clientH - j * cellSize);
glVertex2i(i * cellSize + cellSize, clientH - j * cellSize - cellSize);
glEnd();
}
}
}
}
//start locations
glLineWidth(3);
for (int i = 0; i < map->getMaxFactions(); i++) {
switch (i) {
case 0: glColor3f(1.f, 0.f, 0.f); break;
case 1: glColor3f(0.f, 0.f, 1.f); break;
case 2: glColor3f(0.f, 1.f, 0.f); break;
case 3: glColor3f(1.f, 1.f, 0.f); break;
case 4: glColor3f(1.f, 1.f, 1.f); break;
case 5: glColor3f(0.f, 1.f, 0.8f); break;
case 6: glColor3f(1.f, 0.5f, 0.f); break;
case 7: glColor3f(1.f, 0.5f, 1.f); break;
}
glBegin(GL_LINES);
glVertex2i((map->getStartLocationX(i) - 1) * cellSize, clientH - (map->getStartLocationY(i) - 1) * cellSize);
glVertex2i((map->getStartLocationX(i) + 1) * cellSize + cellSize, clientH - (map->getStartLocationY(i) + 1) * cellSize - cellSize);
glVertex2i((map->getStartLocationX(i) - 1) * cellSize, clientH - (map->getStartLocationY(i) + 1) * cellSize - cellSize);
glVertex2i((map->getStartLocationX(i) + 1) * cellSize + cellSize, clientH - (map->getStartLocationY(i) - 1) * cellSize);
glEnd();
}
glPopMatrix();
glPopAttrib();
assertGl();
}
void BaseRenderer::renderMapPreview( const MapPreview *map, int x, int y,
bool renderAll, int screenX, int screenY) {
float alt=0;
float showWater=0;
int renderMapHeight=128;
int renderMapWidth=128;
float clientW=256;
float clientH=256;
float cellSize=2;
float playerCrossSize=2;
// stretch small maps to 128x128
if(map->getW() < map->getH()) {
cellSize = cellSize * renderMapHeight / map->getH();
}
else {
cellSize = cellSize * renderMapWidth / map->getW();
}
assertGl();
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, clientW, 0, clientH, 1, -1);
glViewport(screenX, screenY, renderMapWidth,renderMapHeight);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glPushAttrib(GL_CURRENT_BIT);
glTranslatef(static_cast<float>(x), static_cast<float>(y), 0.0f);
glLineWidth(1);
//glClear(GL_COLOR_BUFFER_BIT);
glColor3f(0, 0, 0);
for (int j = 0; j < map->getH(); j++) {
for (int i = 0; i < map->getW(); i++) {
//surface
alt = map->getHeight(i, j) / 20.f;
showWater = map->getWaterLevel()/ 20.f - alt;
showWater = (showWater > 0)? showWater:0;
Vec3f surfColor;
switch (map->getSurface(i, j)) {
case st_Grass: surfColor = Vec3f(0.0, 0.8f * alt, 0.f + showWater); break;
case st_Secondary_Grass: surfColor = Vec3f(0.4f * alt, 0.6f * alt, 0.f + showWater); break;
case st_Road: surfColor = Vec3f(0.6f * alt, 0.3f * alt, 0.f + showWater); break;
case st_Stone: surfColor = Vec3f(0.7f * alt, 0.7f * alt, 0.7f * alt + showWater); break;
case st_Ground: surfColor = Vec3f(0.7f * alt, 0.5f * alt, 0.3f * alt + showWater); break;
}
glColor3fv(surfColor.ptr());
glBegin(GL_TRIANGLE_STRIP);
glVertex2f(i * cellSize, clientH - j * cellSize - cellSize);
glVertex2f(i * cellSize, clientH - j * cellSize);
glVertex2f(i * cellSize + cellSize, clientH - j * cellSize - cellSize);
glVertex2f(i * cellSize + cellSize, clientH - j * cellSize);
glEnd();
//objects
switch (map->getObject(i, j)) {
case 0: glColor3f(0.f, 0.f, 0.f); break;
case 1: glColor3f(1.f, 0.f, 0.f); break;
case 2: glColor3f(1.f, 1.f, 1.f); break;
case 3: glColor3f(0.5f, 0.5f, 1.f); break;
case 4: glColor3f(0.f, 0.f, 1.f); break;
case 5: glColor3f(0.5f, 0.5f, 0.5f); break;
case 6: glColor3f(1.f, 0.8f, 0.5f); break;
case 7: glColor3f(0.f, 1.f, 1.f); break;
case 8: glColor3f(0.7f, 0.1f, 0.3f); break;
case 9: glColor3f(0.5f, 1.f, 0.1f); break;
case 10: glColor3f(1.f, 0.2f, 0.8f); break;// we don't render unvisible blocking objects
}
if ( renderAll && (map->getObject(i, j) != 0) && (map->getObject(i, j) != 10) ){
glPointSize(cellSize / 2.f);
glBegin(GL_POINTS);
glVertex2i(i * cellSize + cellSize / 2, clientH - j * cellSize - cellSize / 2);
glEnd();
}
// bool found = false;
//height lines
// if (!found) {
glColor3fv((surfColor*0.5f).ptr());
//left
if (i > 0 && map->getHeight(i - 1, j) > map->getHeight(i, j)) {
glBegin(GL_LINES);
glVertex2f(i * cellSize, clientH - (j + 1) * cellSize);
glVertex2f(i * cellSize, clientH - j * cellSize);
glEnd();
}
//down
if (j > 0 && map->getHeight(i, j - 1) > map->getHeight(i, j)) {
glBegin(GL_LINES);
glVertex2f(i * cellSize, clientH - j * cellSize);
glVertex2f((i + 1) * cellSize, clientH - j * cellSize);
glEnd();
}
glColor3fv((surfColor*2.f).ptr());
//left
if (i > 0 && map->getHeight(i - 1, j) < map->getHeight(i, j)) {
glBegin(GL_LINES);
glVertex2f(i * cellSize, clientH - (j + 1) * cellSize);
glVertex2f(i * cellSize, clientH - j * cellSize);
glEnd();
}
if (j > 0 && map->getHeight(i, j - 1) < map->getHeight(i, j)) {
glBegin(GL_LINES);
glVertex2f(i * cellSize, clientH - j * cellSize);
glVertex2f((i + 1) * cellSize, clientH - j * cellSize);
glEnd();
}
// }
//resources
switch (map->getResource(i, j)) {
case 1: glColor3f(1.f, 1.f, 0.f); break;
case 2: glColor3f(0.5f, 0.5f, 0.5f); break;
case 3: glColor3f(1.f, 0.f, 0.f); break;
case 4: glColor3f(0.f, 0.f, 1.f); break;
case 5: glColor3f(0.5f, 0.5f, 1.f); break;
}
if (renderAll && map->getResource(i, j) != 0) {
glBegin(GL_LINES);
glVertex2f(i * cellSize, clientH - j * cellSize - cellSize);
glVertex2f(i * cellSize + cellSize, clientH - j * cellSize);
glVertex2f(i * cellSize, clientH - j * cellSize);
glVertex2f(i * cellSize + cellSize, clientH - j * cellSize - cellSize);
glEnd();
}
}
}
//start locations
glLineWidth(3);
// force playerCrossSize to be at least of size 4
if(cellSize<4)
playerCrossSize=4;
else
playerCrossSize=cellSize;
for (int i = 0; i < map->getMaxFactions(); i++) {
switch (i) {
case 0: glColor3f(1.f, 0.f, 0.f); break;
case 1: glColor3f(0.f, 0.f, 1.f); break;
case 2: glColor3f(0.f, 1.f, 0.f); break;
case 3: glColor3f(1.f, 1.f, 0.f); break;
case 4: glColor3f(1.f, 1.f, 1.f); break;
case 5: glColor3f(0.f, 1.f, 0.8f); break;
case 6: glColor3f(1.f, 0.5f, 0.f); break;
case 7: glColor3f(1.f, 0.5f, 1.f); break;
}
glBegin(GL_LINES);
glVertex2f((map->getStartLocationX(i) - 1) * cellSize, clientH - (map->getStartLocationY(i) - 1) * cellSize);
glVertex2f((map->getStartLocationX(i) + 1) * cellSize + playerCrossSize, clientH - (map->getStartLocationY(i) + 1) * cellSize - playerCrossSize);
glVertex2f((map->getStartLocationX(i) - 1) * cellSize, clientH - (map->getStartLocationY(i) + 1) * cellSize - playerCrossSize);
glVertex2f((map->getStartLocationX(i) + 1) * cellSize + playerCrossSize, clientH - (map->getStartLocationY(i) - 1) * cellSize);
glEnd();
}
glPopMatrix();
glPopAttrib();
assertGl();
}
}} // end namespace