Menu2D::Menu2D(const std::string pathTextureMenu): nbButtonInMenu(0){ vertices[0] = glimac::Vertex2DUV(glm::vec2(-1.f, -1.f), glm::vec2(0,1)); vertices[1] = glimac::Vertex2DUV(glm::vec2(1.f, -1.f), glm::vec2(1,1)); vertices[2] = glimac::Vertex2DUV(glm::vec2(1.f, 1.f), glm::vec2(1,0)); vertices[3] = glimac::Vertex2DUV(glm::vec2(-1.f, 1.f), glm::vec2(0,0)); glimac::Texture* background = new glimac::Texture(GL_TEXTURE_2D); background->loadTexture2D(pathTextureMenu); tabTexture.push_back(background); activTexture = tabTexture[0]; setVBO(); setVAO(); }
void Map3DViewWidget::initializeGL() { m_OGLinitialized = true; qglClearColor(QColor(0, 0, 32, 0)); glEnable(GL_DEPTH_TEST); glEnable(GL_TEXTURE_2D); glEnable(GL_CULL_FACE); //glEnable(GL_LIGHTING); //glEnable(GL_LIGHT0); glEnable(GL_MULTISAMPLE); glEnable(GL_BLEND); glShadeModel(GL_SMOOTH); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); glColor4f(1.0, 1.0, 1.0, 1.0); setVBO(); }
void Map3DViewWidget::setMap(Map *data) { qDebug("Map3DWidget::setMap()"); m_map = data; m_entities.clear(); m_vboData.clear(); const int tileSize = SettingManager::value("tileSize").toInt(); for (int i = 1; i <= m_map->size().width(); ++i) { for (int j = 1; j <= m_map->size().height(); ++j) { GLint texid; // set objects Entity ent; ent.type = TerrainEntity; ent.x = i; ent.y = j; ent.selected = false; ent.hovered = false; // set verticles and textures for cache // this moves objects drawing position // simple hack to set center in really center of map - not on left-bottom edge int centerFactorX = (m_map->size().width() * 1.0) / 2; int centerFactorY = (m_map->size().height() * 1.0) / 2; MapTile tile(m_map->tile((i - 1), (j - 1))); bool _old_tex = false; for (unsigned int x = 0; x < m_used_textures.size(); ++x) { if (m_used_textures[x].tileset == m_map->tileset() && m_used_textures[x].tiletexture == tile.texture) { ent.texid = m_used_textures[x].texid; _old_tex = true; break; } } if (_old_tex == false) { texid = bindTexture(Tileset::pixmap(m_map->tileset(), tile.texture, tileSize), GL_TEXTURE_2D, GL_RGBA, QGLContext::LinearFilteringBindOption); qDebug() << "bindTexture" << i << j << texid << tile.texture; used_texture t; t.tileset = m_map->tileset(); t.tiletexture = tile.texture; t.texid = texid; m_used_textures.push_back(t); } if (texid == 0) { qDebug() << "error while loading texture" << m_map->tileset() << tile.texture; } float tile_left_top, tile_left_bottom, tile_right_top, tile_right_bottom; MapTile t_left_top(m_map->tile((i - 1), (j - 1))); tile_left_top = (t_left_top.height * 3.0f) / 255.0f; MapTile t_right_top(m_map->tile((i), (j - 1))); tile_right_top = (t_right_top.height * 3.0f) / 255.0f; if (j - 2 < 0) { tile_left_bottom = tile_left_top; } else { MapTile t_left_bottom(m_map->tile((i - 1), (j - 2))); tile_left_bottom = (t_left_bottom.height * 3.0f) / 255.0f; } if (j - 2 < 0) { tile_right_bottom = tile_right_top; } else { MapTile t_right_bottom(m_map->tile((i), (j - 2))); tile_right_bottom = (t_right_bottom.height * 3.0f) / 255.0f; } float posY = 1.0 * j - centerFactorY; float posX = 1.0 * i - centerFactorX; QPoint flip(((tile.flip & HorizontalFlip) ? -1.0 : 1.0), ((tile.flip & VerticalFlip) ? 1.0 : -1.0)); float rotation((GLfloat)(tile.rotation + 90)); Vertex v1 = {{posX, posY - 1.0, tile_right_bottom}, {0, 0}}; Vertex v2 = {{posX, posY, tile_right_top }, {1, 0}}; Vertex v3 = {{posX - 1.0, posY - 1.0, tile_left_bottom }, {0, 1}}; Vertex v4 = {{posX - 1.0, posY, tile_left_top }, {1, 1}}; m_vboData.push_back(v1); m_vboData.push_back(v2); m_vboData.push_back(v3); m_vboData.push_back(v4); m_vboData.push_back(v3); m_vboData.push_back(v2); ent.flip = flip; ent.rotation = rotation; m_entities.push_back(ent); } } setVBO(); repaint(); connect(m_map, SIGNAL(changed(QRect)), this, SLOT(repaint())); }