enabled depth_test for colorpicking

To do it many changes were needed, because mouse position on map was 
calculated using the depth buffer with current rendering state
This commit is contained in:
titiger 2015-01-04 14:38:32 +01:00
parent 4e0c96adae
commit ab02478096
6 changed files with 45 additions and 31 deletions

View File

@ -4122,8 +4122,7 @@ void Game::mouseDownLeft(int x, int y) {
if(setMarker) { if(setMarker) {
Vec2i targetPos; Vec2i targetPos;
Vec2i screenPos(x,y-60); Vec2i screenPos(x,y-60);
Renderer &renderer= Renderer::getInstance(); targetPos=getMouseCellPos();
renderer.computePosition(screenPos, targetPos);
//Vec2i surfaceCellPos = map->toSurfCoords(targetPos); //Vec2i surfaceCellPos = map->toSurfCoords(targetPos);
@ -4137,8 +4136,7 @@ void Game::mouseDownLeft(int x, int y) {
if(originalIsMarkCellEnabled == true && isMarkCellEnabled == true) { if(originalIsMarkCellEnabled == true && isMarkCellEnabled == true) {
Vec2i targetPos; Vec2i targetPos;
Vec2i screenPos(x,y-60); Vec2i screenPos(x,y-60);
Renderer &renderer= Renderer::getInstance(); targetPos=getMouseCellPos();
renderer.computePosition(screenPos, targetPos);
Vec2i surfaceCellPos = map->toSurfCoords(targetPos); Vec2i surfaceCellPos = map->toSurfCoords(targetPos);
MarkedCell mc(targetPos,world.getThisFaction(),"placeholder for note",world.getThisFaction()->getStartLocationIndex()); MarkedCell mc(targetPos,world.getThisFaction(),"placeholder for note",world.getThisFaction()->getStartLocationIndex());
@ -4152,14 +4150,13 @@ void Game::mouseDownLeft(int x, int y) {
chatManager.switchOnEdit(this,500); chatManager.switchOnEdit(this,500);
//renderer.updateMarkedCellScreenPosQuadCache(surfaceCellPos); //renderer.updateMarkedCellScreenPosQuadCache(surfaceCellPos);
renderer.forceQuadCacheUpdate(); Renderer::getInstance().forceQuadCacheUpdate();
} }
if(originalIsUnMarkCellEnabled == true && isUnMarkCellEnabled == true) { if(originalIsUnMarkCellEnabled == true && isUnMarkCellEnabled == true) {
Vec2i targetPos; Vec2i targetPos;
Vec2i screenPos(x,y-35); Vec2i screenPos(x,y-35);
Renderer &renderer= Renderer::getInstance(); targetPos=getMouseCellPos();
renderer.computePosition(screenPos, targetPos);
Vec2i surfaceCellPos = map->toSurfCoords(targetPos); Vec2i surfaceCellPos = map->toSurfCoords(targetPos);
// if(mapMarkedCellList.find(surfaceCellPos) != mapMarkedCellList.end()) { // if(mapMarkedCellList.find(surfaceCellPos) != mapMarkedCellList.end()) {
@ -4177,7 +4174,7 @@ void Game::mouseDownLeft(int x, int y) {
//Renderer &renderer= Renderer::getInstance(); //Renderer &renderer= Renderer::getInstance();
//renderer.updateMarkedCellScreenPosQuadCache(surfaceCellPos); //renderer.updateMarkedCellScreenPosQuadCache(surfaceCellPos);
renderer.forceQuadCacheUpdate(); Renderer::getInstance().forceQuadCacheUpdate();
} }
} }
} }
@ -4259,9 +4256,8 @@ void Game::mouseDownRight(int x, int y) {
else { else {
Vec2i targetPos; Vec2i targetPos;
Vec2i screenPos(x,y); Vec2i screenPos(x,y);
Renderer &renderer= Renderer::getInstance(); targetPos=getMouseCellPos();
renderer.computePosition(screenPos, targetPos); if(isValidMouseCellPos() == true &&
if(renderer.computePosition(screenPos, targetPos) == true &&
map->isInsideSurface(map->toSurfCoords(targetPos)) == true) { map->isInsideSurface(map->toSurfCoords(targetPos)) == true) {
gui.mouseDownRightGraphics(x, y,false); gui.mouseDownRightGraphics(x, y,false);
} }
@ -4521,7 +4517,7 @@ void Game::mouseMove(int x, int y, const MouseState *ms) {
lastMousePos.y = mouseY; lastMousePos.y = mouseY;
Renderer &renderer= Renderer::getInstance(); Renderer &renderer= Renderer::getInstance();
renderer.computePosition(Vec2i(mouseX, mouseY), mouseCellPos); renderer.ccomputePosition(Vec2i(mouseX, mouseY), mouseCellPos);
} }
catch(const exception &ex) { catch(const exception &ex) {
char szBuf[8096]=""; char szBuf[8096]="";
@ -4541,6 +4537,15 @@ void Game::mouseMove(int x, int y, const MouseState *ms) {
} }
} }
bool Game::isValidMouseCellPos() const{
if(world.getMap() == NULL){
return false;
}
else {
return world.getMap()->isInside(mouseCellPos);
}
}
void Game::eventMouseWheel(int x, int y, int zDelta) { void Game::eventMouseWheel(int x, int y, int zDelta) {
if(this->masterserverMode == true) { if(this->masterserverMode == true) {
return; return;

View File

@ -257,6 +257,9 @@ public:
Program *getProgram() {return program;} Program *getProgram() {return program;}
Vec2i getMouseCellPos() const {return mouseCellPos;}
bool isValidMouseCellPos() const;
void removeUnitFromSelection(const Unit *unit); void removeUnitFromSelection(const Unit *unit);
bool addUnitToSelection(Unit *unit); bool addUnitToSelection(Unit *unit);
void addUnitToGroupSelection(Unit *unit,int groupIndex); void addUnitToGroupSelection(Unit *unit,int groupIndex);

View File

@ -1648,11 +1648,11 @@ void Renderer::renderMouse2d(int x, int y, int anim, float fade) {
if(game->isMarkCellMode() == true) { if(game->isMarkCellMode() == true) {
const Texture2D *texture= game->getMarkCellTexture(); const Texture2D *texture= game->getMarkCellTexture();
renderTextureQuad(x-18,y-50,texture->getTextureWidth(),texture->getTextureHeight(),texture,0.8f); renderTextureQuad(x,y,texture->getTextureWidth(),texture->getTextureHeight(),texture,0.8f);
} }
if(game->isUnMarkCellMode() == true) { if(game->isUnMarkCellMode() == true) {
const Texture2D *texture= game->getUnMarkCellTexture(); const Texture2D *texture= game->getUnMarkCellTexture();
renderTextureQuad(x-18,y-50,texture->getTextureWidth(),texture->getTextureHeight(),texture,0.8f); renderTextureQuad(x,y,texture->getTextureWidth(),texture->getTextureHeight(),texture,0.8f);
} }
} }
@ -6274,7 +6274,7 @@ void Renderer::renderHighlightedCellsOnMinimap() {
//int mx= metrics.getMinimapX(); //int mx= metrics.getMinimapX();
int my= metrics.getMinimapY(); //int my= metrics.getMinimapY();
int mw= metrics.getMinimapW(); int mw= metrics.getMinimapW();
int mh= metrics.getMinimapH(); int mh= metrics.getMinimapH();
@ -6297,7 +6297,8 @@ void Renderer::renderHighlightedCellsOnMinimap() {
if(texture != NULL) { if(texture != NULL) {
//float alpha = 0.49f+0.5f/(mc->getAliveCount()%15); //float alpha = 0.49f+0.5f/(mc->getAliveCount()%15);
float alpha=1.0f; float alpha=1.0f;
renderTextureQuad((int)(pos.x*zoom.x)+pointersize, my + mh-(int)(pos.y*zoom.y), pointersize, pointersize, texture, alpha,&myColor); renderTextureQuad((int)(pos.x*zoom.x),(int)(pos.y*zoom.y), pointersize, pointersize, texture, alpha,&myColor);
//renderTextureQuad((int)(pos.x*zoom.x)+pointersize, my + mh-(int)(pos.y*zoom.y), pointersize, pointersize, texture, alpha,&myColor);
} }
} }
} }
@ -6394,7 +6395,7 @@ void Renderer::renderVisibleMarkedCells(bool renderTextHint,int x, int y) {
std::map<Vec2i, MarkedCell> markedCells = game->getMapMarkedCellList(); std::map<Vec2i, MarkedCell> markedCells = game->getMapMarkedCellList();
if(markedCells.empty() == false) { if(markedCells.empty() == false) {
const Texture2D *texture= game->getMarkCellTexture(); const Texture2D *texture= game->getMarkCellTexture();
const int yOffset = 10; const int yOffset = -40;
for(std::map<Vec2i, MarkedCell>::iterator iterMap =markedCells.begin(); for(std::map<Vec2i, MarkedCell>::iterator iterMap =markedCells.begin();
iterMap != markedCells.end(); ++iterMap) { iterMap != markedCells.end(); ++iterMap) {
@ -6885,7 +6886,7 @@ void Renderer::renderMenuBackground(Camera *camera, float fade, Model *mainModel
// ==================== computing ==================== // ==================== computing ====================
bool Renderer::computePosition(const Vec2i &screenPos, Vec2i &worldPos, bool exactCoords) { bool Renderer::ccomputePosition(const Vec2i &screenPos, Vec2i &worldPos, bool exactCoords) {
assertGl(); assertGl();
const Map* map= game->getWorld()->getMap(); const Map* map= game->getWorld()->getMap();
const Metrics &metrics= Metrics::getInstance(); const Metrics &metrics= Metrics::getInstance();

View File

@ -568,7 +568,7 @@ public:
void renderMenuBackground(Camera *camera, float fade, Model *mainModel, vector<Model *> characterModels,const Vec3f characterPosition, float anim); void renderMenuBackground(Camera *camera, float fade, Model *mainModel, vector<Model *> characterModels,const Vec3f characterPosition, float anim);
//computing //computing
bool computePosition(const Vec2i &screenPos, Vec2i &worldPos,bool exactCoords=false); bool ccomputePosition(const Vec2i &screenPos, Vec2i &worldPos,bool exactCoords=false);
void computeSelected(Selection::UnitContainer &units, const Object *&obj, const bool withObjectSelection, const Vec2i &posDown, const Vec2i &posUp); void computeSelected(Selection::UnitContainer &units, const Object *&obj, const bool withObjectSelection, const Vec2i &posDown, const Vec2i &posUp);
void selectUsingColorPicking(Selection::UnitContainer &units, const Object *&obj,const bool withObjectSelection,const Vec2i &posDown, const Vec2i &posUp); void selectUsingColorPicking(Selection::UnitContainer &units, const Object *&obj,const bool withObjectSelection,const Vec2i &posDown, const Vec2i &posUp);
void selectUsingSelectionBuffer(Selection::UnitContainer &units,const Object *&obj, const bool withObjectSelection,const Vec2i &posDown, const Vec2i &posUp); void selectUsingSelectionBuffer(Selection::UnitContainer &units,const Object *&obj, const bool withObjectSelection,const Vec2i &posDown, const Vec2i &posUp);

View File

@ -256,8 +256,8 @@ void Gui::mouseMoveOutsideDisplay() {
void Gui::mouseDownLeftGraphics(int x, int y, bool prepared) { void Gui::mouseDownLeftGraphics(int x, int y, bool prepared) {
if(selectingPos) { if(selectingPos) {
//give standard orders //give standard orders
Vec2i targetPos; Vec2i targetPos=game->getMouseCellPos();
if(Renderer::getInstance().computePosition(Vec2i(x, y), targetPos) && if(game->isValidMouseCellPos() &&
world->getMap()->isInsideSurface(world->getMap()->toSurfCoords(targetPos)) == true) { world->getMap()->isInsideSurface(world->getMap()->toSurfCoords(targetPos)) == true) {
giveTwoClickOrders(x, y, prepared); giveTwoClickOrders(x, y, prepared);
} }
@ -266,8 +266,8 @@ void Gui::mouseDownLeftGraphics(int x, int y, bool prepared) {
//set meeting point //set meeting point
else if(selectingMeetingPoint) { else if(selectingMeetingPoint) {
if(selection.isCommandable()) { if(selection.isCommandable()) {
Vec2i targetPos; Vec2i targetPos=game->getMouseCellPos();
if(Renderer::getInstance().computePosition(Vec2i(x, y), targetPos) && if(game->isValidMouseCellPos() &&
world->getMap()->isInsideSurface(world->getMap()->toSurfCoords(targetPos)) == true) { world->getMap()->isInsideSurface(world->getMap()->toSurfCoords(targetPos)) == true) {
commander->trySetMeetingPoint(selection.getFrontUnit(), targetPos); commander->trySetMeetingPoint(selection.getFrontUnit(), targetPos);
} }
@ -287,15 +287,15 @@ void Gui::mouseDownRightGraphics(int x, int y , bool prepared) {
} }
else if(selection.isCommandable()) { else if(selection.isCommandable()) {
if(prepared) { if(prepared) {
Vec2i targetPos; Vec2i targetPos=game->getMouseCellPos();
if(Renderer::getInstance().computePosition(Vec2i(x, y), targetPos) && if(game->isValidMouseCellPos() &&
world->getMap()->isInsideSurface(world->getMap()->toSurfCoords(targetPos)) == true) { world->getMap()->isInsideSurface(world->getMap()->toSurfCoords(targetPos)) == true) {
givePreparedDefaultOrders(x, y); givePreparedDefaultOrders(x, y);
} }
} }
else { else {
Vec2i targetPos; Vec2i targetPos=game->getMouseCellPos();
if(Renderer::getInstance().computePosition(Vec2i(x, y), targetPos) && if(game->isValidMouseCellPos() &&
world->getMap()->isInsideSurface(world->getMap()->toSurfCoords(targetPos)) == true) { world->getMap()->isInsideSurface(world->getMap()->toSurfCoords(targetPos)) == true) {
giveDefaultOrders(x, y); giveDefaultOrders(x, y);
} }
@ -331,7 +331,8 @@ void Gui::mouseMoveGraphics(int x, int y) {
//compute position for building //compute position for building
if(isPlacingBuilding()){ if(isPlacingBuilding()){
validPosObjWorld= Renderer::getInstance().computePosition(Vec2i(x,y), posObjWorld); posObjWorld=game->getMouseCellPos();
validPosObjWorld= game->isValidMouseCellPos();
} }
display.setInfoText(""); display.setInfoText("");
@ -1160,8 +1161,7 @@ bool Gui::computeTarget(const Vec2i &screenPos, Vec2i &targetPos, const Unit *&t
if(selObj != NULL) { if(selObj != NULL) {
selObj->resetHighlight(); selObj->resetHighlight();
// get real click pos // get real click pos
renderer.computePosition(screenPos, targetPos); targetPos=game->getMouseCellPos();
//validPosObjWorld= true; //validPosObjWorld= true;
//posObjWorld = targetPos; //posObjWorld = targetPos;
@ -1252,7 +1252,8 @@ bool Gui::computeTarget(const Vec2i &screenPos, Vec2i &targetPos, const Unit *&t
} }
else{ else{
targetUnit= NULL; targetUnit= NULL;
if(renderer.computePosition(screenPos, targetPos)){ targetPos=game->getMouseCellPos();
if(game->isValidMouseCellPos()){
validPosObjWorld= true; validPosObjWorld= true;
posObjWorld= targetPos; posObjWorld= targetPos;

View File

@ -2068,6 +2068,10 @@ void BaseColorPickEntity::beginPicking() {
glDisable(GL_POLYGON_OFFSET_FILL); glDisable(GL_POLYGON_OFFSET_FILL);
glDisable(GL_NORMALIZE); glDisable(GL_NORMALIZE);
// all off, but we want depth test
glEnable(GL_DEPTH_TEST);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
//glPushAttrib(GL_TEXTURE_2D | GL_LIGHTING | GL_BLEND | GL_MULTISAMPLE | GL_DITHER); //glPushAttrib(GL_TEXTURE_2D | GL_LIGHTING | GL_BLEND | GL_MULTISAMPLE | GL_DITHER);
//glPushAttrib(GL_ENABLE_BIT | GL_LIGHTING_BIT | GL_POLYGON_BIT | GL_CURRENT_BIT | GL_TEXTURE_BIT | GL_NORMALIZE | GL_BLEND | GL_POLYGON_OFFSET_FILL); //glPushAttrib(GL_ENABLE_BIT | GL_LIGHTING_BIT | GL_POLYGON_BIT | GL_CURRENT_BIT | GL_TEXTURE_BIT | GL_NORMALIZE | GL_BLEND | GL_POLYGON_OFFSET_FILL);
} }