void Renderer::Interpolation(const Pipeline &pipeline) { if (this->renderTarget->useFBO) glBindTexture(GL_TEXTURE_2D, renderTarget->textureID[1]); else glBindTexture(GL_TEXTURE_2D, renderTarget->textureID[0]); //Texture wrapping( clamp vs. wrap) if (pipeline.textureWrap == 0) { #ifdef USE_GLES1 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); #else glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); #endif } else { glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); } glMatrixMode(GL_TEXTURE); glLoadIdentity(); glBlendFunc(GL_SRC_ALPHA, GL_ZERO); glColor4f(1.0, 1.0, 1.0, pipeline.screenDecay); glEnable(GL_TEXTURE_2D); glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glDisableClientState(GL_COLOR_ARRAY); //glVertexPointer(2, GL_FLOAT, 0, p); //glTexCoordPointer(2, GL_FLOAT, 0, t); glInterleavedArrays(GL_T2F_V3F,0,p); if (pipeline.staticPerPixel) { for (int j = 0; j < mesh.height - 1; j++) { int base = j * mesh.width * 2 * 5; for (int i = 0; i < mesh.width; i++) { int strip = base + i * 10; p[strip] = pipeline.x_mesh[i][j]; p[strip + 1] = pipeline.y_mesh[i][j]; p[strip + 5] = pipeline.x_mesh[i][j+1]; p[strip + 6] = pipeline.y_mesh[i][j+1]; } } } else { mesh.Reset(); omptl::transform(mesh.p.begin(), mesh.p.end(), mesh.identity.begin(), mesh.p.begin(), &Renderer::PerPixel); for (int j = 0; j < mesh.height - 1; j++) { int base = j * mesh.width * 2 * 5; for (int i = 0; i < mesh.width; i++) { int strip = base + i * 10; int index = j * mesh.width + i; int index2 = (j + 1) * mesh.width + i; p[strip] = mesh.p[index].x; p[strip + 1] = mesh.p[index].y; p[strip + 5] = mesh.p[index2].x; p[strip + 6] = mesh.p[index2].y; } } } for (int j = 0; j < mesh.height - 1; j++) glDrawArrays(GL_TRIANGLE_STRIP,j* mesh.width* 2,mesh.width*2); glDisable(GL_TEXTURE_2D); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); }
static void draw_particles(GLFWwindow* window, double t, float dt) { int i, particle_count; Vertex vertex_array[BATCH_PARTICLES * PARTICLE_VERTS]; Vertex* vptr; float alpha; GLuint rgba; Vec3 quad_lower_left, quad_lower_right; GLfloat mat[16]; PARTICLE* pptr; // Here comes the real trick with flat single primitive objects (s.c. // "billboards"): We must rotate the textured primitive so that it // always faces the viewer (is coplanar with the view-plane). // We: // 1) Create the primitive around origo (0,0,0) // 2) Rotate it so that it is coplanar with the view plane // 3) Translate it according to the particle position // Note that 1) and 2) is the same for all particles (done only once). // Get modelview matrix. We will only use the upper left 3x3 part of // the matrix, which represents the rotation. glGetFloatv(GL_MODELVIEW_MATRIX, mat); // 1) & 2) We do it in one swift step: // Although not obvious, the following six lines represent two matrix/ // vector multiplications. The matrix is the inverse 3x3 rotation // matrix (i.e. the transpose of the same matrix), and the two vectors // represent the lower left corner of the quad, PARTICLE_SIZE/2 * // (-1,-1,0), and the lower right corner, PARTICLE_SIZE/2 * (1,-1,0). // The upper left/right corners of the quad is always the negative of // the opposite corners (regardless of rotation). quad_lower_left.x = (-PARTICLE_SIZE / 2) * (mat[0] + mat[1]); quad_lower_left.y = (-PARTICLE_SIZE / 2) * (mat[4] + mat[5]); quad_lower_left.z = (-PARTICLE_SIZE / 2) * (mat[8] + mat[9]); quad_lower_right.x = (PARTICLE_SIZE / 2) * (mat[0] - mat[1]); quad_lower_right.y = (PARTICLE_SIZE / 2) * (mat[4] - mat[5]); quad_lower_right.z = (PARTICLE_SIZE / 2) * (mat[8] - mat[9]); // Don't update z-buffer, since all particles are transparent! glDepthMask(GL_FALSE); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE); // Select particle texture if (!wireframe) { glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, particle_tex_id); } // Set up vertex arrays. We use interleaved arrays, which is easier to // handle (in most situations) and it gives a linear memeory access // access pattern (which may give better performance in some // situations). GL_T2F_C4UB_V3F means: 2 floats for texture coords, // 4 ubytes for color and 3 floats for vertex coord (in that order). // Most OpenGL cards / drivers are optimized for this format. glInterleavedArrays(GL_T2F_C4UB_V3F, 0, vertex_array); // Wait for particle physics thread to be done mtx_lock(&thread_sync.particles_lock); while (!glfwWindowShouldClose(window) && thread_sync.p_frame <= thread_sync.d_frame) { struct timespec ts; clock_gettime(CLOCK_REALTIME, &ts); ts.tv_nsec += 100000000; cnd_timedwait(&thread_sync.p_done, &thread_sync.particles_lock, &ts); } // Store the frame time and delta time for the physics thread thread_sync.t = t; thread_sync.dt = dt; // Update frame counter thread_sync.d_frame++; // Loop through all particles and build vertex arrays. particle_count = 0; vptr = vertex_array; pptr = particles; for (i = 0; i < MAX_PARTICLES; i++) { if (pptr->active) { // Calculate particle intensity (we set it to max during 75% // of its life, then it fades out) alpha = 4.f * pptr->life; if (alpha > 1.f) alpha = 1.f; // Convert color from float to 8-bit (store it in a 32-bit // integer using endian independent type casting) ((GLubyte*) &rgba)[0] = (GLubyte)(pptr->r * 255.f); ((GLubyte*) &rgba)[1] = (GLubyte)(pptr->g * 255.f); ((GLubyte*) &rgba)[2] = (GLubyte)(pptr->b * 255.f); ((GLubyte*) &rgba)[3] = (GLubyte)(alpha * 255.f); // 3) Translate the quad to the correct position in modelview // space and store its parameters in vertex arrays (we also // store texture coord and color information for each vertex). // Lower left corner vptr->s = 0.f; vptr->t = 0.f; vptr->rgba = rgba; vptr->x = pptr->x + quad_lower_left.x; vptr->y = pptr->y + quad_lower_left.y; vptr->z = pptr->z + quad_lower_left.z; vptr ++; // Lower right corner vptr->s = 1.f; vptr->t = 0.f; vptr->rgba = rgba; vptr->x = pptr->x + quad_lower_right.x; vptr->y = pptr->y + quad_lower_right.y; vptr->z = pptr->z + quad_lower_right.z; vptr ++; // Upper right corner vptr->s = 1.f; vptr->t = 1.f; vptr->rgba = rgba; vptr->x = pptr->x - quad_lower_left.x; vptr->y = pptr->y - quad_lower_left.y; vptr->z = pptr->z - quad_lower_left.z; vptr ++; // Upper left corner vptr->s = 0.f; vptr->t = 1.f; vptr->rgba = rgba; vptr->x = pptr->x - quad_lower_right.x; vptr->y = pptr->y - quad_lower_right.y; vptr->z = pptr->z - quad_lower_right.z; vptr ++; // Increase count of drawable particles particle_count ++; } // If we have filled up one batch of particles, draw it as a set // of quads using glDrawArrays. if (particle_count >= BATCH_PARTICLES) { // The first argument tells which primitive type we use (QUAD) // The second argument tells the index of the first vertex (0) // The last argument is the vertex count glDrawArrays(GL_QUADS, 0, PARTICLE_VERTS * particle_count); particle_count = 0; vptr = vertex_array; } // Next particle pptr++; } // We are done with the particle data mtx_unlock(&thread_sync.particles_lock); cnd_signal(&thread_sync.d_done); // Draw final batch of particles (if any) glDrawArrays(GL_QUADS, 0, PARTICLE_VERTS * particle_count); // Disable vertex arrays (Note: glInterleavedArrays implicitly called // glEnableClientState for vertex, texture coord and color arrays) glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_TEXTURE_COORD_ARRAY); glDisableClientState(GL_COLOR_ARRAY); glDisable(GL_TEXTURE_2D); glDisable(GL_BLEND); glDepthMask(GL_TRUE); }
void TerrainRenderer::DrawWays(const PreparedRoads& sorted_roads) { // 2D Array: [3][4] static const boost::array<PointI, 12> begin_end_coords = {{ PointI(-3, -3), PointI(-3, 3), PointI(-3, 3), PointI(-3, -3), PointI( 3, -3), PointI(-3, 3), PointI(-3, 3), PointI( 3, -3), PointI( 3, 3), PointI(-3, -3), PointI(-3, -3), PointI( 3, 3) }}; if (vboBuffersUsed) { // unbind VBO glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0); } int type = 0; for (PreparedRoads::const_iterator itRoad = sorted_roads.begin(); itRoad != sorted_roads.end(); ++itRoad, ++type) { unsigned int i = 0; boost::scoped_array<GL_T2F_C3F_V3F_Struct> tmp(new GL_T2F_C3F_V3F_Struct[itRoad->size() * 4]); for (std::vector<PreparedRoad>::const_iterator it = itRoad->begin(); it != itRoad->end(); ++it) { assert(it->dir < 3); // begin_end_coords has 3 dir entries tmp[i].tx = 0.0f; tmp[i].ty = 0.0f; tmp[i].r = it->color1; tmp[i].g = it->color1; tmp[i].b = it->color1; PointI tmpP = it->pos + begin_end_coords[it->dir * 4]; tmp[i].x = GLfloat(tmpP.x); tmp[i].y = GLfloat(tmpP.y); tmp[i].z = 0.0f; i++; tmp[i].tx = 0.0f; tmp[i].ty = 1.0f; tmp[i].r = it->color1; tmp[i].g = it->color1; tmp[i].b = it->color1; tmpP = it->pos + begin_end_coords[it->dir * 4 + 1]; tmp[i].x = GLfloat(tmpP.x); tmp[i].y = GLfloat(tmpP.y); tmp[i].z = 0.0f; i++; tmp[i].tx = 0.78f; tmp[i].ty = 1.0f; tmp[i].r = it->color2; tmp[i].g = it->color2; tmp[i].b = it->color2; tmpP = it->pos2 + begin_end_coords[it->dir * 4 + 2]; tmp[i].x = GLfloat(tmpP.x); tmp[i].y = GLfloat(tmpP.y); tmp[i].z = 0.0f; i++; tmp[i].tx = 0.78f; tmp[i].ty = 0.0f; tmp[i].r = it->color2; tmp[i].g = it->color2; tmp[i].b = it->color2; tmpP = it->pos2 + begin_end_coords[it->dir * 4 + 3]; tmp[i].x = GLfloat(tmpP.x); tmp[i].y = GLfloat(tmpP.y); tmp[i].z = 0.0f; i++; } glInterleavedArrays(GL_T2F_C3F_V3F, 0, tmp.get()); VIDEODRIVER.BindTexture(GetImage(roads, type)->GetTexture()); glDrawArrays(GL_QUADS, 0, i); } }
void GuiRenderer::renderQuadDirect(const CEGUI::Rect& dest_rect, float z, const CEGUI::Texture* tex, const CEGUI::Rect& texture_rect, const CEGUI::ColourRect& colours, CEGUI::QuadSplitMode quad_split_mode) { QuadInfo quad; quad.position.d_left = dest_rect.d_left; quad.position.d_right = dest_rect.d_right; quad.position.d_bottom = _display_area.d_bottom - dest_rect.d_bottom; quad.position.d_top = _display_area.d_bottom - dest_rect.d_top; quad.texPosition = texture_rect; quad.topLeftCol = colourToOGL(colours.d_top_left); quad.topRightCol = colourToOGL(colours.d_top_right); quad.bottomLeftCol = colourToOGL(colours.d_bottom_left); quad.bottomRightCol = colourToOGL(colours.d_bottom_right); MyQuad myquad[VERTEX_PER_QUAD]; initPerFrameStates(); glInterleavedArrays(GL_T2F_C4UB_V3F , 0, myquad); glBindTexture(GL_TEXTURE_2D, ((GuiTexture*)tex)->getOGLTexid()); //vert0 myquad[0].vertex[0] = quad.position.d_left; myquad[0].vertex[1] = quad.position.d_top; myquad[0].vertex[2] = z; myquad[0].color = quad.topLeftCol; myquad[0].tex[0] = quad.texPosition.d_left; myquad[0].tex[1] = quad.texPosition.d_top; //vert1 myquad[1].vertex[0] = quad.position.d_left; myquad[1].vertex[1] = quad.position.d_bottom; myquad[1].vertex[2] = z; myquad[1].color = quad.bottomLeftCol; myquad[1].tex[0] = quad.texPosition.d_left; myquad[1].tex[1] = quad.texPosition.d_bottom; //vert2 // top-left to bottom-right diagonal if (quad_split_mode == CEGUI::TopLeftToBottomRight) { myquad[2].vertex[0] = quad.position.d_right; myquad[2].vertex[1] = quad.position.d_bottom; myquad[2].vertex[2] = z; myquad[2].color = quad.bottomRightCol; myquad[2].tex[0] = quad.texPosition.d_right; myquad[2].tex[1] = quad.texPosition.d_bottom; } // bottom-left to top-right diagonal else { myquad[2].vertex[0] = quad.position.d_right; myquad[2].vertex[1] = quad.position.d_top; myquad[2].vertex[2] = z; myquad[2].color = quad.topRightCol; myquad[2].tex[0] = quad.texPosition.d_right; myquad[2].tex[1] = quad.texPosition.d_top; } //vert3 myquad[3].vertex[0] = quad.position.d_right; myquad[3].vertex[1] = quad.position.d_top; myquad[3].vertex[2] = z; myquad[3].color = quad.topRightCol; myquad[3].tex[0] = quad.texPosition.d_right; myquad[3].tex[1] = quad.texPosition.d_top; //vert4 // top-left to bottom-right diagonal if (quad_split_mode == CEGUI::TopLeftToBottomRight) { myquad[4].vertex[0] = quad.position.d_left; myquad[4].vertex[1] = quad.position.d_top; myquad[4].vertex[2] = z; myquad[4].color = quad.topLeftCol; myquad[4].tex[0] = quad.texPosition.d_left; myquad[4].tex[1] = quad.texPosition.d_top; } // bottom-left to top-right diagonal else { myquad[4].vertex[0] = quad.position.d_left; myquad[4].vertex[1] = quad.position.d_bottom; myquad[4].vertex[2] = z; myquad[4].color = quad.bottomLeftCol; myquad[4].tex[0] = quad.texPosition.d_left; myquad[4].tex[1] = quad.texPosition.d_bottom; } //vert5 myquad[5].vertex[0] = quad.position.d_right; myquad[5].vertex[1] = quad.position.d_bottom; myquad[5].vertex[2] = z; myquad[5].color = quad.bottomRightCol; myquad[5].tex[0] = quad.texPosition.d_right; myquad[5].tex[1] = quad.texPosition.d_bottom; glDrawArrays(GL_TRIANGLES, 0, 6); exitPerFrameStates(); }
void TerrainRenderer::DrawWays(GameWorldView* gwv) { const float begin_end_coords[24] = { -3.0f, -3.0f, -3.0f, 3.0f, -3.0f, 3.0f, -3.0f, -3.0f, 3.0f, -3.0f, -3.0f, 3.0f, -3.0f, 3.0f, 3.0f, -3.0f, 3.0f, 3.0f, -3.0f, -3.0f, -3.0f, -3.0f, 3.0f, 3.0f, }; if (SETTINGS.video.vbo) { // unbind VBO glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0); } for (unsigned char type = 0; type < 4; type++) { unsigned int i = 0; GL_T2F_C3F_V3F_Struct* tmp = new GL_T2F_C3F_V3F_Struct[gwv->sorted_roads[type].size() * 4]; for (std::list<PreparedRoad>::iterator it = gwv->sorted_roads[type].begin(); it != gwv->sorted_roads[type].end(); ++it) { tmp[i].tx = 0.0f; tmp[i].ty = 0.0f; tmp[i].r = (*it).color1; tmp[i].g = (*it).color1; tmp[i].b = (*it).color1; tmp[i].x = (*it).xpos + begin_end_coords[(*it).dir * 8]; tmp[i].y = (*it).ypos + begin_end_coords[(*it).dir * 8 + 1]; tmp[i].z = 0.0f; i++; tmp[i].tx = 0.0f; tmp[i].ty = 1.0f; tmp[i].r = (*it).color1; tmp[i].g = (*it).color1; tmp[i].b = (*it).color1; tmp[i].x = (*it).xpos + begin_end_coords[(*it).dir * 8 + 2]; tmp[i].y = (*it).ypos + begin_end_coords[(*it).dir * 8 + 3]; tmp[i].z = 0.0f; i++; tmp[i].tx = 0.78f; tmp[i].ty = 1.0f; tmp[i].r = (*it).color2; tmp[i].g = (*it).color2; tmp[i].b = (*it).color2; tmp[i].x = (*it).xpos2 + begin_end_coords[(*it).dir * 8 + 4]; tmp[i].y = (*it).ypos2 + begin_end_coords[(*it).dir * 8 + 5]; tmp[i].z = 0.0f; i++; tmp[i].tx = 0.78f; tmp[i].ty = 0.0f; tmp[i].r = (*it).color2; tmp[i].g = (*it).color2; tmp[i].b = (*it).color2; tmp[i].x = (*it).xpos2 + begin_end_coords[(*it).dir * 8 + 6]; tmp[i].y = (*it).ypos2 + begin_end_coords[(*it).dir * 8 + 7]; tmp[i].z = 0.0f; i++; } glInterleavedArrays(GL_T2F_C3F_V3F, 0, tmp); VIDEODRIVER.BindTexture(GetImage(roads, type)->GetTexture()); glDrawArrays(GL_QUADS, 0, i); delete[] tmp; } }
M(void, glInterleavedArrays, jint format, jint stride, jobject pointer) { glInterleavedArrays(format, stride, BUFF(GLvoid, pointer)); }
void GuiRenderer::doRender() { initPerFrameStates(); glInterleavedArrays( GL_T2F_C4UB_V3F , 0, _buff ); _currTexture = 0; // iterate over each quad in the list for (QuadList::iterator i = _quadlist.begin(); i != _quadlist.end(); ++i) { const QuadInfo& quad = (*i); if(_currTexture != quad.texid) { renderVBuffer(); glBindTexture(GL_TEXTURE_2D, quad.texid); _currTexture = quad.texid; } //vert0 _buff[_bufferPos].vertex[0] = quad.position.d_left; _buff[_bufferPos].vertex[1] = quad.position.d_top; _buff[_bufferPos].vertex[2] = quad.z; _buff[_bufferPos].color = quad.topLeftCol; _buff[_bufferPos].tex[0] = quad.texPosition.d_left; _buff[_bufferPos].tex[1] = quad.texPosition.d_top; ++_bufferPos; //vert1 _buff[_bufferPos].vertex[0] = quad.position.d_left; _buff[_bufferPos].vertex[1] = quad.position.d_bottom; _buff[_bufferPos].vertex[2] = quad.z; _buff[_bufferPos].color = quad.bottomLeftCol; _buff[_bufferPos].tex[0] = quad.texPosition.d_left; _buff[_bufferPos].tex[1] = quad.texPosition.d_bottom; ++_bufferPos; //vert2 // top-left to bottom-right diagonal if (quad.splitMode == CEGUI::TopLeftToBottomRight) { _buff[_bufferPos].vertex[0] = quad.position.d_right; _buff[_bufferPos].vertex[1] = quad.position.d_bottom; _buff[_bufferPos].vertex[2] = quad.z; _buff[_bufferPos].color = quad.bottomRightCol; _buff[_bufferPos].tex[0] = quad.texPosition.d_right; _buff[_bufferPos].tex[1] = quad.texPosition.d_bottom; } // bottom-left to top-right diagonal else { _buff[_bufferPos].vertex[0] = quad.position.d_right; _buff[_bufferPos].vertex[1] = quad.position.d_top; _buff[_bufferPos].vertex[2] = quad.z; _buff[_bufferPos].color = quad.topRightCol; _buff[_bufferPos].tex[0] = quad.texPosition.d_right; _buff[_bufferPos].tex[1] = quad.texPosition.d_top; } ++_bufferPos; //vert3 _buff[_bufferPos].vertex[0] = quad.position.d_right; _buff[_bufferPos].vertex[1] = quad.position.d_top; _buff[_bufferPos].vertex[2] = quad.z; _buff[_bufferPos].color = quad.topRightCol; _buff[_bufferPos].tex[0] = quad.texPosition.d_right; _buff[_bufferPos].tex[1] = quad.texPosition.d_top; ++_bufferPos; //vert4 // top-left to bottom-right diagonal if (quad.splitMode == CEGUI::TopLeftToBottomRight) { _buff[_bufferPos].vertex[0] = quad.position.d_left; _buff[_bufferPos].vertex[1] = quad.position.d_top; _buff[_bufferPos].vertex[2] = quad.z; _buff[_bufferPos].color = quad.topLeftCol; _buff[_bufferPos].tex[0] = quad.texPosition.d_left; _buff[_bufferPos].tex[1] = quad.texPosition.d_top; } // bottom-left to top-right diagonal else { _buff[_bufferPos].vertex[0] = quad.position.d_left; _buff[_bufferPos].vertex[1] = quad.position.d_bottom; _buff[_bufferPos].vertex[2] = quad.z; _buff[_bufferPos].color = quad.bottomLeftCol; _buff[_bufferPos].tex[0] = quad.texPosition.d_left; _buff[_bufferPos].tex[1] = quad.texPosition.d_bottom; } ++_bufferPos; //vert 5 _buff[_bufferPos].vertex[0] = quad.position.d_right; _buff[_bufferPos].vertex[1] = quad.position.d_bottom; _buff[_bufferPos].vertex[2] = quad.z; _buff[_bufferPos].color = quad.bottomRightCol; _buff[_bufferPos].tex[0] = quad.texPosition.d_right; _buff[_bufferPos].tex[1] = quad.texPosition.d_bottom; ++_bufferPos; if(_bufferPos > (VERTEXBUFFER_CAPACITY - VERTEX_PER_QUAD)) { renderVBuffer(); } } //Render renderVBuffer(); exitPerFrameStates(); }
void GLDrawable::Commit() { glBindBuffer( GL_ARRAY_BUFFER, vboID ); glBufferData( GL_ARRAY_BUFFER, dataSize * sizeof(GLfloat), data, usage ); glInterleavedArrays( format, 0, 0 ); }
void GLDrawable::Update( GLuint index, GLuint length ) { glBindBuffer( GL_ARRAY_BUFFER, vboID ); glBufferSubData( GL_ARRAY_BUFFER, index * elemSize * sizeof(GLfloat), length * elemSize * sizeof(GLfloat), data ); glInterleavedArrays( format, 0, 0 ); }
void ClientOSRenderer::Render() { if (view_width_ == 0 || view_height_ == 0) return; DCHECK(initialized_); struct { float tu, tv; float x, y, z; } static vertices[] = { {0.0f, 1.0f, -1.0f, -1.0f, 0.0f}, {1.0f, 1.0f, 1.0f, -1.0f, 0.0f}, {1.0f, 0.0f, 1.0f, 1.0f, 0.0f}, {0.0f, 0.0f, -1.0f, 1.0f, 0.0f} }; glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); VERIFY_NO_ERROR; glMatrixMode(GL_MODELVIEW); VERIFY_NO_ERROR; glLoadIdentity(); VERIFY_NO_ERROR; // Match GL units to screen coordinates. glViewport(0, 0, view_width_, view_height_); VERIFY_NO_ERROR; glMatrixMode(GL_PROJECTION); VERIFY_NO_ERROR; glLoadIdentity(); VERIFY_NO_ERROR; // Draw the background gradient. glPushAttrib(GL_ALL_ATTRIB_BITS); VERIFY_NO_ERROR; // Don't check for errors until glEnd(). glBegin(GL_QUADS); glColor4f(1.0, 0.0, 0.0, 1.0); // red glVertex2f(-1.0, -1.0); glVertex2f(1.0, -1.0); glColor4f(0.0, 0.0, 1.0, 1.0); // blue glVertex2f(1.0, 1.0); glVertex2f(-1.0, 1.0); glEnd(); VERIFY_NO_ERROR; glPopAttrib(); VERIFY_NO_ERROR; // Rotate the view based on the mouse spin. if (spin_x_ != 0) { glRotatef(-spin_x_, 1.0f, 0.0f, 0.0f); VERIFY_NO_ERROR; } if (spin_y_ != 0) { glRotatef(-spin_y_, 0.0f, 1.0f, 0.0f); VERIFY_NO_ERROR; } if (transparent_) { // Alpha blending style. Texture values have premultiplied alpha. glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); VERIFY_NO_ERROR; // Enable alpha blending. glEnable(GL_BLEND); VERIFY_NO_ERROR; } // Enable 2D textures. glEnable(GL_TEXTURE_2D); VERIFY_NO_ERROR; // Draw the facets with the texture. DCHECK_NE(texture_id_, 0U); VERIFY_NO_ERROR; glBindTexture(GL_TEXTURE_2D, texture_id_); VERIFY_NO_ERROR; glInterleavedArrays(GL_T2F_V3F, 0, vertices); VERIFY_NO_ERROR; glDrawArrays(GL_QUADS, 0, 4); VERIFY_NO_ERROR; // Disable 2D textures. glDisable(GL_TEXTURE_2D); VERIFY_NO_ERROR; if (transparent_) { // Disable alpha blending. glDisable(GL_BLEND); VERIFY_NO_ERROR; } // Draw a rectangle around the update region. if (show_update_rect_ && !update_rect_.IsEmpty()) { int left = update_rect_.x; int right = update_rect_.x + update_rect_.width; int top = update_rect_.y; int bottom = update_rect_.y + update_rect_.height; #if defined(OS_LINUX) // Shrink the box so that top & right sides are drawn. top += 1; right -= 1; #else // Shrink the box so that left & bottom sides are drawn. left += 1; bottom -= 1; #endif glPushAttrib(GL_ALL_ATTRIB_BITS); VERIFY_NO_ERROR glMatrixMode(GL_PROJECTION); VERIFY_NO_ERROR; glPushMatrix(); VERIFY_NO_ERROR; glLoadIdentity(); VERIFY_NO_ERROR; glOrtho(0, view_width_, view_height_, 0, 0, 1); VERIFY_NO_ERROR; glLineWidth(1); VERIFY_NO_ERROR; glColor3f(1.0f, 0.0f, 0.0f); VERIFY_NO_ERROR; // Don't check for errors until glEnd(). glBegin(GL_LINE_STRIP); glVertex2i(left, top); glVertex2i(right, top); glVertex2i(right, bottom); glVertex2i(left, bottom); glVertex2i(left, top); glEnd(); VERIFY_NO_ERROR; glPopMatrix(); VERIFY_NO_ERROR; glPopAttrib(); VERIFY_NO_ERROR; } }
//----------------------------------------------------------------------------- // Name: render() // Desc: //----------------------------------------------------------------------------- void render( void ) { glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); glMatrixMode( GL_MODELVIEW ); glLoadIdentity(); glTranslatef( 0.0f, 0.0f, g_fDistance ); glRotatef( -g_fSpinY, 1.0f, 0.0f, 0.0f ); glRotatef( -g_fSpinX, 0.0f, 1.0f, 0.0f ); for (int i=0; i<g_vertexCount; i++) { g_quadVertices[i].tv += g_arrowSpeed; } if( g_bBlending == true ) { // // Use the texture's alpha channel to blend it with whatever’s already // in the frame-buffer. // glDisable( GL_DEPTH_TEST ); glEnable( GL_BLEND ); // glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); glBlendFunc( GL_SRC_COLOR, GL_ONE_MINUS_SRC_COLOR ); glBindTexture( GL_TEXTURE_2D, g_textureID ); if( g_bSortUsingCullModeTrick == true ) { // // Use the cull-mode sorting trick for convex non-overlapping // geometry. // glEnable( GL_CULL_FACE ); // // Render the cube but only render the back-facing polygons. // glCullFace( GL_FRONT ); glInterleavedArrays( GL_T2F_V3F, 0, g_quadVertices ); glDrawArrays( GL_QUADS, 0, g_vertexCount ); // // Render the cube again, but this time we only render the // front-facing polygons. // glCullFace( GL_BACK ); glInterleavedArrays( GL_T2F_V3F, 0, g_quadVertices ); glDrawArrays( GL_QUADS, 0, g_vertexCount ); glDisable( GL_CULL_FACE ); } else { // // Do no sorting and hope for the best. From certain viewing // positions the cube's sides will appear sorted correctly, but this // is typically rare and the cube will not look right most of the // time. // glInterleavedArrays( GL_T2F_V3F, 0, g_quadVertices ); glDrawArrays( GL_QUADS, 0, g_vertexCount ); } } else { // // Render the cube, but do no blending... // glDisable( GL_BLEND ); glEnable( GL_DEPTH_TEST ); glBindTexture( GL_TEXTURE_2D, g_textureID ); glInterleavedArrays( GL_T2F_V3F, 0, g_quadVertices ); glDrawArrays( GL_QUADS, 0, g_vertexCount ); } SwapBuffers( g_hDC ); Sleep(40); }
void DotSpreaderTool::render(DTS::DataItem* dataItem) const { // if dragging locator render release sphere if (active and !data.running) { // save current attribute state #ifdef MESA // GL_POINT_BIT causes GL enum error glPushAttrib(GL_LIGHTING_BIT | GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); #else glPushAttrib(GL_LIGHTING_BIT | GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT | GL_POINT_BIT); #endif glDisable(GL_LIGHTING); // save current location glPushMatrix(); // move to center of sphere glTranslatef(org[0], org[1], org[2]); // compute radius of sphere float radius=Math::sqrt((pos[0] - org[0]) * (pos[0] - org[0]) + (pos[1] - org[1]) * (pos[1] - org[1]) + (pos[2] - org[2]) * (pos[2] - org[2])); GLUquadricObj *quadric=gluNewQuadric(); // draw transparent sphere gluQuadricDrawStyle(quadric, GLU_FILL); glDepthMask(GL_FALSE); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glColor4f(0.0f, 0.6f, 1.0f, 0.2f); gluSphere(quadric, radius, 10, 15); glDisable(GL_BLEND); // draw surrounding wireframe (solid) gluQuadricDrawStyle(quadric, GLU_LINE); glDepthMask(GL_TRUE); glColor4f(0.0f, 0.8f, 1.0f, 1.0f); gluSphere(quadric, radius, 10, 15); glDepthMask(GL_FALSE); gluDeleteQuadric(quadric); // restore previous position glPopMatrix(); // restore previous attribute state glPopAttrib(); } // if simulation is running draw particles else if (data.running) { // save current attribute state #ifdef MESA // GL_POINT_BIT causes GL enum error glPushAttrib(GL_LIGHTING_BIT | GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); #else glPushAttrib(GL_LIGHTING_BIT | GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT | GL_POINT_BIT); #endif glDisable(GL_LIGHTING); glDepthMask(GL_FALSE); glEnable(GL_POINT_SMOOTH); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE); glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, dataItem->spriteTextureObjectId); glTexEnvf(GL_POINT_SPRITE_ARB, GL_COORD_REPLACE_ARB, GL_TRUE); glEnable(GL_POINT_SPRITE_ARB); float particleRadius=data.point_radius; // Query the OpenGL viewing frustum GLFrustum<float> frustum; frustum.setFromGL(); #ifdef GHETTO if (0) #else if (dataItem->hasShaders) #endif { /* Calculate the scaled point size for this frustum: */ GLfloat scaledParticleRadius=frustum.getPixelSize() * particleRadius / frustum.getEyeScreenDistance(); /* Enable the vertex/fragment shader: */ glEnable(GL_VERTEX_PROGRAM_POINT_SIZE_ARB); glUseProgramObjectARB(dataItem->programObject); glUniform1fARB(dataItem->scaledParticleRadiusLocation, scaledParticleRadius); glUniform1iARB(dataItem->tex0Location, 0); } else { glPointSize(particleRadius * Vrui::getNavigationTransformation().getScaling()); GLfloat linear[3]= { 0.0, 1 / 5.0, 0.0 }; glPointParameterfvARB(GL_POINT_DISTANCE_ATTENUATION_ARB, linear); // // NOTE::the following scaling calculation does not work properly // in the CAVE. This is due to changes in the OpenGL library and // cannot be fixed. On a 2D screen the scaling should look correct. // // Query the OpenGL viewing frustum GLFrustum<float> frustum; frustum.setFromGL(); // Calculate the nominal pixel size for particles float pointSizeCounter=frustum.getPixelSize() * 2.0f * particleRadius; float pointSizeDenominator=frustum.getEyeScreenDistance(); // Query the maximum point size accepted by glPointSize(...) GLfloat pointSizeRange[2]; glGetFloatv(GL_SMOOTH_POINT_SIZE_RANGE, pointSizeRange); // Enable point parameters glPointSize(pointSizeRange[1]); // select the maximum point size pointSizeCounter/=pointSizeRange[1]; // adjust the point size numerator GLfloat attenuation[3]= { 0.0f, 0.0f, 0.0f }; attenuation[2]=Math::sqr(pointSizeDenominator / pointSizeCounter); glPointParameterfvARB(GL_POINT_DISTANCE_ATTENUATION_ARB, attenuation); } glBindBufferARB(GL_ARRAY_BUFFER_ARB, dataItem->vertexBufferId); glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_COLOR_ARRAY); // If data has been modified, send to graphics card if (dataItem->versionDS != data.currentVersion) { dataItem->numParticlesDS = data.numPoints; glBufferDataARB(GL_ARRAY_BUFFER_ARB, dataItem->numParticlesDS * sizeof(ColorPoint), &data.particles[0], GL_DYNAMIC_DRAW_ARB); dataItem->versionDS = data.currentVersion; } glInterleavedArrays(GL_C4UB_V3F, sizeof(ColorPoint), 0); glDrawArrays(GL_POINTS, 0, dataItem->numParticlesDS); glDisableClientState(GL_COLOR_ARRAY); glDisableClientState(GL_VERTEX_ARRAY); #ifndef GHETTO if (dataItem->hasShaders) #endif { glUseProgramObjectARB(0); glDisable(GL_VERTEX_PROGRAM_POINT_SIZE_ARB); } glBindTexture(GL_TEXTURE_2D, 0); glDisable(GL_TEXTURE_2D); glDisable(GL_POINT_SPRITE_ARB); glDisable(GL_BLEND); // restore previous attribute state glPopAttrib(); } }
void GL_draw_frame( void * vp ) { static float rot; static int t0; float s; glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLineWidth(1.f); set_camera_view(); if ( t0 == 0 ) { init_VBO(); t0 = 1; } int now = get_milliseconds(); /* while ( now - t0 > 20 ) { rot += 1.0f; t0 += 20; if ( rot > 360.f ) rot -= 360.f; if ( rot < 0.f ) rot += 360.f; } */ // hack to get rotation timer right const float p180 = 0.017453126f; const float c180p = 57.295776f; const float c2pi = 6.2831854f; const int ms_per_frame = 20; // milliseconds per frame const float rot_per_frame = 1.0f * p180; /* while ( now - t0 > ms_per_frame ) { rot += 1.0f; t0 += ms_per_frame; } */ static int set = 0; if ( t0 <= 0 ) t0 = 1; if ( now - t0 > 0 ) { int diff = now - t0; /* the rotation is incremented 1 rot_per_frame each 1 ms_per_frame */ float newrot = rot + (rot_per_frame/(float)ms_per_frame) * ((float)diff); if ( set < 20 ) core.printf( "hiccup > 2pi: before: %f, %f ", rot, sinf(rot) ); rot = newrot; // catch it up t0 = now; if ( set < 20 ) core.printf( "after: %f, %f\n", rot, sinf( rot ) ); // clamp if ( rot > c2pi ) { rot = rot - c2pi; set = 1; // no more print core.printf( " --> MARK <-- \n" ); } if ( set != 0 ) ++set; } const float rotdeg = rot * c180p; /// -- DRAW --- // rotating wire spiral glColor4ub( 255,255,255,255 ); glPushMatrix(); glRotatef( rotdeg, 0, 1, 0 ); draw_spiral( 24.0f, 10.f, 0.05f ); glPopMatrix(); // rotating circle glEnable(GL_TEXTURE_2D); glBindTexture( GL_TEXTURE_2D, core.materials.findByName( "jr_bob" )->img->texhandle ); glPushMatrix(); glTranslatef( 60.f, 60.f, -60.f ); glRotatef( rotdeg, 0, 1, 0 ); draw_circle( 0, 0, 10.f ); GL_TEX_SQUARE( -10.f, 30.f, 0.f, 20.f ); glRotatef( 180, 0, 1, 0 ); draw_circle( 0, 0, 10.f ); GL_TEX_SQUARE( -10.f, 30.f, 0.f, 20.f ); glBegin(GL_LINES); glVertex3f( 0, -30.f, 0 ); glVertex3f( 0, 30.f, 0 ); glEnd(); glPopMatrix(); glDisable( GL_TEXTURE_2D ); // FIXME : obviously move, later. tessellatedPlane_t& tes = *(tessellatedPlane_t*)vp; // heightmap triangles glInterleavedArrays( GL_C3F_V3F, 0, tes.array ); glDrawArrays( GL_TRIANGLE_STRIP, 0, tes.num_verts ); //glDrawArrays( GL_LINE_STRIP, 0, tes->num_verts ); // gazillion boxes core.drawer.drawLists(); // serpinski glColor4ub( 255,255,0,255 ); glPushMatrix(); glTranslatef( 250.f, 100.f, -250.f ); glRotatef( rotdeg * 1.618f, 0, 1, 0 ); glRotatef( rotdeg , 0.707, 0, -0.707 ); glDisable( GL_CULL_FACE ); draw_serpinski( 3, 40.f ); glEnable( GL_CULL_FACE ); glPopMatrix(); glColor4ub( 255,255,255,255 ); // icosahedron glPushMatrix(); glTranslatef( 500.f, 100.f, -250.f ); trans_spiral_f( rot, 50.f /*radius*/, 1.0f/*rot rate*/, 1.0f/*climb rate*/, 50.f /*ceiling*/ ); s = 14.f; s = (sinf( rot * 2.718f ) + 1.1f) * 14.f; glScalef( s, s, s ); glRotatef( rotdeg * 5.f, 0, 1, 0 ); glRotatef( rotdeg * 3.f , 0.707, 0, -0.707 ); glColor4ub( 230, 100, 0, 255 ); draw_icosahedron(); glColor4ub( 255, 255, 255, 255 ); draw_icosahedron_wire(); glPopMatrix(); // axis marker float l = 100.f; glColor3f( 1.f, 0.f, 1.f ); glLineWidth(2.f); glBegin( GL_LINES ); glVertex3i( 0,0,0 ); glVertex3i( 0,l,0); glVertex3i( 0,0,0 ); glVertex3i( l,0,0 ); glVertex3i( 0,0,0 ); glVertex3i( 0,0,-l ); glEnd(); // 4-sided glPushMatrix(); glTranslatef( 300, 100, 0 ); s = 20.f; glScalef( s, s, s ); glRotatef( rotdeg, 0, 1, 0 ); glColor4ub( 0, 255, 255, 128 ); draw_triangle4(0); glColor4ub( 255, 255, 255, 255 ); draw_triangle4(1); glPopMatrix(); // 4-sided, 2nd type glPushMatrix(); glTranslatef( 340, 100, 0 ); s = 20.f; glScalef( s, s, s ); glRotatef( rotdeg, 0, 1, 0 ); glColor4ub( 100, 0, 100, 128 ); draw_triangle4_2(0); glColor4ub( 255, 255, 255, 255 ); draw_triangle4(1); // inner lines don't draw right, so use first form glPopMatrix(); // 5-sided glPushMatrix(); glTranslatef( 100, 100, -50 ); s = 20.f; glScalef( s, s, s ); glRotatef( rotdeg, 1, 0, 0 ); glColor4ub( 100, 50, 0, 200 ); draw_triangle5(0); glColor4ub( 255, 255, 255, 255 ); draw_triangle5(1); glPopMatrix(); // unit-cube w/ tri glPushMatrix(); glTranslatef( 150.f, 130.f, -800.f ); glTranslatef( 0.f, 0.f, sinf(rot)*1600.f ); s = 20.f; glScalef( s, s, s ); glRotatef( 90, 1, 0, 0 ); glRotatef( sinf(rotdeg*0.03f)*180.f, 0, 1, 0 ); glColor4ub( 128,128,128,255 ); draw_unitcube(0); glColor4ub( 255,255,255,255 ); draw_unitcube(1); glTranslatef( 0, 1.f, 0.f ); glColor4ub( 128,128,128,255 ); draw_triangle5(0); glColor4ub( 255,255,255,255 ); draw_triangle5(1); glPopMatrix(); // test model //glEnable(GL_LIGHTING); glPushMatrix(); glTranslatef( 300.f, 75.f, 200.f ); glRotatef( 315.f, 0,1,0 ); glEnable(GL_LIGHT0); s = 550.f; glScalef( s, s, s ); glColor4ub( 255,255,255,255); //draw_test_model_Vertex_Arrays(); draw_test_model_VBO(); glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); glColor4ub( 128,128,168,255 ); //draw_test_model_Vertex_Arrays(); draw_test_model_VBO(); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); glPopMatrix(); glDisable(GL_LIGHTING); glDisable(GL_LIGHT0); glFlush(); SDL_GL_SwapBuffers(); }
void glArchivItem_Bitmap_Player::Draw(short dst_x, short dst_y, short dst_w, short dst_h, short src_x, short src_y, short src_w, short src_h, const unsigned int color, const unsigned int player_color) { if(texture == 0) GenerateTexture(); if(texture == 0) return; if(src_w == 0) src_w = width; if(src_h == 0) src_h = height; if(dst_w == 0) dst_w = src_w; if(dst_h == 0) dst_h = src_h; struct GL_T2F_C4UB_V3F_Struct { GLfloat tx, ty; GLubyte r, g, b, a; GLfloat x, y, z; }; GL_T2F_C4UB_V3F_Struct tmp[8]; tmp[0].z = tmp[1].z = tmp[2].z = tmp[3].z = 0.0; int x = -nx + dst_x; int y = -ny + dst_y; tmp[0].x = tmp[1].x = GLfloat(x); tmp[2].x = tmp[3].x = GLfloat(x + dst_w); tmp[0].y = tmp[3].y = GLfloat(y); tmp[1].y = tmp[2].y = GLfloat(y + dst_h); tmp[0].tx = tmp[1].tx = (GLfloat)(src_x) / (GLfloat)tex_width / 2.0f; tmp[2].tx = tmp[3].tx = (GLfloat)(src_x + src_w) / (GLfloat)tex_width / 2.0f; tmp[0].ty = tmp[3].ty = (GLfloat)src_y / tex_height; tmp[1].ty = tmp[2].ty = (GLfloat)(src_y + src_h) / tex_height; tmp[4] = tmp[0]; tmp[5] = tmp[1]; tmp[6] = tmp[2]; tmp[7] = tmp[3]; tmp[4].tx += 0.5; tmp[5].tx += 0.5; tmp[6].tx += 0.5; tmp[7].tx += 0.5; tmp[0].r = tmp[1].r = tmp[2].r = tmp[3].r = GetRed(color); tmp[0].g = tmp[1].g = tmp[2].g = tmp[3].g = GetGreen(color); tmp[0].b = tmp[1].b = tmp[2].b = tmp[3].b = GetBlue(color); tmp[0].a = tmp[1].a = tmp[2].a = tmp[3].a = GetAlpha(color); tmp[4].r = tmp[5].r = tmp[6].r = tmp[7].r = GetRed(player_color); tmp[4].g = tmp[5].g = tmp[6].g = tmp[7].g = GetGreen(player_color); tmp[4].b = tmp[5].b = tmp[6].b = tmp[7].b = GetBlue(player_color); tmp[4].a = tmp[5].a = tmp[6].a = tmp[7].a = GetAlpha(player_color); glInterleavedArrays(GL_T2F_C4UB_V3F, 0, tmp); VideoDriverWrapper::inst().BindTexture(texture); glDrawArrays(GL_QUADS, 0, 8); }
void printDecimalNumbers(float inputValue) { tempInputValue = inputValue; inputValueIsNegative = false; if(inputValue < 10.0f) { twoLeftOfDecimalPoint = 0; } if(tempInputValue < 0.0f) { inputValueIsNegative = true; tempInputValue = tempInputValue * -1.0f; inputValue = inputValue * -1.0f; } if(tempInputValue >= 10.0f) { twoLeftOfDecimalPoint = (int)tempInputValue; twoLeftOfDecimalPoint = twoLeftOfDecimalPoint / 10; } tempValueA = (int)inputValue; leftOfDecimalPoint = tempValueA; if(leftOfDecimalPoint >= 10 && leftOfDecimalPoint < 20) { leftOfDecimalPoint = leftOfDecimalPoint -10; } if(leftOfDecimalPoint >= 20 && leftOfDecimalPoint < 30) { leftOfDecimalPoint = leftOfDecimalPoint -20; } if(leftOfDecimalPoint >= 30 && leftOfDecimalPoint < 40) { leftOfDecimalPoint = leftOfDecimalPoint -30; } if(leftOfDecimalPoint >= 40 && leftOfDecimalPoint < 50) { leftOfDecimalPoint = leftOfDecimalPoint -40; } if(leftOfDecimalPoint >= 50 && leftOfDecimalPoint < 60) { leftOfDecimalPoint = leftOfDecimalPoint -50; } if(leftOfDecimalPoint >= 60 && leftOfDecimalPoint < 70) { leftOfDecimalPoint = leftOfDecimalPoint -60; } if(leftOfDecimalPoint >= 70 && leftOfDecimalPoint < 80) { leftOfDecimalPoint = leftOfDecimalPoint -70; } if(leftOfDecimalPoint >= 80 && leftOfDecimalPoint < 90) { leftOfDecimalPoint = leftOfDecimalPoint -80; } if(leftOfDecimalPoint >= 90 && leftOfDecimalPoint < 100) { leftOfDecimalPoint = leftOfDecimalPoint -90; } tempInputValueB = tempInputValue; inputValue = inputValue - tempValueA; tempInputValueB = tempInputValueB - tempValueA; tempInputValueB = tempInputValueB * 10; inputValue = inputValue * 10; input_01 = (int)inputValue; tempInputValueB = tempInputValueB - input_01; tempInputValue = tempInputValueB * 10; input_02 = (int)tempInputValue; glScalef(.3,.3,.3); if(leftOfDecimalPoint == 0) { glPushMatrix(); glTranslatef(-.13, 0.0f, 0.0f); glInterleavedArrays( GL_V3F, 0, zero_VERT ); glDrawArrays( GL_TRIANGLES, 0, 36); glPopMatrix(); } if(leftOfDecimalPoint == 1) { glPushMatrix(); glTranslatef(-.13f, 0.0f, 0.0f); glInterleavedArrays( GL_V3F, 0, one_VERT ); glDrawArrays( GL_TRIANGLES, 0, 6); glPopMatrix(); } if(twoLeftOfDecimalPoint == 1) { glPushMatrix(); glTranslatef(-.23f, 0.0f, 0.0f); glInterleavedArrays( GL_V3F, 0, one_VERT ); glDrawArrays( GL_TRIANGLES, 0, 6); glPopMatrix(); } if(leftOfDecimalPoint == 2) { glPushMatrix(); glTranslatef(-.13f, 0.0f, 0.0f); glInterleavedArrays( GL_V3F, 0, two_VERT ); glDrawArrays( GL_TRIANGLES, 0, 27); glPopMatrix(); } if(twoLeftOfDecimalPoint == 2) { glPushMatrix(); glTranslatef(-.23f, 0.0f, 0.0f); glInterleavedArrays( GL_V3F, 0, two_VERT ); glDrawArrays( GL_TRIANGLES, 0, 27); glPopMatrix(); } if(leftOfDecimalPoint == 3) { glPushMatrix(); glTranslatef(-.13f, 0.0f, 0.0f); glInterleavedArrays( GL_V3F, 0, three_VERT ); glDrawArrays( GL_TRIANGLES, 0, 51); glPopMatrix(); } if(twoLeftOfDecimalPoint == 3) { glPushMatrix(); glTranslatef(-.23f, 0.0f, 0.0f); glInterleavedArrays( GL_V3F, 0, three_VERT ); glDrawArrays( GL_TRIANGLES, 0, 51); glPopMatrix(); } if(leftOfDecimalPoint == 4) { glPushMatrix(); glTranslatef(-.13f, 0.0f, 0.0f); glInterleavedArrays( GL_V3F, 0, four_VERT ); glDrawArrays( GL_TRIANGLES, 0, 18); glPopMatrix(); } if(twoLeftOfDecimalPoint == 4) { glPushMatrix(); glTranslatef(-.23f, 0.0f, 0.0f); glInterleavedArrays( GL_V3F, 0, four_VERT ); glDrawArrays( GL_TRIANGLES, 0, 18); glPopMatrix(); } if(leftOfDecimalPoint == 5) { glPushMatrix(); glTranslatef(-.13f, 0.0f, 0.0f); glInterleavedArrays( GL_V3F, 0, five_VERT ); glDrawArrays( GL_TRIANGLES, 0, 39); glPopMatrix(); } if(twoLeftOfDecimalPoint == 5) { glPushMatrix(); glTranslatef(-.23f, 0.0f, 0.0f); glInterleavedArrays( GL_V3F, 0, five_VERT ); glDrawArrays( GL_TRIANGLES, 0, 39); glPopMatrix(); } if(leftOfDecimalPoint == 6) { glPushMatrix(); glTranslatef(-.13f, 0.0f, 0.0f); glInterleavedArrays( GL_V3F, 0, six_VERT ); glDrawArrays( GL_TRIANGLES, 0, 69); glPopMatrix(); } if(twoLeftOfDecimalPoint == 6) { glPushMatrix(); glTranslatef(-.23f, 0.0f, 0.0f); glInterleavedArrays( GL_V3F, 0, six_VERT ); glDrawArrays( GL_TRIANGLES, 0, 69); glPopMatrix(); } if(leftOfDecimalPoint == 7) { glPushMatrix(); glTranslatef(-.13f, 0.0f, 0.0f); glInterleavedArrays( GL_V3F, 0, seven_VERT ); glDrawArrays( GL_TRIANGLES, 0, 15); glPopMatrix(); } if(twoLeftOfDecimalPoint == 7) { glPushMatrix(); glTranslatef(-.23f, 0.0f, 0.0f); glInterleavedArrays( GL_V3F, 0, seven_VERT ); glDrawArrays( GL_TRIANGLES, 0, 15); glPopMatrix(); } if(leftOfDecimalPoint == 8) { glPushMatrix(); glTranslatef(-.13f, 0.0f, 0.0f); glInterleavedArrays( GL_V3F, 0, eight_VERT ); glDrawArrays( GL_TRIANGLES, 0, 84); glPopMatrix(); } if(twoLeftOfDecimalPoint == 8) { glPushMatrix(); glTranslatef(-.23f, 0.0f, 0.0f); glInterleavedArrays( GL_V3F, 0, eight_VERT ); glDrawArrays( GL_TRIANGLES, 0, 84); glPopMatrix(); } if(leftOfDecimalPoint == 9) { glPushMatrix(); glTranslatef(-.13f, 0.0f, 0.0f); glInterleavedArrays( GL_V3F, 0, nine_VERT ); glDrawArrays( GL_TRIANGLES, 0, 60); glPopMatrix(); } if(twoLeftOfDecimalPoint == 9) { glPushMatrix(); glTranslatef(-.23f, 0.0f, 0.0f); glInterleavedArrays( GL_V3F, 0, nine_VERT ); glDrawArrays( GL_TRIANGLES, 0, 60); glPopMatrix(); } if(inputValueIsNegative) { glPushMatrix(); glTranslatef(-0.33, 0.0f, 0.0f); glScalef(10.0f, 3.0f, 3.0f); glInterleavedArrays( GL_V3F, 0, decimalPoint_VERT ); glDrawArrays( GL_TRIANGLES, 0, 6); glPopMatrix(); } glPushMatrix(); glTranslatef(-0.07, 0.0f, 0.0f); glScalef(3.0f, 3.0f, 3.0f); glInterleavedArrays( GL_V3F, 0, decimalPoint_VERT ); glDrawArrays( GL_TRIANGLES, 0, 6); glPopMatrix(); if(input_01 == 0) { glPushMatrix(); glTranslatef(numberPosition, 0.0f, 0.0f); glInterleavedArrays( GL_V3F, 0, zero_VERT ); glDrawArrays( GL_TRIANGLES, 0, 36); glPopMatrix(); } if(input_02 == 0) { glPushMatrix(); glTranslatef(numberPosition + pushNumber, 0.0f, 0.0f); glInterleavedArrays( GL_V3F, 0, zero_VERT ); glDrawArrays( GL_TRIANGLES, 0, 36); glPopMatrix(); } //////////////////////////////////////////////////////////////////////////////// if(input_01 == 1) { glPushMatrix(); glTranslatef(numberPosition, 0.0f, 0.0f); glInterleavedArrays( GL_V3F, 0, one_VERT ); glDrawArrays( GL_TRIANGLES, 0, 6); glPopMatrix(); } if(input_02 == 1) { glPushMatrix(); glTranslatef(numberPosition + pushNumber, 0.0f, 0.0f); glInterleavedArrays( GL_V3F, 0, one_VERT ); glDrawArrays( GL_TRIANGLES, 0, 6); glPopMatrix(); } //////////////////////////////////////////////////////////////////////////////// if(input_01 == 2) { glPushMatrix(); glTranslatef(numberPosition, 0.0f, 0.0f); glInterleavedArrays( GL_V3F, 0, two_VERT ); glDrawArrays( GL_TRIANGLES, 0, 27); glPopMatrix(); } if(input_02 == 2) { glPushMatrix(); glTranslatef(numberPosition + pushNumber, 0.0f, 0.0f); glInterleavedArrays( GL_V3F, 0, two_VERT ); glDrawArrays( GL_TRIANGLES, 0, 27); glPopMatrix(); } //////////////////////////////////////////////////////////////////////////////// if(input_01 == 3) { glPushMatrix(); glTranslatef(numberPosition, 0.0f, 0.0f); glInterleavedArrays( GL_V3F, 0, three_VERT ); glDrawArrays( GL_TRIANGLES, 0, 51); glPopMatrix(); } if(input_02 == 3) { glPushMatrix(); glTranslatef(numberPosition + pushNumber, 0.0f, 0.0f); glInterleavedArrays( GL_V3F, 0, three_VERT ); glDrawArrays( GL_TRIANGLES, 0, 51); glPopMatrix(); } //////////////////////////////////////////////////////////////////////////////// if(input_01 == 4) { glPushMatrix(); glTranslatef(numberPosition, 0.0f, 0.0f); glInterleavedArrays( GL_V3F, 0, four_VERT ); glDrawArrays( GL_TRIANGLES, 0, 18); glPopMatrix(); } if(input_02 == 4) { glPushMatrix(); glTranslatef(numberPosition + pushNumber, 0.0f, 0.0f); glInterleavedArrays( GL_V3F, 0, four_VERT ); glDrawArrays( GL_TRIANGLES, 0, 18); glPopMatrix(); } //////////////////////////////////////////////////////////////////////////////// if(input_01 == 5) { glPushMatrix(); glTranslatef(numberPosition, 0.0f, 0.0f); glInterleavedArrays( GL_V3F, 0, five_VERT ); glDrawArrays( GL_TRIANGLES, 0, 39); glPopMatrix(); } if(input_02 == 5) { glPushMatrix(); glTranslatef(numberPosition + pushNumber, 0.0f, 0.0f); glInterleavedArrays( GL_V3F, 0, five_VERT ); glDrawArrays( GL_TRIANGLES, 0, 39); glPopMatrix(); } //////////////////////////////////////////////////////////////////////////////// if(input_01 == 6) { glPushMatrix(); glTranslatef(numberPosition, 0.0f, 0.0f); glInterleavedArrays( GL_V3F, 0, six_VERT ); glDrawArrays( GL_TRIANGLES, 0, 69); glPopMatrix(); } if(input_02 == 6) { glPushMatrix(); glTranslatef(numberPosition + pushNumber, 0.0f, 0.0f); glInterleavedArrays( GL_V3F, 0, six_VERT ); glDrawArrays( GL_TRIANGLES, 0, 69); glPopMatrix(); } //////////////////////////////////////////////////////////////////////////////// if(input_01 == 7) { glPushMatrix(); glTranslatef(numberPosition, 0.0f, 0.0f); glInterleavedArrays( GL_V3F, 0, seven_VERT ); glDrawArrays( GL_TRIANGLES, 0, 15); glPopMatrix(); } if(input_02 == 7) { glPushMatrix(); glTranslatef(numberPosition + pushNumber, 0.0f, 0.0f); glInterleavedArrays( GL_V3F, 0, seven_VERT ); glDrawArrays( GL_TRIANGLES, 0, 15); glPopMatrix(); } //////////////////////////////////////////////////////////////////////////////// if(input_01 == 8) { glPushMatrix(); glTranslatef(numberPosition, 0.0f, 0.0f); glInterleavedArrays( GL_V3F, 0, eight_VERT ); glDrawArrays( GL_TRIANGLES, 0, 84); glPopMatrix(); } if(input_02 == 8) { glPushMatrix(); glTranslatef(numberPosition + pushNumber, 0.0f, 0.0f); glInterleavedArrays( GL_V3F, 0, eight_VERT ); glDrawArrays( GL_TRIANGLES, 0, 84); glPopMatrix(); } //////////////////////////////////////////////////////////////////////////////// if(input_01 == 9) { glPushMatrix(); glTranslatef(numberPosition, 0.0f, 0.0f); glInterleavedArrays( GL_V3F, 0, nine_VERT ); glDrawArrays( GL_TRIANGLES, 0, 60); glPopMatrix(); } if(input_02 == 9) { glPushMatrix(); glTranslatef(numberPosition + pushNumber, 0.0f, 0.0f); glInterleavedArrays( GL_V3F, 0, nine_VERT ); glDrawArrays( GL_TRIANGLES, 0, 60); glPopMatrix(); } }//__close-->> printNumbers(function)
void CMiniMap::Draw() { PROFILE("minimap"); // The terrain isn't actually initialized until the map is loaded, which // happens when the game is started, so abort until then. if(!(GetGUI() && g_Game && g_Game->IsGameStarted())) return; CSimulation2* sim = g_Game->GetSimulation2(); CmpPtr<ICmpRangeManager> cmpRangeManager(*sim, SYSTEM_ENTITY); ENSURE(!cmpRangeManager.null()); // Set our globals in case they hadn't been set before m_Camera = g_Game->GetView()->GetCamera(); m_Terrain = g_Game->GetWorld()->GetTerrain(); m_Width = (u32)(m_CachedActualSize.right - m_CachedActualSize.left); m_Height = (u32)(m_CachedActualSize.bottom - m_CachedActualSize.top); m_MapSize = m_Terrain->GetVerticesPerSide(); m_TextureSize = (GLsizei)round_up_to_pow2((size_t)m_MapSize); m_MapScale = (cmpRangeManager->GetLosCircular() ? 1.f : 1.414f); if(!m_TerrainTexture || g_GameRestarted) CreateTextures(); // only update 2x / second // (note: since units only move a few pixels per second on the minimap, // we can get away with infrequent updates; this is slow) static double last_time; const double cur_time = timer_Time(); if(cur_time - last_time > 0.5) { last_time = cur_time; if(m_TerrainDirty) RebuildTerrainTexture(); } const float x = m_CachedActualSize.left, y = m_CachedActualSize.bottom; const float x2 = m_CachedActualSize.right, y2 = m_CachedActualSize.top; const float z = GetBufferedZ(); const float texCoordMax = (float)(m_MapSize - 1) / (float)m_TextureSize; const float angle = GetAngle(); // Draw the main textured quad g_Renderer.BindTexture(0, m_TerrainTexture); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); DrawTexture(texCoordMax, angle, x, y, x2, y2, z); /* // TODO: reimplement with new sim system // Shade territories by player CTerritoryManager* territoryMgr = g_Game->GetWorld()->GetTerritoryManager(); std::vector<CTerritory*>& territories = territoryMgr->GetTerritories(); PROFILE_START("minimap territory shade"); glDisable(GL_TEXTURE_2D); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); for( size_t i=0; i<territories.size(); i++ ) { if( territories[i]->owner->GetPlayerID() == 0 ) continue; std::vector<CVector2D>& boundary = territories[i]->boundary; SPlayerColour col = territories[i]->owner->GetColour(); glColor4f(col.r, col.g, col.b, 0.25f); glBegin(GL_POLYGON); for( size_t j=0; j<boundary.size(); j++ ) { float fx = boundary[j].x / (m_Terrain->GetTilesPerSide() * CELL_SIZE); float fy = boundary[j].y / (m_Terrain->GetTilesPerSide() * CELL_SIZE); glVertex3f( x*(1-fx) + x2*fx, y*(1-fy) + y2*fy, z ); } glEnd(); } glDisable(GL_BLEND); PROFILE_END("minimap territory shade"); // Draw territory boundaries glEnable(GL_LINE_SMOOTH); glLineWidth(1.0f); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glColor4f(0.8f, 0.8f, 0.8f, 0.8f); for( size_t i=0; i<territories.size(); i++ ) { std::vector<CVector2D>& boundary = territories[i]->boundary; glBegin(GL_LINE_LOOP); for( size_t j=0; j<boundary.size(); j++ ) { float fx = boundary[j].x / (m_Terrain->GetTilesPerSide() * CELL_SIZE); float fy = boundary[j].y / (m_Terrain->GetTilesPerSide() * CELL_SIZE); glVertex3f( x*(1-fx) + x2*fx, y*(1-fy) + y2*fy, z ); } glEnd(); } glLineWidth(1.0f); glDisable(GL_LINE_SMOOTH); glDisable(GL_BLEND); */ // Draw the LOS quad in black, using alpha values from the LOS texture CLOSTexture& losTexture = g_Game->GetView()->GetLOSTexture(); losTexture.BindTexture(0); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE); glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_REPLACE); glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_PRIMARY_COLOR_ARB); glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR); glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_ARB, GL_REPLACE); glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_ARB, GL_TEXTURE); glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA_ARB, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glColor3f(0.0f, 0.0f, 0.0f); glMatrixMode(GL_TEXTURE); glLoadMatrixf(losTexture.GetMinimapTextureMatrix()); glMatrixMode(GL_MODELVIEW); DrawTexture(1.0f, angle, x, y, x2, y2, z); glMatrixMode(GL_TEXTURE); glLoadIdentity(); glMatrixMode(GL_MODELVIEW); glDisable(GL_BLEND); // Set up the matrix for drawing points and lines glPushMatrix(); glTranslatef(x, y, z); // Rotate around the center of the map glTranslatef((x2-x)/2.f, (y2-y)/2.f, 0.f); // Scale square maps to fit in circular minimap area float unitScale = (cmpRangeManager->GetLosCircular() ? 1.f : m_MapScale/2.f); glScalef(unitScale, unitScale, 1.f); glRotatef(angle * 180.f/M_PI, 0.f, 0.f, 1.f); glTranslatef(-(x2-x)/2.f, -(y2-y)/2.f, 0.f); PROFILE_START("minimap units"); // Don't enable GL_POINT_SMOOTH because it's far too slow // (~70msec/frame on a GF4 rendering a thousand points) glPointSize(3.f); float sx = (float)m_Width / ((m_MapSize - 1) * CELL_SIZE); float sy = (float)m_Height / ((m_MapSize - 1) * CELL_SIZE); CSimulation2::InterfaceList ents = sim->GetEntitiesWithInterface(IID_Minimap); std::vector<MinimapUnitVertex> vertexArray; vertexArray.reserve(ents.size()); for (CSimulation2::InterfaceList::const_iterator it = ents.begin(); it != ents.end(); ++it) { MinimapUnitVertex v; ICmpMinimap* cmpMinimap = static_cast<ICmpMinimap*>(it->second); entity_pos_t posX, posZ; if (cmpMinimap->GetRenderData(v.r, v.g, v.b, posX, posZ)) { ICmpRangeManager::ELosVisibility vis = cmpRangeManager->GetLosVisibility(it->first, g_Game->GetPlayerID()); if (vis != ICmpRangeManager::VIS_HIDDEN) { v.a = 255; v.x = posX.ToFloat()*sx; v.y = -posZ.ToFloat()*sy; vertexArray.push_back(v); } } } if (!vertexArray.empty()) { glInterleavedArrays(GL_C4UB_V2F, sizeof(MinimapUnitVertex), &vertexArray[0]); glDrawArrays(GL_POINTS, 0, (GLsizei)vertexArray.size()); glDisableClientState(GL_COLOR_ARRAY); glDisableClientState(GL_VERTEX_ARRAY); } PROFILE_END("minimap units"); DrawViewRect(); glPopMatrix(); // Reset everything back to normal glPointSize(1.0f); glEnable(GL_TEXTURE_2D); }