Example #1
0
void blf_glyph_render(FontBLF *font, GlyphBLF *g, float x, float y)
{
	rctf rect;

	if ((!g->width) || (!g->height))
		return;

	if (g->build_tex == 0) {
		GlyphCacheBLF *gc = font->glyph_cache;

		if (font->max_tex_size == -1)
			glGetIntegerv(GL_MAX_TEXTURE_SIZE, (GLint *)&font->max_tex_size);

		if (gc->cur_tex == BLF_CURTEX_UNSET) {
			blf_glyph_cache_texture(font, gc);
			gc->x_offs = gc->pad;
			gc->y_offs = 0;
		}

		if (gc->x_offs > (gc->p2_width - gc->max_glyph_width)) {
			gc->x_offs = gc->pad;
			gc->y_offs += gc->max_glyph_height;

			if (gc->y_offs > (gc->p2_height - gc->max_glyph_height)) {
				gc->y_offs = 0;
				blf_glyph_cache_texture(font, gc);
			}
		}

		g->tex = gc->textures[gc->cur_tex];
		g->xoff = gc->x_offs;
		g->yoff = gc->y_offs;

		/* prevent glTexSubImage2D from failing if the character
		 * asks for pixels out of bounds, this tends only to happen
		 * with very small sizes (5px high or less) */
		if (UNLIKELY((g->xoff + g->width)  > gc->p2_width)) {
			g->width  -= (g->xoff + g->width)  - gc->p2_width;
			BLI_assert(g->width > 0);
		}
		if (UNLIKELY((g->yoff + g->height) > gc->p2_height)) {
			g->height -= (g->yoff + g->height) - gc->p2_height;
			BLI_assert(g->height > 0);
		}


		glPushClientAttrib(GL_CLIENT_PIXEL_STORE_BIT);
		glPixelStorei(GL_UNPACK_LSB_FIRST, GL_FALSE);
		glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
		glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

		glBindTexture(GL_TEXTURE_2D, g->tex);
		glTexSubImage2D(GL_TEXTURE_2D, 0, g->xoff, g->yoff, g->width, g->height, GL_ALPHA, GL_UNSIGNED_BYTE, g->bitmap);
		glPopClientAttrib();

		g->uv[0][0] = ((float)g->xoff) / ((float)gc->p2_width);
		g->uv[0][1] = ((float)g->yoff) / ((float)gc->p2_height);
		g->uv[1][0] = ((float)(g->xoff + g->width)) / ((float)gc->p2_width);
		g->uv[1][1] = ((float)(g->yoff + g->height)) / ((float)gc->p2_height);

		/* update the x offset for the next glyph. */
		gc->x_offs += (int)BLI_rctf_size_x(&g->box) + gc->pad;

		gc->rem_glyphs--;
		g->build_tex = 1;
	}

	blf_glyph_calc_rect(&rect, g, x, y);

	if (font->flags & BLF_CLIPPING) {
		/* intentionally check clipping without shadow offset */
		rctf rect_test = rect;
		BLI_rctf_translate(&rect_test, font->pos[0], font->pos[1]);

		if (!BLI_rctf_inside_rctf(&font->clip_rec, &rect_test)) {
			return;
		}
	}

	if (font->tex_bind_state != g->tex) {
		glBindTexture(GL_TEXTURE_2D, (font->tex_bind_state = g->tex));
	}

	if (font->flags & BLF_SHADOW) {
		rctf rect_ofs;
		blf_glyph_calc_rect(&rect_ofs, g,
		                    x + (float)font->shadow_x,
		                    y + (float)font->shadow_y);

		switch (font->shadow) {
			case 3:
				blf_texture3_draw(font->shadow_col, g->uv, rect_ofs.xmin, rect_ofs.ymin, rect_ofs.xmax, rect_ofs.ymax);
				break;
			case 5:
				blf_texture5_draw(font->shadow_col, g->uv, rect_ofs.xmin, rect_ofs.ymin, rect_ofs.xmax, rect_ofs.ymax);
				break;
			default:
				glColor4fv(font->shadow_col);
				blf_texture_draw(g->uv, rect_ofs.xmin, rect_ofs.ymin, rect_ofs.xmax, rect_ofs.ymax);
				break;
		}

		glColor4fv(font->orig_col);
	}

	switch (font->blur) {
		case 3:
			blf_texture3_draw(font->orig_col, g->uv, rect.xmin, rect.ymin, rect.xmax, rect.ymax);
			break;
		case 5:
			blf_texture5_draw(font->orig_col, g->uv, rect.xmin, rect.ymin, rect.xmax, rect.ymax);
			break;
		default:
			blf_texture_draw(g->uv, rect.xmin, rect.ymin, rect.xmax, rect.ymax);
			break;
	}

	return;
}
// This function comes from the code of Songho's works:
//    http://www.songho.ca/opengl/gl_transform.html#modelview
// I use this as debug helper functions that help me better understand
// about the OpenGL frustum works.
// It should not be used in the assignment
void Frustum::DrawFrustum(float fovY, float aspectRatio, float nearPlane, float farPlane){
  float tangent = tanf(fovY/2 * 3.141593f / 180.0);
  float nearHeight = nearPlane * tangent;
  float nearWidth = nearHeight * aspectRatio;
  float farHeight = farPlane * tangent;
  float farWidth = farHeight * aspectRatio;
  
  // compute 8 vertices of the frustum
  float vertices[8][3];
  // near top right
  vertices[0][0] = nearWidth;     vertices[0][1] = nearHeight;    vertices[0][2] = -nearPlane;
  // near top left
  vertices[1][0] = -nearWidth;    vertices[1][1] = nearHeight;    vertices[1][2] = -nearPlane;
  // near bottom left
  vertices[2][0] = -nearWidth;    vertices[2][1] = -nearHeight;   vertices[2][2] = -nearPlane;
  // near bottom right
  vertices[3][0] = nearWidth;     vertices[3][1] = -nearHeight;   vertices[3][2] = -nearPlane;
  // far top right
  vertices[4][0] = farWidth;      vertices[4][1] = farHeight;     vertices[4][2] = -farPlane;
  // far top left
  vertices[5][0] = -farWidth;     vertices[5][1] = farHeight;     vertices[5][2] = -farPlane;
  // far bottom left
  vertices[6][0] = -farWidth;     vertices[6][1] = -farHeight;    vertices[6][2] = -farPlane;
  // far bottom right
  vertices[7][0] = farWidth;      vertices[7][1] = -farHeight;    vertices[7][2] = -farPlane;
  
  float colorLine1[4] = { 0.7f, 0.7f, 0.7f, 0.7f };
  float colorLine2[4] = { 0.2f, 0.2f, 0.2f, 0.7f };
  float colorPlane[4] = { 0.5f, 0.5f, 0.5f, 0.5f };
  
  glDisable(GL_LIGHTING);
  glDisable(GL_CULL_FACE);
  glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  
  // draw the edges around frustum
  glBegin(GL_LINES);
  glColor4fv(colorLine2);
  glVertex3f(0, 0, 0);
  glColor4fv(colorLine1);
  glVertex3fv(vertices[4]);
  
  glColor4fv(colorLine2);
  glVertex3f(0, 0, 0);
  glColor4fv(colorLine1);
  glVertex3fv(vertices[5]);
  
  glColor4fv(colorLine2);
  glVertex3f(0, 0, 0);
  glColor4fv(colorLine1);
  glVertex3fv(vertices[6]);
  
  glColor4fv(colorLine2);
  glVertex3f(0, 0, 0);
  glColor4fv(colorLine1);
  glVertex3fv(vertices[7]);
  glEnd();
  
  glColor4fv(colorLine1);
  glBegin(GL_LINE_LOOP);
  glVertex3fv(vertices[4]);
  glVertex3fv(vertices[5]);
  glVertex3fv(vertices[6]);
  glVertex3fv(vertices[7]);
  glEnd();
  
  glColor4fv(colorLine1);
  glBegin(GL_LINE_LOOP);
  glVertex3fv(vertices[0]);
  glVertex3fv(vertices[1]);
  glVertex3fv(vertices[2]);
  glVertex3fv(vertices[3]);
  glEnd();
  
  // draw near and far plane
  glColor4fv(colorPlane);
  glBegin(GL_QUADS);
  glVertex3fv(vertices[0]);
  glVertex3fv(vertices[1]);
  glVertex3fv(vertices[2]);
  glVertex3fv(vertices[3]);
  glVertex3fv(vertices[4]);
  glVertex3fv(vertices[5]);
  glVertex3fv(vertices[6]);
  glVertex3fv(vertices[7]);
  glEnd();
  
  glEnable(GL_CULL_FACE);
  glEnable(GL_LIGHTING);
}
Example #3
0
void ssgVtxTableSmoke::draw_geometry ()
{
	int num_colours = getNumColours();
	int num_normals = getNumNormals();
	float alpha;
	GLfloat modelView[16];
	sgVec3 A, B, C, D;
	sgVec3 right, up, offset;

	sgVec3 *vx = (sgVec3 *) vertices->get(0);
	sgVec3 *nm = (sgVec3 *) normals->get(0);
    sgVec4 *cl = (sgVec4 *) colours->get(0);
	alpha =  0.9f - ((float)(cur_life/max_life));
	glDepthMask(GL_FALSE);
	glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

	/*glPolygonOffset(-5.0f, +10.0f);*/
	/*glEnable(GL_POLYGON_OFFSET_FILL);*/

	// the principle is to have a right and up vector
	// to determine how the points of the quadri should be placed
	// orthogonaly to the view, parallel to the screen.

	/* get the matrix */
	// TODO: replace that, glGet stalls rendering pipeline (forces flush).
	glGetFloatv(GL_MODELVIEW_MATRIX, modelView);

	// get the up and right vector from the matrice view

	offset[0] = offset[1] = offset[2] = 0.0f;

	int i;
	for (i = 0; i < 3; i++) {
		int j = i;
		int k;
		for (k = 0; k < 4; k++, j+=4) {
			if (k != 3) {
				offset[i] += modelView[j] * vx[0][k];
			} else {
				offset[i] += modelView[j];
			}
		}
	}
	//printf ("%f %f %f\n", offset[0], offset[1], offset[2]);

	tdble dist = sqrt(offset[0]*offset[0]
		+ offset[1]*offset[1]
		+ offset[2]*offset[2]);

	up[0] = modelView[1];
	up[1] = modelView[5];
	up[2] = modelView[9];

	right[0] = modelView[0];
	right[1] = modelView[4];
	right[2] = modelView[8];

	// compute the coordinates of the four points of the quadri.

	// up and right points
	C[0] = right[0]+up[0];
	C[1] = right[1]+up[1];
	C[2] = right[2]+up[2];

	// left and up
	D[0] = -right[0]+up[0];
	D[1] = -right[1]+up[1];
	D[2] = -right[2]+up[2];

	// down and left
	A[0] = -right[0]-up[0];
	A[1] = -right[1]-up[1];
	A[2] = -right[2]-up[2];

	// right and down
	B[0] = right[0]-up[0];
	B[1] = right[1]-up[1];
	B[2] = right[2]-up[2];

	glBegin ( gltype ) ;

	if (dist < 50.0f) {
		alpha *= (1.0f - exp(-0.1f * dist));
	}

	glColor4f(cur_col[0],cur_col[1],cur_col[2],alpha);
	if (num_colours == 1) {
		glColor4fv(cl[0]);
	}
	if (num_normals == 1) {
		glNormal3fv(nm[0]);
	}

	// the computed coordinates are translated from the smoke position with the x, y, z speed
	glTexCoord2f(0,0);
	glVertex3f(vx[0][0]+sizex*A[0],vx[0][1]+sizey*A[1], vx[0][2]+sizez*A[2]);
	glTexCoord2f(0,1);
	glVertex3f(vx[0][0]+sizex*B[0],vx[0][1]+sizey*B[1], vx[0][2]+sizez*B[2]);
	glTexCoord2f(1,0);
	glVertex3f(vx[0][0]+sizex*D[0],vx[0][1]+sizey*D[1], vx[0][2]+sizez*D[2]);
	glTexCoord2f(1,1);
	glVertex3f(vx[0][0]+sizex*C[0],vx[0][1]+sizey*C[1], vx[0][2]+sizez*C[2]);
	glEnd();

	glDisable(GL_POLYGON_OFFSET_FILL);
	glDepthMask(GL_TRUE);
	glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MODULATE);
}
Example #4
0
static void
drawfire(void)
{
   static char frbuf[80] = "";
   int j;
   static double t0 = -1.;
   double t = glutGet(GLUT_ELAPSED_TIME) / 1000.0;
   if (t0 < 0.0)
      t0 = t;
   dt = (t - t0) * 1.0;
   t0 = t;

   dojoy();

   if (NiceFog)
      glHint(GL_FOG_HINT, GL_NICEST);
   else
      glHint(GL_FOG_HINT, GL_DONT_CARE);

   glEnable(GL_DEPTH_TEST);

   if (fog)
      glEnable(GL_FOG);
   else
      glDisable(GL_FOG);

   glDepthMask(GL_TRUE);
   glClearColor(1.0, 1.0, 1.0, 1.0);
   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

   glPushMatrix();
   calcposobs();
   gluLookAt(obs[0], obs[1], obs[2],
	     obs[0] + dir[0], obs[1] + dir[1], obs[2] + dir[2],
	     0.0, 1.0, 0.0);

   glColor4f(1.0, 1.0, 1.0, 1.0);

   glEnable(GL_TEXTURE_2D);

   glBindTexture(GL_TEXTURE_2D, groundid);
#if 1
   glBegin(GL_QUADS);
   glTexCoord2fv(qt[0]);
   glVertex3fv(q[0]);
   glTexCoord2fv(qt[1]);
   glVertex3fv(q[1]);
   glTexCoord2fv(qt[2]);
   glVertex3fv(q[2]);
   glTexCoord2fv(qt[3]);
   glVertex3fv(q[3]);
   glEnd();
#else
   /* Subdivide the ground into a bunch of quads.  This improves fog
    * if GL_FOG_HINT != GL_NICEST
    */
   {
      float x, y;
      float dx = 1.0, dy = 1.0;
      glBegin(GL_QUADS);
      for (y = -DIMP; y < DIMP; y += 1.0) {
         for (x = -DIMP; x < DIMP; x += 1.0) {
            glTexCoord2f(0, 0);   glVertex3f(x, 0, y);
            glTexCoord2f(1, 0);   glVertex3f(x+dx, 0, y);
            glTexCoord2f(1, 1);   glVertex3f(x+dx, 0, y+dy);
            glTexCoord2f(0, 1);   glVertex3f(x, 0, y+dy);
         }
      }
      glEnd();
   }
#endif


   glEnable(GL_ALPHA_TEST);
   glAlphaFunc(GL_GEQUAL, 0.9);

   glBindTexture(GL_TEXTURE_2D, treeid);
   for (j = 0; j < NUMTREE; j++)
      drawtree(treepos[j][0], treepos[j][1], treepos[j][2]);

   glDisable(GL_TEXTURE_2D);
   glDepthMask(GL_FALSE);
   glDisable(GL_ALPHA_TEST);

   if (shadows) {
      glBegin(GL_TRIANGLES);
      for (j = 0; j < np; j++) {
	 glColor4f(black[0], black[1], black[2], p[j].c[0][3]);
	 glVertex3f(p[j].p[0][0], 0.1, p[j].p[0][2]);

	 glColor4f(black[0], black[1], black[2], p[j].c[1][3]);
	 glVertex3f(p[j].p[1][0], 0.1, p[j].p[1][2]);

	 glColor4f(black[0], black[1], black[2], p[j].c[2][3]);
	 glVertex3f(p[j].p[2][0], 0.1, p[j].p[2][2]);
      }
      glEnd();
   }

   glBegin(GL_TRIANGLES);
   for (j = 0; j < np; j++) {
      glColor4fv(p[j].c[0]);
      glVertex3fv(p[j].p[0]);

      glColor4fv(p[j].c[1]);
      glVertex3fv(p[j].p[1]);

      glColor4fv(p[j].c[2]);
      glVertex3fv(p[j].p[2]);

      setpart(&p[j]);
   }
   glEnd();

   glDisable(GL_TEXTURE_2D);
   glDisable(GL_ALPHA_TEST);
   glDisable(GL_DEPTH_TEST);
   glDisable(GL_FOG);

   glMatrixMode(GL_PROJECTION);
   glLoadIdentity();
   glOrtho(-0.5, 639.5, -0.5, 479.5, -1.0, 1.0);
   glMatrixMode(GL_MODELVIEW);
   glLoadIdentity();

   glColor3f(1.0, 0.0, 0.0);
   glRasterPos2i(10, 10);
   printstring(GLUT_BITMAP_HELVETICA_18, frbuf);
   glRasterPos2i(370, 470);
   printstring(GLUT_BITMAP_HELVETICA_10,
	       "Fire V1.5 Written by David Bucciarelli ([email protected])");

   if (help)
      printhelp();

   reshape(WIDTH, HEIGHT);
   glPopMatrix();

   glutSwapBuffers();

   Frames++;
   {
      GLint t = glutGet(GLUT_ELAPSED_TIME);
      if (t - T0 >= 2000) {
         GLfloat seconds = (t - T0) / 1000.0;
         GLfloat fps = Frames / seconds;
         sprintf(frbuf, "Frame rate: %f", fps);
         printf("%s\n", frbuf);
         fflush(stdout);
         T0 = t;
         Frames = 0;
      }
   }
}
void CSelectedUnitsHandler::Draw()
{
	glDisable(GL_TEXTURE_2D);
	glDepthMask(false);
	glDisable(GL_DEPTH_TEST);
	glEnable(GL_BLEND); // for line smoothing
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
	glLineWidth(cmdColors.UnitBoxLineWidth());

	SColor color1(cmdColors.unitBox);
	SColor color2(cmdColors.unitBox);
	color2.r = 255 - color2.r;
	color2.g = 255 - color2.g;
	color2.b = 255 - color2.b;

	if (color1.a > 0) {
		const CUnitSet* unitSet;
		if (selectedGroup != -1) {
			// note: units in this set are not necessarily all selected themselves, eg.
			// if autoAddBuiltUnitsToSelectedGroup is true, so we check IsUnitSelected
			// for each
			unitSet = &grouphandlers[gu->myTeam]->groups[selectedGroup]->units;
		} else {
			unitSet = &selectedUnits;
		}

		CVertexArray* va = GetVertexArray();
		va->Initialize();
		va->EnlargeArrays(unitSet->size() * 8, 0, VA_SIZE_C);

		for (CUnitSet::const_iterator ui = unitSet->begin(); ui != unitSet->end(); ++ui) {
			const CUnit* unit = *ui;
			const MoveDef* moveDef = unit->moveDef;

			if (unit->isIcon) continue;
			if (!IsUnitSelected(unit)) continue;

			const int
				uhxsize = (unit->xsize * SQUARE_SIZE) >> 1,
				uhzsize = (unit->zsize * SQUARE_SIZE) >> 1,
				mhxsize = (moveDef == NULL)? uhxsize: ((moveDef->xsize * SQUARE_SIZE) >> 1),
				mhzsize = (moveDef == NULL)? uhzsize: ((moveDef->zsize * SQUARE_SIZE) >> 1);
			const float3 verts[8] = {
				// UnitDef footprint corners
				float3(unit->drawPos.x + uhxsize, unit->drawPos.y, unit->drawPos.z + uhzsize),
				float3(unit->drawPos.x - uhxsize, unit->drawPos.y, unit->drawPos.z + uhzsize),
				float3(unit->drawPos.x - uhxsize, unit->drawPos.y, unit->drawPos.z - uhzsize),
				float3(unit->drawPos.x + uhxsize, unit->drawPos.y, unit->drawPos.z - uhzsize),
				// MoveDef footprint corners
				float3(unit->drawPos.x + mhxsize, unit->drawPos.y, unit->drawPos.z + mhzsize),
				float3(unit->drawPos.x - mhxsize, unit->drawPos.y, unit->drawPos.z + mhzsize),
				float3(unit->drawPos.x - mhxsize, unit->drawPos.y, unit->drawPos.z - mhzsize),
				float3(unit->drawPos.x + mhxsize, unit->drawPos.y, unit->drawPos.z - mhzsize),
			};

			va->AddVertexQC(verts[0], color1);
			va->AddVertexQC(verts[1], color1);
			va->AddVertexQC(verts[2], color1);
			va->AddVertexQC(verts[3], color1);

			if (globalRendering->drawdebug && (mhxsize != uhxsize || mhzsize != uhzsize)) {
				va->AddVertexQC(verts[4], color2);
				va->AddVertexQC(verts[5], color2);
				va->AddVertexQC(verts[6], color2);
				va->AddVertexQC(verts[7], color2);
			}
		}

		va->DrawArrayC(GL_QUADS);
	}

	// highlight queued build sites if we are about to build something
	// (or old-style, whenever the shift key is being held down)
	if (cmdColors.buildBox[3] > 0.0f) {
		if (!selectedUnits.empty() &&
				((cmdColors.BuildBoxesOnShift() && KeyInput::GetKeyModState(KMOD_SHIFT)) ||
				 ((guihandler->inCommand >= 0) &&
					(guihandler->inCommand < int(guihandler->commands.size())) &&
					(guihandler->commands[guihandler->inCommand].id < 0)))) {

			bool myColor = true;
			glColor4fv(cmdColors.buildBox);

			for (const auto bi: unitHandler->GetBuilderCAIs()) {
				const CBuilderCAI* builderCAI = bi.second;
				const CUnit* builder = builderCAI->owner;

				if (builder->team == gu->myTeam) {
					if (!myColor) {
						glColor4fv(cmdColors.buildBox);
						myColor = true;
					}
					commandDrawer->DrawQuedBuildingSquares(builderCAI);
				}
				else if (teamHandler->AlliedTeams(builder->team, gu->myTeam)) {
					if (myColor) {
						glColor4fv(cmdColors.allyBuildBox);
						myColor = false;
					}
					commandDrawer->DrawQuedBuildingSquares(builderCAI);
				}
			}
		}
	}

	glLineWidth(1.0f);
	glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
	glDisable(GL_BLEND);
	glEnable(GL_DEPTH_TEST);
	glDepthMask(true);
	glEnable(GL_TEXTURE_2D);
}
Example #6
0
static int
create_cube_fbo(void)
{
	GLuint tex, fb;
	GLenum status;
	int face, dim;

	glGenTextures(1, &tex);
	glBindTexture(GL_TEXTURE_CUBE_MAP, tex);

	for (face = 0; face < 6; face++) {
		int level = 0;

		for (dim = BUF_WIDTH; dim > 0; dim /= 2) {
			glTexImage2D(cube_face_targets[face], level, GL_RGBA,
				     dim, dim,
				     0,
				     GL_RGBA, GL_UNSIGNED_BYTE, NULL);
			level++;
		}
	}
	if (!piglit_check_gl_error(GL_NO_ERROR))
		piglit_report_result(PIGLIT_FAIL);

	glGenFramebuffersEXT(1, &fb);
	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb);

	for (face = 0; face < 6; face++) {
		int level = 0;

		for (dim = BUF_WIDTH; dim > 0; dim /= 2) {
			glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT,
						  GL_COLOR_ATTACHMENT0_EXT,
						  cube_face_targets[face],
						  tex,
						  level);

			if (!piglit_check_gl_error(GL_NO_ERROR))
				piglit_report_result(PIGLIT_FAIL);

			status = glCheckFramebufferStatusEXT (GL_FRAMEBUFFER_EXT);
			if (status != GL_FRAMEBUFFER_COMPLETE_EXT) {
				fprintf(stderr, "FBO incomplete\n");
				goto done;
			}

			glViewport(0, 0, dim, dim);
			piglit_ortho_projection(dim, dim, GL_FALSE);

			glColor4fv(get_face_color(face, level));
			/* Draw a little outside the bounds to make
			 * sure clipping's working.
			 */
			piglit_draw_rect(-2, -2, dim + 2, dim + 2);

			level++;
		}
	}


done:
	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, piglit_winsys_fbo);
	glDeleteFramebuffersEXT(1, &fb);

	return tex;
}
Example #7
0
  //draw axis
  void GlWidget::drawAxis()

  {
      GLdouble dAxisLength=1.0;
      GLdouble  dAxisRadius=0.05;
      GLdouble  dArrowLength=0.1;
      GLdouble  dArrowRadius=0.1;
      float     fScale=0.1;
      GLint     iSlices=32;
      GLint     iStacks=32;
      GLfloat   fColorX[4]={1.0,0.0,0.0,1.0};
      GLfloat   fColorY[4]={0.0,1.0,0.0,1.0};
      GLfloat   fColorZ[4]={0.0,0.0,1.0,1.0};
      bool      bSolid=true;
      bool      bBlend=true;
      GLdouble dArrowPosn = dAxisLength;// - (dArrowLength/2);
      GLfloat fCurrentColor[4];

      // Get the current color
      glGetFloatv(GL_CURRENT_COLOR, fCurrentColor);

      // Save the current transformation matrix..
      glPushMatrix();

      // Create a quadratic object used to draw our axis
      // cylinders and cones
      GLUquadricObj* pQuadric = gluNewQuadric();
      if(!pQuadric)
          return;

      // Set the quadric state
      gluQuadricNormals(pQuadric, GLU_SMOOTH);
      gluQuadricTexture(pQuadric, GL_FALSE);

      if(bSolid)
      {
          glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
          gluQuadricDrawStyle(pQuadric, GLU_FILL);
      }
      else
      {
          glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
          gluQuadricDrawStyle(pQuadric, GLU_LINE);
      }

      // Enable alpha blending?
      if(bBlend)
      {
          glEnable(GL_BLEND);
          glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
      }

      // Display a Sphere at the axis origin
      glColor4f(0.5f, 0.5f, 0.5f, 1.0f);
      gluSphere(pQuadric, dAxisRadius*fScale*2.5f, iSlices, iStacks);

      // Display the Z-Axis and arrow
      // Set the color
      glColor4fv(fColorZ);

      gluCylinder(pQuadric, dAxisRadius*fScale, dAxisRadius*fScale, dAxisLength*fScale, iSlices, iStacks);
      glTranslated(0.0f, 0.0f, dArrowPosn*fScale);    // Move to arrow position
      gluCylinder(pQuadric, dArrowRadius*fScale, 0.0f, dArrowLength*fScale, iSlices, iStacks);
      gluQuadricOrientation(pQuadric, GLU_INSIDE);
      gluDisk(pQuadric, 0.0f, dArrowRadius*fScale, iSlices, 1);
      gluQuadricOrientation(pQuadric, GLU_OUTSIDE);
      glTranslated(0.0f, 0.0f, -dArrowPosn*fScale);   // Move to 0, 0, 0


      // Display the X-Axis and arrow
      // Set the color
      glColor4fv(fColorX);

      glRotated(90, 0.0, 1.0, 0.0);                   // Rotate for X
      gluCylinder(pQuadric, dAxisRadius*fScale, dAxisRadius*fScale, dAxisLength*fScale, iSlices, iStacks);
      glTranslated(0.0f, 0.0f, dArrowPosn*fScale);    // Move to arrow position
      gluCylinder(pQuadric, dArrowRadius*fScale, 0.0f, dArrowLength*fScale, iSlices, iStacks);
      gluQuadricOrientation(pQuadric, GLU_INSIDE);
      gluDisk(pQuadric, 0.0f, dArrowRadius*fScale, iSlices, 1);
      gluQuadricOrientation(pQuadric, GLU_OUTSIDE);
      glTranslated(0.0f, 0.0f, -dArrowPosn*fScale);   // Move to 0, 0, 0


      // Display the Y-Axis and arrow
      // Set the color
      glColor4fv(fColorY);

      glRotated(-90, 1.0, 0.0, 0.0);                  // Rotate for Y
      gluCylinder(pQuadric, dAxisRadius*fScale, dAxisRadius*fScale, dAxisLength*fScale, iSlices, iStacks);
      glTranslated(0.0f, 0.0f, dArrowPosn*fScale);    // Move to arrow position
      gluCylinder(pQuadric, dArrowRadius*fScale, 0.0f, dArrowLength*fScale, iSlices, iStacks);
      gluQuadricOrientation(pQuadric, GLU_INSIDE);
      gluDisk(pQuadric, 0.0f, dArrowRadius*fScale, iSlices, 1);
      gluQuadricOrientation(pQuadric, GLU_OUTSIDE);
      glTranslated(0.0f, 0.0f, -dArrowPosn*fScale);   // Move to 0, 0, 0


      // Delete the quadric
      gluDeleteQuadric(pQuadric);

      // Restore the current transformation matrix..
      glPopMatrix();

      // Restore the current color
      glColor4fv(fCurrentColor);

      // Disable blend function
      glDisable(GL_BLEND);
  }
Example #8
0
/**
 * Common code for framebuffer and FBO tests.
 */
static GLboolean
test_srgb(void)
{
	GLboolean pass = GL_TRUE;
	GLboolean srgb_capable;
	float green[] = {0, 0.3, 0, 0};
	float expected_green[4];
	float expected_blend[4];

	/*
	 * Note: the window-system framebuffer may or may not be sRGB capable.
	 * But the user-created FBO should be sRGB capable.
	 */
	glGetBooleanv(GL_FRAMEBUFFER_SRGB_CAPABLE_EXT, &srgb_capable);

	glDisable(GL_BLEND);
	glClear(GL_COLOR_BUFFER_BIT);
	glDisable(GL_FRAMEBUFFER_SRGB_EXT);
	glColor4fv(green);

	/*
	 * First square: draw green square without sRGB and no blending
	 */
	piglit_draw_rect(0, 0, 20, 20);

	/*
	 * Second square: draw a green square with sRGB enabled and no blending
	 */
	glEnable(GL_FRAMEBUFFER_SRGB_EXT);
	piglit_draw_rect(20, 0, 20, 20);

	/*
	 * Third square: draw green square, then blend/add another on top of it
	 */
	glEnable(GL_FRAMEBUFFER_SRGB_EXT);
	piglit_draw_rect(40, 0, 20, 20);
	glEnable(GL_BLEND);
	glBlendFunc(GL_ONE, GL_ONE);
	piglit_draw_rect(40, 0, 20, 20);
	glDisable(GL_BLEND);
	glDisable(GL_FRAMEBUFFER_SRGB_EXT);

	/*
	 * Check first square.
	 */
	if (!piglit_probe_rect_rgb(0, 0, 20, 20, green))
		pass = GL_FALSE;
	/* check pixel path */
	glEnable(GL_FRAMEBUFFER_SRGB_EXT);
	if (!piglit_probe_rect_rgb(0, 0, 20, 20, green))
		pass = GL_FALSE;
	glDisable(GL_FRAMEBUFFER_SRGB_EXT);

	/*
	 * Check second square
	 */
	memcpy(expected_green, green, sizeof(float) * 4);
	if (srgb_capable)
		expected_green[1] = piglit_linear_to_srgb(green[1]);
	if (!piglit_probe_rect_rgb(20, 0, 20, 20, expected_green))
		pass = GL_FALSE;
	/* check it doesn't affect the pixel path */
	glEnable(GL_FRAMEBUFFER_SRGB_EXT);
	if (!piglit_probe_rect_rgb(20, 0, 20, 20, expected_green))
		pass = GL_FALSE;
	glDisable(GL_FRAMEBUFFER_SRGB_EXT);

	/*
	 * Check third square
	 */
	memcpy(expected_blend, green, sizeof(float) * 4);
	if (srgb_capable)
		expected_blend[1] = piglit_linear_to_srgb(green[1] * 2.0);
	else
		expected_blend[1] = green[1] * 2.0;
	if (!piglit_probe_rect_rgb(40, 0, 20, 20, expected_blend))
		pass = GL_FALSE;

	return pass;
}
Example #9
0
/*
=============
GL_DrawAliasFrame -- johnfitz -- rewritten to support colored light, lerping, entalpha, multitexture, and r_drawflat
=============
*/
void GL_DrawAliasFrame (aliashdr_t *paliashdr, lerpdata_t lerpdata)
{
	float	vertcolor[4];
	trivertx_t *verts1, *verts2;
	int		*commands;
	int		count;
	float	u,v;
	float	blend, iblend;
	qboolean lerping;

	if (lerpdata.pose1 != lerpdata.pose2)
	{
		lerping = true;
		verts1  = (trivertx_t *)((byte *)paliashdr + paliashdr->posedata);
		verts2  = verts1;
		verts1 += lerpdata.pose1 * paliashdr->poseverts;
		verts2 += lerpdata.pose2 * paliashdr->poseverts;
		blend = lerpdata.blend;
		iblend = 1.0f - blend;
	}
	else // poses the same means either 1. the entity has paused its animation, or 2. r_lerpmodels is disabled
	{
		lerping = false;
		verts1  = (trivertx_t *)((byte *)paliashdr + paliashdr->posedata);
		verts2  = verts1; // avoid bogus compiler warning
		verts1 += lerpdata.pose1 * paliashdr->poseverts;
		blend = iblend = 0; // avoid bogus compiler warning
	}

	commands = (int *)((byte *)paliashdr + paliashdr->commands);

	vertcolor[3] = entalpha; //never changes, so there's no need to put this inside the loop

	while (1)
	{
		// get the vertex count and primitive type
		count = *commands++;
		if (!count)
			break;		// done

		if (count < 0)
		{
			count = -count;
			glBegin (GL_TRIANGLE_FAN);
		}
		else
			glBegin (GL_TRIANGLE_STRIP);

		do
		{
			u = ((float *)commands)[0];
			v = ((float *)commands)[1];
			if (mtexenabled)
			{
				GL_MTexCoord2fFunc (TEXTURE0, u, v);
				GL_MTexCoord2fFunc (TEXTURE1, u, v);
			}
			else
				glTexCoord2f (u, v);

			commands += 2;

			if (shading)
			{
				if (r_drawflat_cheatsafe)
				{
					srand(count * (unsigned int)(src_offset_t)commands);
					glColor3f (rand()%256/255.0, rand()%256/255.0, rand()%256/255.0);
				}
				else if (lerping)
				{
					vertcolor[0] = (shadedots[verts1->lightnormalindex]*iblend + shadedots[verts2->lightnormalindex]*blend) * lightcolor[0];
					vertcolor[1] = (shadedots[verts1->lightnormalindex]*iblend + shadedots[verts2->lightnormalindex]*blend) * lightcolor[1];
					vertcolor[2] = (shadedots[verts1->lightnormalindex]*iblend + shadedots[verts2->lightnormalindex]*blend) * lightcolor[2];
					glColor4fv (vertcolor);
				}
				else
				{
					vertcolor[0] = shadedots[verts1->lightnormalindex] * lightcolor[0];
					vertcolor[1] = shadedots[verts1->lightnormalindex] * lightcolor[1];
					vertcolor[2] = shadedots[verts1->lightnormalindex] * lightcolor[2];
					glColor4fv (vertcolor);
				}
			}

			if (lerping)
			{
				glVertex3f (verts1->v[0]*iblend + verts2->v[0]*blend,
							verts1->v[1]*iblend + verts2->v[1]*blend,
							verts1->v[2]*iblend + verts2->v[2]*blend);
				verts1++;
				verts2++;
			}
			else
			{
				glVertex3f (verts1->v[0], verts1->v[1], verts1->v[2]);
				verts1++;
			}
		} while (--count);

		glEnd ();
	}

	rs_aliaspasses += paliashdr->numtris;
}
void CFactoryCAI::DrawCommands(void)
{
	lineDrawer.StartPath(owner->midPos, cmdColors.start);

	if (owner->selfDCountdown != 0) {
		lineDrawer.DrawIconAtLastPos(CMD_SELFD);
	}

	if (!commandQue.empty() && (commandQue.front().id == CMD_WAIT)) {
		DrawWaitIcon(commandQue.front());
	}

	CCommandQueue::iterator ci;
	for(ci=newUnitCommands.begin();ci!=newUnitCommands.end();++ci){
		switch(ci->id){
			case CMD_MOVE:{
				const float3 endPos(ci->params[0],ci->params[1]+3,ci->params[2]);
				lineDrawer.DrawLineAndIcon(ci->id, endPos, cmdColors.move);
				break;
			}
			case CMD_FIGHT:{
				const float3 endPos(ci->params[0],ci->params[1]+3,ci->params[2]);
				lineDrawer.DrawLineAndIcon(ci->id, endPos, cmdColors.fight);
				break;
			}
			case CMD_PATROL:{
				const float3 endPos(ci->params[0],ci->params[1]+3,ci->params[2]);
				lineDrawer.DrawLineAndIcon(ci->id, endPos, cmdColors.patrol);
				break;
			}
			case CMD_ATTACK:{
				if(ci->params.size()==1){
					const CUnit* unit = uh->units[int(ci->params[0])];
					if((unit != NULL) && isTrackable(unit)) {
						const float3 endPos =
							helper->GetUnitErrorPos(unit, owner->allyteam);
						lineDrawer.DrawLineAndIcon(ci->id, endPos, cmdColors.attack);
					}
				} else {
					const float3 endPos(ci->params[0],ci->params[1]+3,ci->params[2]);
					lineDrawer.DrawLineAndIcon(ci->id, endPos, cmdColors.attack);
				}
				break;
			}
			case CMD_GUARD:{
				const CUnit* unit = uh->units[int(ci->params[0])];
				if((unit != NULL) && isTrackable(unit)) {
					const float3 endPos =
						helper->GetUnitErrorPos(unit, owner->allyteam);
					lineDrawer.DrawLineAndIcon(ci->id, endPos, cmdColors.guard);
				}
				break;
			}
			case CMD_WAIT:{
				DrawWaitIcon(*ci);
				break;
			}
			case CMD_SELFD:{
				lineDrawer.DrawIconAtLastPos(ci->id);
				break;
			}
		}

		if ((ci->id < 0) && (ci->params.size() >= 3)) {
			BuildInfo bi;
			bi.def = unitDefHandler->GetUnitByID(-(ci->id));
			if (ci->params.size() == 4) {
				bi.buildFacing = int(ci->params[3]);
			}
			bi.pos = float3(ci->params[0], ci->params[1], ci->params[2]);
			bi.pos = helper->Pos2BuildPos(bi);

			cursorIcons.AddBuildIcon(ci->id, bi.pos, owner->team, bi.buildFacing);
			lineDrawer.DrawLine(bi.pos, cmdColors.build);

			// draw metal extraction range
			if (bi.def->extractRange > 0) {
				lineDrawer.Break(bi.pos, cmdColors.build);
				glColor4fv(cmdColors.rangeExtract);
				glSurfaceCircle(bi.pos, bi.def->extractRange, 40);
				lineDrawer.Restart();
			}
		}
	}
	lineDrawer.FinishPath();
}
Example #11
0
void ParticleSystem::draw()
{
	/*
	// just draw points:
	glDisable(GL_TEXTURE_2D);
	glDisable(GL_LIGHTING);
	glColor4f(1,1,1,1);
	glBegin(GL_POINTS);
	for (ParticleList::iterator it = particles.begin(); it != particles.end(); ++it) {
		glVertex3fv(it->tpos);
	}
	glEnd();
	glEnable(GL_LIGHTING);
	glEnable(GL_TEXTURE_2D);
	*/

	Vec3D bv0,bv1,bv2,bv3;

	// setup blend mode
	switch (blend) {
	case 0:
		glDisable(GL_BLEND);
		glDisable(GL_ALPHA_TEST);
		break;
	case 1:
		glEnable(GL_BLEND);
		glBlendFunc(GL_SRC_COLOR, GL_ONE);
		glDisable(GL_ALPHA_TEST);
		break;
	case 2:
		glEnable(GL_BLEND);
		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
		glDisable(GL_ALPHA_TEST);
		break;
	case 3:
		glDisable(GL_BLEND);
		glEnable(GL_ALPHA_TEST);
		break;
	case 4:
		glEnable(GL_BLEND);
		glDisable(GL_ALPHA_TEST);
		glBlendFunc(GL_SRC_ALPHA, GL_ONE);
		break;
	}

	glDisable(GL_LIGHTING);
	glDisable(GL_CULL_FACE);
	glDepthMask(GL_FALSE);

	glBindTexture(GL_TEXTURE_2D, texture);

	Matrix mbb;
	mbb.unit();

	if (billboard) {
		// get a billboard matrix
		Matrix mtrans;
		glGetFloatv(GL_MODELVIEW_MATRIX, &(mtrans.m[0][0]));
		mtrans.transpose();
		mtrans.invert();
		Vec3D camera = mtrans * Vec3D(0,0,0);
		Vec3D look = (camera - pos).normalize();
		Vec3D up = ((mtrans * Vec3D(0,1,0)) - camera).normalize();
		Vec3D right = (up % look).normalize();
		up = (look % right).normalize();
		// calculate the billboard matrix
		mbb.m[0][1] = right.x;
		mbb.m[1][1] = right.y;
		mbb.m[2][1] = right.z;
		mbb.m[0][2] = up.x;
		mbb.m[1][2] = up.y;
		mbb.m[2][2] = up.z;
		mbb.m[0][0] = look.x;
		mbb.m[1][0] = look.y;
		mbb.m[2][0] = look.z;
	}

	if (type==0 || type==2) {
		// TODO: figure out type 2 (deeprun tram subway sign)
		// - doesn't seem to be any different from 0 -_-
		// regular particles
		float f = 0.707106781f; // sqrt(2)/2
		if (billboard) {
			bv0 = mbb * Vec3D(0,-f,+f);
			bv1 = mbb * Vec3D(0,+f,+f);
			bv2 = mbb * Vec3D(0,+f,-f);
			bv3 = mbb * Vec3D(0,-f,-f);
		} else {
			bv0 = Vec3D(-f,0,+f);
			bv1 = Vec3D(+f,0,+f);
			bv2 = Vec3D(+f,0,-f);
			bv3 = Vec3D(-f,0,-f);
		}
		// TODO: per-particle rotation in a non-expensive way?? :|

		glBegin(GL_QUADS);
		for (ParticleList::iterator it = particles.begin(); it != particles.end(); ++it) {
			glColor4fv(it->color);

			glTexCoord2fv(tiles[it->tile].tc[0]);
			glVertex3fv(it->pos + bv0 * it->size);

			glTexCoord2fv(tiles[it->tile].tc[1]);
			glVertex3fv(it->pos + bv1 * it->size);

			glTexCoord2fv(tiles[it->tile].tc[2]);
			glVertex3fv(it->pos + bv2 * it->size);

			glTexCoord2fv(tiles[it->tile].tc[3]);
			glVertex3fv(it->pos + bv3 * it->size);
		}
		glEnd();
	}
	else if (type==1) {
		// particles from origin to position
		bv0 = mbb * Vec3D(0,-1.0f,0);
		bv1 = mbb * Vec3D(0,+1.0f,0);

		glBegin(GL_QUADS);
		for (ParticleList::iterator it = particles.begin(); it != particles.end(); ++it) {
			glColor4fv(it->color);

			glTexCoord2fv(tiles[it->tile].tc[0]);
			glVertex3fv(it->pos + bv0 * it->size);

			glTexCoord2fv(tiles[it->tile].tc[1]);
			glVertex3fv(it->pos + bv1 * it->size);

			glTexCoord2fv(tiles[it->tile].tc[2]);
			glVertex3fv(it->origin + bv1 * it->size);

			glTexCoord2fv(tiles[it->tile].tc[3]);
			glVertex3fv(it->origin + bv0 * it->size);
		}
		glEnd();
	}

	glEnable(GL_LIGHTING);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	glDepthMask(GL_TRUE);
	glColor4f(1,1,1,1);
}
// Draw the track in the panning aligned mode.
void cGrTrackMap::drawTrackPanningAligned(
	int Winx,
	int Winy,
	int Winw,
	int Winh,
	tCarElt *currentCar,
	tSituation *s
)
{
	float tracksize = MAX(track_width, track_height);
	float radius = MIN(500.0, tracksize/2.0);

	float x = Winx + Winw + map_x - map_size;
	float y = Winy + Winh + map_y - map_size;
	glMatrixMode(GL_TEXTURE);
	glPushMatrix();

	glTranslatef(
		(currentCar->_pos_X - track_min_x)/tracksize,
		(currentCar->_pos_Y - track_min_y)/tracksize,
		0.0
	);
	glRotatef(currentCar->_yaw*360.0/(2.0*PI) - 90.0, 0.0, 0.0, 1.0);
	float factor = (2.0*radius)/tracksize;
	glScalef(factor, factor, 1.0);
	glTranslatef(-0.5, -0.5, 0.0);

	glBegin(GL_QUADS);
    glTexCoord2f(0.0, 0.0); glVertex2f(x, y);
    glTexCoord2f(1.0, 0.0); glVertex2f(x + map_size, y);
    glTexCoord2f(1.0, 1.0); glVertex2f(x + map_size, y + map_size);
    glTexCoord2f(0.0, 1.0); glVertex2f(x, y + map_size);
	glEnd();

	glPopMatrix();
	glMatrixMode(GL_MODELVIEW);

	// Draw car "dots".
	glDisable(GL_BLEND);
	glDisable(GL_TEXTURE_2D);

	if (viewmode & TRACK_MAP_PAN_ALIGNED_WITH_OPPONENTS) {
		int i;
		for (i = 0; i < s->_ncars; i++) {
			if ((s->cars[i] != currentCar) && !(s->cars[i]->_state & (RM_CAR_STATE_DNF | RM_CAR_STATE_PULLUP | RM_CAR_STATE_PULLSIDE | RM_CAR_STATE_PULLDN))) {
				if (s->cars[i]->race.pos > currentCar->race.pos) {
					glColor4fv(behindCarColor);
				} else {
					glColor4fv(aheadCarColor);
				}
				float xc = (s->cars[i]->_pos_X - currentCar->_pos_X)/(radius*2.0)*map_size;
				float yc = (s->cars[i]->_pos_Y - currentCar->_pos_Y)/(radius*2.0)*map_size;
				float ss = sin(-currentCar->_yaw + PI/2.0);
				float cs = cos(-currentCar->_yaw + PI/2.0);
				float xrc = xc * cs - yc * ss;
				float yrc = xc * ss + yc * cs;

				if (fabs(xrc) < map_size/2.0 && fabs(yrc) < map_size/2.0) {
					glPushMatrix();
					glTranslatef(x + xrc + map_size/2.0, y + yrc + map_size/2.0, 0.0);
					float factor = tracksize/(2.0*radius);
		        	glScalef(factor, factor, 1.0);
					glCallList(cardot);
					glPopMatrix();
				}
			}
		}
	}

	glColor4fv(currentCarColor);
	if (cardot != 0) {
		glMatrixMode(GL_MODELVIEW);
		glPushMatrix();
		glTranslatef(x + map_size/2.0, y + map_size/2.0, 0.0);
		glScalef(1.0/factor, 1.0/factor, 1.0);
		glCallList(cardot);
		glPopMatrix();
	}
}
// Draw the track in the panning mode.
void cGrTrackMap::drawTrackPanning(
	int Winx,
	int Winy,
	int Winw,
	int Winh,
	tCarElt *currentCar,
	tSituation *s
)
{
	float x1, y1, x2, y2;
	float tracksize = MAX(track_width, track_height);
	float radius = MIN(500.0, tracksize/2.0);
	x1 = (currentCar->_pos_X - radius - track_min_x)/tracksize;
	y1 = (currentCar->_pos_Y - radius - track_min_y)/tracksize;
	x2 = (currentCar->_pos_X + radius - track_min_x)/tracksize;
	y2 = (currentCar->_pos_Y + radius - track_min_y)/tracksize;

	// Draw track.
	int x = Winx + Winw + map_x - map_size;
	int y = Winy + Winh + map_y - map_size;
	glBegin(GL_QUADS);
    glTexCoord2f(x1, y1); glVertex2f(x, y);
    glTexCoord2f(x2, y1); glVertex2f(x + map_size, y);
    glTexCoord2f(x2, y2); glVertex2f(x + map_size, y + map_size);
    glTexCoord2f(x1, y2); glVertex2f(x, y + map_size);
	glEnd();

	// Draw car "dots".
	glDisable(GL_BLEND);
	glDisable(GL_TEXTURE_2D);

	if (viewmode & TRACK_MAP_PAN_WITH_OPPONENTS) {
		int i;
		for (i = 0; i < s->_ncars; i++) {
			if ((s->cars[i] != currentCar) &&
				!(s->cars[i]->_state &
				(RM_CAR_STATE_DNF | RM_CAR_STATE_PULLUP | RM_CAR_STATE_PULLSIDE | RM_CAR_STATE_PULLDN)))
			{
				if (s->cars[i]->race.pos > currentCar->race.pos) {
					glColor4fv(behindCarColor);
				} else {
					glColor4fv(aheadCarColor);
				}
				float xc = s->cars[i]->_pos_X - currentCar->_pos_X;
				float yc = s->cars[i]->_pos_Y - currentCar->_pos_Y;
				if (fabs(xc) < radius && fabs(yc) < radius) {
					xc = xc/radius*map_size;
					yc = yc/radius*map_size;

					glPushMatrix();
					glTranslatef(x + (xc + map_size)/2.0, y + (yc + map_size)/2.0, 0.0);
					float factor = tracksize/(2.0*radius);
		        	glScalef(factor, factor, 1.0);
					glCallList(cardot);
					glPopMatrix();
				}
			}
		}
	}

	glColor4fv(currentCarColor);
	if (cardot != 0) {
		glMatrixMode(GL_MODELVIEW);
		glPushMatrix();
		glTranslatef(x + map_size/2.0, y + map_size/2.0, 0.0);
		float factor = tracksize/(2.0*radius);
		glScalef(factor, factor, 1.0);
		glCallList(cardot);
		glPopMatrix();
	}
}
Example #14
0
void LLFacePool::LLOverrideFaceColor::setColor(const LLColor4& color)
{
	glColor4fv(color.mV);
}
Example #15
0
int PGXP_DrawDebugQuad(OGLVertex* vertex1, OGLVertex* vertex2, OGLVertex* vertex3, OGLVertex* vertex4)
{
	GLboolean	bTexture = glIsEnabled(GL_TEXTURE_2D);
	GLfloat		fColour[4];
	GLint		iShadeModel;


	//if ((vertex1->PGXP_flag == 0) ||
	//	(vertex2->PGXP_flag == 0) ||
	//	(vertex3->PGXP_flag == 0) ||
	//	(vertex4->PGXP_flag == 0))
	//	return 0;


	// Quit if PGXP_flag == ignore
	if ((vertex1->PGXP_flag == 5) ||
		(vertex2->PGXP_flag == 5) ||
		(vertex3->PGXP_flag == 5) ||
		(vertex4->PGXP_flag == 5))
		return 1;

	glGetIntegerv(GL_SHADE_MODEL, &iShadeModel);
	glGetFloatv(GL_CURRENT_COLOR, fColour);

	glDisable(GL_TEXTURE_2D);
	glShadeModel(GL_SMOOTH);

	glBegin(GL_QUADS);

	PGXP_colour(vertex1);
	PGXP_glVertexfv(&vertex1->x);

	PGXP_colour(vertex2);
	PGXP_glVertexfv(&vertex2->x);

	PGXP_colour(vertex3);
	PGXP_glVertexfv(&vertex3->x);

	PGXP_colour(vertex4);
	PGXP_glVertexfv(&vertex4->x);

	glEnd();

	glPolygonMode(GL_FRONT, GL_LINE);
	glPolygonMode(GL_BACK, GL_LINE);

	glBegin(GL_TRIANGLE_STRIP);

	glColor4ubv(black);
	PGXP_glVertexfv(&vertex1->x);
	PGXP_glVertexfv(&vertex2->x);
	PGXP_glVertexfv(&vertex3->x);
	PGXP_glVertexfv(&vertex4->x);

	glColor4fv(fColour);

	glEnd();

	glPolygonMode(GL_FRONT, GL_FILL);
	glPolygonMode(GL_BACK, GL_FILL);

	if (bTexture == GL_TRUE)
		glEnable(GL_TEXTURE_2D);

	glShadeModel(iShadeModel);

	return 1;
}
void AbstractObj::namePolyhedron()
{
    glColor4fv(TypeCast::indexToColor(id).data());
}
Example #17
0
void DrawRoundRect(float x, float y, float width, float height, float* color,
		float radius) {
	y = y + height;
	Vector2f top_left[ROUNDING_POINT_COUNT];
	Vector2f bottom_left[ROUNDING_POINT_COUNT];
	Vector2f top_right[ROUNDING_POINT_COUNT];
	Vector2f bottom_right[ROUNDING_POINT_COUNT];

	if (radius == 0.0) {
		radius = min(width, height);
		radius *= 0.10; // 10%
	}

	int i = 0;
	float x_offset, y_offset;
	float step = (2.0f * M_PI) / (ROUNDING_POINT_COUNT * 4), angle = 0.0f;

	unsigned int index = 0, segment_count = ROUNDING_POINT_COUNT;
	Vector2f bottom_left_corner = { x + radius, y - height + radius };

	while (i != segment_count) {
		x_offset = cosf(angle);
		y_offset = sinf(angle);

		top_left[index].x = bottom_left_corner.x - (x_offset * radius);
		top_left[index].y = (height - (radius * 2.0f)) + bottom_left_corner.y
				- (y_offset * radius);

		top_right[index].x = (width - (radius * 2.0f)) + bottom_left_corner.x
				+ (x_offset * radius);
		top_right[index].y = (height - (radius * 2.0f)) + bottom_left_corner.y
				- (y_offset * radius);

		bottom_right[index].x = (width - (radius * 2.0f)) + bottom_left_corner.x
				+ (x_offset * radius);
		bottom_right[index].y = bottom_left_corner.y + (y_offset * radius);

		bottom_left[index].x = bottom_left_corner.x - (x_offset * radius);
		bottom_left[index].y = bottom_left_corner.y + (y_offset * radius);

	/*	top_left[index].x = top_left[index].x;
		top_left[index].y = top_left[index].y;

		top_right[index].x = top_right[index].x;
		top_right[index].y = top_right[index].y;

		bottom_right[index].x = bottom_right[index].x;
		bottom_right[index].y = bottom_right[index].y;

		bottom_left[index].x = bottom_left[index].x;
		bottom_left[index].y = bottom_left[index].y;*/

		angle -= step;

		++index;

		++i;
	}

	static GLubyte clr[] = { 156, 207, 255, 128 }; // Light blue, 50% transparent.

	if (color)
		glColor4fv(color);
	else
		glColor4ubv(clr);

	glBegin( GL_TRIANGLE_STRIP);
	{
		// Top
		for (i = segment_count - 1; i >= 0; i--) {
			glVertex2f(top_left[i].x, top_left[i].y);
			glVertex2f(top_right[i].x, top_right[i].y);
		}

		// In order to stop and restart the strip.
		glVertex2f(top_right[0].x, top_right[0].y);
		glVertex2f(top_right[0].x, top_right[0].y);

		// Center
		glVertex2f(top_right[0].x, top_right[0].y);
		glVertex2f(top_left[0].x, top_left[0].y);
		glVertex2f(bottom_right[0].x, bottom_right[0].y);
		glVertex2f(bottom_left[0].x, bottom_left[0].y);

		// Bottom
		for (i = 0; i != segment_count; i++) {
			glVertex2f(bottom_right[i].x, bottom_right[i].y);
			glVertex2f(bottom_left[i].x, bottom_left[i].y);
		}
	}
	glEnd();
} //DrawRoundRect
Example #18
0
void CAirCAI::DrawCommands(void)
{
	lineDrawer.StartPath(owner->drawMidPos, cmdColors.start);

	if (owner->selfDCountdown != 0) {
		lineDrawer.DrawIconAtLastPos(CMD_SELFD);
	}

	CCommandQueue::iterator ci;
	for (ci = commandQue.begin(); ci != commandQue.end(); ++ci) {
		switch (ci->id) {
			case CMD_MOVE: {
				const float3 endPos(ci->params[0], ci->params[1], ci->params[2]);
				lineDrawer.DrawLineAndIcon(ci->id, endPos, cmdColors.move);
				break;
			}
			case CMD_FIGHT: {
				const float3 endPos(ci->params[0], ci->params[1], ci->params[2]);
				lineDrawer.DrawLineAndIcon(ci->id, endPos, cmdColors.fight);
				break;
			}
			case CMD_PATROL: {
				const float3 endPos(ci->params[0], ci->params[1], ci->params[2]);
				lineDrawer.DrawLineAndIcon(ci->id, endPos, cmdColors.patrol);
				break;
			}
			case CMD_ATTACK: {
				if (ci->params.size() == 1) {
					const CUnit* unit = uh->GetUnit(ci->params[0]);

					if ((unit != NULL) && isTrackable(unit)) {
						const float3 endPos = helper->GetUnitErrorPos(unit, owner->allyteam);
						lineDrawer.DrawLineAndIcon(ci->id, endPos, cmdColors.attack);
					}
				} else {
					const float3 endPos(ci->params[0], ci->params[1], ci->params[2]);
					lineDrawer.DrawLineAndIcon(ci->id, endPos, cmdColors.attack);
				}
				break;
			}
			case CMD_AREA_ATTACK: {
				const float3 endPos(ci->params[0], ci->params[1], ci->params[2]);

				lineDrawer.DrawLineAndIcon(ci->id, endPos, cmdColors.attack);
				lineDrawer.Break(endPos, cmdColors.attack);
				glColor4fv(cmdColors.attack);
				glSurfaceCircle(endPos, ci->params[3], 20);
				lineDrawer.RestartWithColor(cmdColors.attack);
				break;
			}
			case CMD_GUARD: {
				const CUnit* unit = uh->GetUnit(ci->params[0]);

				if ((unit != NULL) && isTrackable(unit)) {
					const float3 endPos = helper->GetUnitErrorPos(unit, owner->allyteam);
					lineDrawer.DrawLineAndIcon(ci->id, endPos, cmdColors.guard);
				}
				break;
			}
			case CMD_WAIT: {
				DrawWaitIcon(*ci);
				break;
			}
			case CMD_SELFD: {
				lineDrawer.DrawIconAtLastPos(ci->id);
				break;
			}
			default:
				DrawDefaultCommand(*ci);
				break;
		}
	}
	lineDrawer.FinishPath();
}
Example #19
0
  //drawing 20x20cm grind in 3dview
  void GlWidget::drawGrid(){
      GLint     iSlices=32;
      GLint     iStacks=32;
      GLdouble  lineRadius=0.001;
      bool      bSolid=true;
      bool      bBlend=true;
      GLfloat fCurrentColor[4];
      // Get the current color
      glGetFloatv(GL_CURRENT_COLOR, fCurrentColor);

      // Save the current transformation matrix..
      glPushMatrix();

      // Create a quadratic object used to draw our axis
      // cylinders and cones
      GLUquadricObj* pQuadric = gluNewQuadric();
      if(!pQuadric)
          return;

      // Set the quadric state
      gluQuadricNormals(pQuadric, GLU_SMOOTH);
      gluQuadricTexture(pQuadric, GL_FALSE);

      if(bSolid)
      {
          glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
          gluQuadricDrawStyle(pQuadric, GLU_FILL);
      }
      else
      {
          glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
          gluQuadricDrawStyle(pQuadric, GLU_LINE);
      }

      // Enable alpha blending?
      if(bBlend)
      {
          glEnable(GL_BLEND);
          glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
      }

      //draw grid
      //rotate for x
      glRotated(90, 0.0, 1.0, 0.0);
      for(int i=0; i<sizeY; i++){
          gluCylinder(pQuadric, lineRadius, lineRadius, (double)sizeX/10, iSlices, iStacks);
                glTranslated(0.0f, 0.1f, 0.0f);
      }
                gluCylinder(pQuadric, lineRadius, lineRadius, (double)sizeX/10, iSlices, iStacks);
      glRotated(90, 1.0, 0.0, 0.0);
      for(int i=0; i<sizeX+1; i++){
                gluCylinder(pQuadric, lineRadius, lineRadius, (double)sizeY/10, iSlices, iStacks);
                glTranslated(0.0f, 0.1f, 0.0f);
      }

      // Delete the quadric
      gluDeleteQuadric(pQuadric);

      // Restore the current transformation matrix..
      glPopMatrix();

      // Restore the current color
      glColor4fv(fCurrentColor);

      // Disable blend function
      glDisable(GL_BLEND);
  }
void mitk::UnstructuredGridMapper2D::Paint( mitk::BaseRenderer* renderer )
{
  bool visible = true;
  GetDataNode()->GetVisibility(visible, renderer, "visible");
  if(!visible) return;

  vtkLinearTransform * vtktransform = GetDataNode()->GetVtkTransform();
  vtkLinearTransform * inversetransform = vtktransform->GetLinearInverse();

  PlaneGeometry::ConstPointer worldGeometry = renderer->GetCurrentWorldPlaneGeometry();
  PlaneGeometry::ConstPointer worldPlaneGeometry = dynamic_cast<const PlaneGeometry*>( worldGeometry.GetPointer() );

  Point3D point;
  Vector3D normal;

  if(worldPlaneGeometry.IsNotNull())
  {
    // set up vtkPlane according to worldGeometry
    point=worldPlaneGeometry->GetOrigin();
    normal=worldPlaneGeometry->GetNormal(); normal.Normalize();
    m_Plane->SetTransform((vtkAbstractTransform*)NULL);
  }
  else
  {
    //@FIXME: does not work correctly. Does m_Plane->SetTransform really transforms a "plane plane" into a "curved plane"?
    return;
    AbstractTransformGeometry::ConstPointer worldAbstractGeometry = dynamic_cast<const AbstractTransformGeometry*>(renderer->GetCurrentWorldPlaneGeometry());
    if(worldAbstractGeometry.IsNotNull())
    {
      // set up vtkPlane according to worldGeometry
      point=const_cast<mitk::BoundingBox*>(worldAbstractGeometry->GetParametricBoundingBox())->GetMinimum();
      FillVector3D(normal, 0, 0, 1);
      m_Plane->SetTransform(worldAbstractGeometry->GetVtkAbstractTransform()->GetInverse());
    }
    else
      return;
  }

  double vp[ 3 ], vnormal[ 3 ];

  vnl2vtk(point.GetVnlVector(), vp);
  vnl2vtk(normal.GetVnlVector(), vnormal);

  //normally, we would need to transform the surface and cut the transformed surface with the cutter.
  //This might be quite slow. Thus, the idea is, to perform an inverse transform of the plane instead.
  //@todo It probably does not work for scaling operations yet:scaling operations have to be
  //dealed with after the cut is performed by scaling the contour.
  inversetransform->TransformPoint( vp, vp );
  inversetransform->TransformNormalAtPoint( vp, vnormal, vnormal );

  m_Plane->SetOrigin( vp );
  m_Plane->SetNormal( vnormal );

  // set data into cutter
  m_Slicer->SetInputData( m_VtkPointSet );
  //    m_Cutter->GenerateCutScalarsOff();
  //    m_Cutter->SetSortByToSortByCell();

  // calculate the cut
  m_Slicer->Update();

  //apply color and opacity read from the PropertyList
  ApplyColorAndOpacityProperties( renderer );

  // traverse the cut contour
  vtkPolyData * contour = m_Slicer->GetOutput();

  vtkPoints *vpoints = contour->GetPoints();
  vtkCellArray *vlines = contour->GetLines();
  vtkCellArray *vpolys = contour->GetPolys();
  vtkPointData *vpointdata = contour->GetPointData();
  vtkDataArray* vscalars = vpointdata->GetScalars();

  vtkCellData *vcelldata = contour->GetCellData();
  vtkDataArray* vcellscalars = vcelldata->GetScalars();

  const int numberOfLines = contour->GetNumberOfLines();
  const int numberOfPolys = contour->GetNumberOfPolys();

  const bool useCellData = m_ScalarMode->GetVtkScalarMode() == VTK_SCALAR_MODE_DEFAULT ||
      m_ScalarMode->GetVtkScalarMode() == VTK_SCALAR_MODE_USE_CELL_DATA;
  const bool usePointData = m_ScalarMode->GetVtkScalarMode() == VTK_SCALAR_MODE_USE_POINT_DATA;

  Point3D p;
  Point2D p2d;

  vlines->InitTraversal();
  vpolys->InitTraversal();

  mitk::Color outlineColor = m_Color->GetColor();

  glLineWidth((float)m_LineWidth->GetValue());

  for (int i = 0;i < numberOfLines;++i )
  {
    vtkIdType *cell(0);
    vtkIdType cellSize(0);

    vlines->GetNextCell( cellSize, cell );

    float rgba[4] = {outlineColor[0], outlineColor[1], outlineColor[2], 1.0f};
    if (m_ScalarVisibility->GetValue() && vcellscalars)
    {
      if ( useCellData )
      {  // color each cell according to cell data
        double scalar = vcellscalars->GetComponent( i, 0 );
        double rgb[3] = { 1.0f, 1.0f, 1.0f };
        m_ScalarsToColors->GetColor(scalar, rgb);
        rgba[0] = (float)rgb[0];
        rgba[1] = (float)rgb[1];
        rgba[2] = (float)rgb[2];
        rgba[3] = (float)m_ScalarsToOpacity->GetValue(scalar);
      }
      else if ( usePointData )
      {
        double scalar = vscalars->GetComponent( i, 0 );
        double rgb[3] = { 1.0f, 1.0f, 1.0f };
        m_ScalarsToColors->GetColor(scalar, rgb);
        rgba[0] = (float)rgb[0];
        rgba[1] = (float)rgb[1];
        rgba[2] = (float)rgb[2];
        rgba[3] = (float)m_ScalarsToOpacity->GetValue(scalar);
      }
    }

    glColor4fv( rgba );

    glBegin ( GL_LINE_LOOP );
    for ( int j = 0;j < cellSize;++j )
    {
      vpoints->GetPoint( cell[ j ], vp );
      //take transformation via vtktransform into account
      vtktransform->TransformPoint( vp, vp );

      vtk2itk( vp, p );

      //convert 3D point (in mm) to display coordinates (units )
      renderer->WorldToDisplay( p, p2d );

      //convert display coordinates ( (0,0) is top-left ) in GL coordinates ( (0,0) is bottom-left )
      //p2d[1]=toGL-p2d[1];

      //add the current vertex to the line
      glVertex2f( p2d[0], p2d[1] );
    }
    glEnd ();

  }

  bool polyOutline = m_Outline->GetValue();
  bool scalarVisibility = m_ScalarVisibility->GetValue();

  // cache the transformed points
  // a fixed size array is way faster than 'new'
  // slices through 3d cells usually do not generated
  // polygons with more than 6 vertices
  const int maxPolySize = 10;
  Point2D* cachedPoints = new Point2D[maxPolySize*numberOfPolys];

  glEnable(GL_BLEND);
  glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

  // only draw polygons if there are cell scalars
  // or the outline property is set to true
  if (scalarVisibility && vcellscalars)
  {
    glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);

    for (int i = 0;i < numberOfPolys;++i )
    {
      vtkIdType *cell(0);
      vtkIdType cellSize(0);

      vpolys->GetNextCell( cellSize, cell );

      float rgba[4] = {1.0f, 1.0f, 1.0f, 0};
      if (scalarVisibility && vcellscalars)
      {
        if ( useCellData )
        {  // color each cell according to cell data
          double scalar = vcellscalars->GetComponent( i+numberOfLines, 0 );
          double rgb[3] = { 1.0f, 1.0f, 1.0f };
          m_ScalarsToColors->GetColor(scalar, rgb);
          rgba[0] = (float)rgb[0];
          rgba[1] = (float)rgb[1];
          rgba[2] = (float)rgb[2];
          rgba[3] = (float)m_ScalarsToOpacity->GetValue(scalar);
        }
        else if ( usePointData )
        {
          double scalar = vscalars->GetComponent( i, 0 );
          double rgb[3] = { 1.0f, 1.0f, 1.0f };
          m_ScalarsToColors->GetColor(scalar, rgb);
          rgba[0] = (float)rgb[0];
          rgba[1] = (float)rgb[1];
          rgba[2] = (float)rgb[2];
          rgba[3] = (float)m_ScalarsToOpacity->GetValue(scalar);
        }
      }
      glColor4fv( rgba );

      glBegin( GL_POLYGON );
      for (int j = 0; j < cellSize; ++j)
      {
        vpoints->GetPoint( cell[ j ], vp );
        //take transformation via vtktransform into account
        vtktransform->TransformPoint( vp, vp );

        vtk2itk( vp, p );

        //convert 3D point (in mm) to display coordinates (units )
        renderer->WorldToDisplay( p, p2d );

        //convert display coordinates ( (0,0) is top-left ) in GL coordinates ( (0,0) is bottom-left )
        //p2d[1]=toGL-p2d[1];

        cachedPoints[i*10+j][0] = p2d[0];
        cachedPoints[i*10+j][1] = p2d[1];

        //add the current vertex to the line
        glVertex2f( p2d[0], p2d[1] );
      }
      glEnd();
    }

    if (polyOutline)
    {
      vpolys->InitTraversal();

      glColor4f(outlineColor[0], outlineColor[1], outlineColor[2], 1.0f);
      glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
      for (int i = 0;i < numberOfPolys;++i)
      {
        vtkIdType *cell(0);
        vtkIdType cellSize(0);

        vpolys->GetNextCell( cellSize, cell );

        glBegin( GL_POLYGON );
        //glPolygonOffset(1.0, 1.0);
        for (int j = 0; j < cellSize; ++j)
        {
          //add the current vertex to the line
          glVertex2f( cachedPoints[i*10+j][0], cachedPoints[i*10+j][1] );
        }
        glEnd();
      }
    }
  }
  glDisable(GL_BLEND);
  delete[] cachedPoints;
}
//-----------------------------------------------.
void guiTypeTextDropDown::render(){

	ofPushStyle();
	guiBaseObject::renderText();

		//draw the background
		ofFill();
		glColor4fv(bgColor.getNormalColorF());
		ofRect(hitArea.x, hitArea.y, hitArea.width, hitArea.height);

		if(bShowDropDown)
		{

			for(int i = 0; i < (int) vecDropList.size(); i++)
			{
				float bx = hitArea.x;
				float by = hitArea.y + i * (boxHeight);

				if(value.getValueI() == i){
					glColor4fv(fgColor.getSelectedColorF());
				}else{
					glColor4fv(bgColor.getNormalColorF());
				}

				ofFill();

				ofRect(bx, by,  boundingBox.width, boxHeight);

				ofNoFill();
				glColor4fv(outlineColor.getColorF());
				ofRect(bx, by,  boundingBox.width, boxHeight);

				if(i==0) {
					ofFill();
					glColor4fv(outlineColor.getColorF());
					ofRect(bx + boundingBox.width - boxHeight*0.5, by, boxHeight*0.5, boxHeight*0.5);
				}

				glColor4fv(textColor.getColorF());

				displayText.renderString(vecDropList[i], bx + 2, by + boxHeight -4);

			}

		} else {
			float bx = hitArea.x;
			float by = hitArea.y;

			ofFill();
			glColor4fv(bgColor.getColorF());
			ofRect(bx, by,  boundingBox.width, boxHeight);

			ofNoFill();
			glColor4fv(outlineColor.getColorF());
			ofRect(bx, by,  boundingBox.width, boxHeight);

			ofFill();
			glColor4fv(outlineColor.getColorF());
			//ofTriangle(bx + boundingBox.width - 7, by + boxHeight, bx + boundingBox.width - 14, by,bx + boundingBox.width, by);
			ofRect(bx + boundingBox.width - boxHeight*0.5, by, boxHeight*0.5, boxHeight*0.5);

			glColor4fv(textColor.getColorF());
			displayText.renderString(vecDropList[value.getValueI()], bx + 2, by + boxHeight -4);

		}

	ofPopStyle();
}
inline void glColor(Vector< float, 4 > const &v)
{
  glColor4fv(v.c);
}
Example #23
0
int blf_glyph_render(FontBLF *font, GlyphBLF *g, float x, float y)
{
	float dx, dx1;
	float y1, y2;
	float xo, yo;

	if ((!g->width) || (!g->height))
		return 1;

	if (g->build_tex == 0) {
		GlyphCacheBLF *gc = font->glyph_cache;

		if (font->max_tex_size == -1)
			glGetIntegerv(GL_MAX_TEXTURE_SIZE, (GLint *)&font->max_tex_size);

		if (gc->cur_tex == -1) {
			blf_glyph_cache_texture(font, gc);
			gc->x_offs = gc->pad;
			gc->y_offs = 0;
		}

		if (gc->x_offs > (gc->p2_width - gc->max_glyph_width)) {
			gc->x_offs = gc->pad;
			gc->y_offs += gc->max_glyph_height;

			if (gc->y_offs > (gc->p2_height - gc->max_glyph_height)) {
				gc->y_offs = 0;
				blf_glyph_cache_texture(font, gc);
			}
		}

		g->tex = gc->textures[gc->cur_tex];
		g->xoff = gc->x_offs;
		g->yoff = gc->y_offs;

		/* prevent glTexSubImage2D from failing if the character
		 * asks for pixels out of bounds, this tends only to happen
		 * with very small sizes (5px high or less) */
		if (UNLIKELY((g->xoff + g->width)  > gc->p2_width)) {
			g->width  -= (g->xoff + g->width)  - gc->p2_width;
			BLI_assert(g->width > 0);
		}
		if (UNLIKELY((g->yoff + g->height) > gc->p2_height)) {
			g->height -= (g->yoff + g->height) - gc->p2_height;
			BLI_assert(g->height > 0);
		}


		glPushClientAttrib(GL_CLIENT_PIXEL_STORE_BIT);
		glPixelStorei(GL_UNPACK_LSB_FIRST, GL_FALSE);
		glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
		glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

		glBindTexture(GL_TEXTURE_2D, g->tex);
		glTexSubImage2D(GL_TEXTURE_2D, 0, g->xoff, g->yoff, g->width, g->height, GL_ALPHA, GL_UNSIGNED_BYTE, g->bitmap);
		glPopClientAttrib();

		g->uv[0][0] = ((float)g->xoff) / ((float)gc->p2_width);
		g->uv[0][1] = ((float)g->yoff) / ((float)gc->p2_height);
		g->uv[1][0] = ((float)(g->xoff + g->width)) / ((float)gc->p2_width);
		g->uv[1][1] = ((float)(g->yoff + g->height)) / ((float)gc->p2_height);

		/* update the x offset for the next glyph. */
		gc->x_offs += (int)(BLI_rctf_size_x(&g->box) + gc->pad);

		gc->rem_glyphs--;
		g->build_tex = 1;
	}

	xo = 0.0f;
	yo = 0.0f;

	if (font->flags & BLF_SHADOW) {
		xo = x;
		yo = y;
		x += font->shadow_x;
		y += font->shadow_y;
	}

	dx = floor(x + g->pos_x);
	dx1 = dx + g->width;
	y1 = y + g->pos_y;
	y2 = y + g->pos_y - g->height;

	if (font->flags & BLF_CLIPPING) {
		if (!BLI_rctf_isect_pt(&font->clip_rec, dx + font->pos[0], y1 + font->pos[1]))
			return 0;
		if (!BLI_rctf_isect_pt(&font->clip_rec, dx + font->pos[0], y2 + font->pos[1]))
			return 0;
		if (!BLI_rctf_isect_pt(&font->clip_rec, dx1 + font->pos[0], y2 + font->pos[1]))
			return 0;
		if (!BLI_rctf_isect_pt(&font->clip_rec, dx1 + font->pos[0], y1 + font->pos[1]))
			return 0;
	}

	if (font->tex_bind_state != g->tex) {
		glBindTexture(GL_TEXTURE_2D, (font->tex_bind_state = g->tex));
	}

	if (font->flags & BLF_SHADOW) {

		switch (font->shadow) {
			case 3:
				blf_texture3_draw(font->shadow_col, g->uv, dx, y1, dx1, y2);
				break;
			case 5:
				blf_texture5_draw(font->shadow_col, g->uv, dx, y1, dx1, y2);
				break;
			default:
				glColor4fv(font->shadow_col);
				blf_texture_draw(g->uv, dx, y1, dx1, y2);
				break;
		}

		glColor4fv(font->orig_col);

		x = xo;
		y = yo;

		dx = floor(x + g->pos_x);
		dx1 = dx + g->width;
		y1 = y + g->pos_y;
		y2 = y + g->pos_y - g->height;
	}

	switch (font->blur) {
		case 3:
			blf_texture3_draw(font->orig_col, g->uv, dx, y1, dx1, y2);
			break;
		case 5:
			blf_texture5_draw(font->orig_col, g->uv, dx, y1, dx1, y2);
			break;
		default:
			blf_texture_draw(g->uv, dx, y1, dx1, y2);
			break;
	}

	return 1;
}
Example #24
0
void BoxGeometry::drawPhysics(unsigned int flags) const
{
  glPushMatrix();
  glMultMatrixf(transformation);

  if(flags & SimRobotCore2::Renderer::showPhysics)
  {
    const float lx = depth * 0.5f;
    const float ly = width * 0.5f;
    const float lz = height * 0.5f;

    // -y-side
    glBegin(GL_TRIANGLE_FAN);
      glColor4fv(color);
      glNormal3f(0, -1, 0);
      glVertex3f(lx, -ly, -lz);
      glVertex3f(lx, -ly, lz);
      glVertex3f(-lx, -ly, lz);
      glVertex3f(-lx, -ly, -lz);
    glEnd();

    // y-side
    glBegin(GL_TRIANGLE_FAN);
      glNormal3f(0, 1, 0);
      glVertex3f(-lx, ly, lz);
      glVertex3f(lx, ly, lz);
      glVertex3f(lx, ly, -lz);
      glVertex3f(-lx, ly, -lz);
    glEnd();

    // -x-side
    glBegin(GL_TRIANGLE_FAN);
      glNormal3f(-1, 0, 0);
      glVertex3f(-lx, -ly, -lz);
      glVertex3f(-lx, -ly, lz);
      glVertex3f(-lx, ly, lz);
      glVertex3f(-lx, ly, -lz);
    glEnd();

    // x-side
    glBegin(GL_TRIANGLE_FAN);
      glNormal3f(1, 0, 0);
      glVertex3f(lx, -ly, -lz);
      glVertex3f(lx, ly, -lz);
      glVertex3f(lx, ly, lz);
      glVertex3f(lx, -ly, lz);
    glEnd();

    // bottom
    glBegin(GL_TRIANGLE_FAN);
      glNormal3f(0, 0, -1);
      glVertex3f(-lx, -ly, -lz);
      glVertex3f(-lx, ly, -lz);
      glVertex3f(lx, ly, -lz);
      glVertex3f(lx, -ly, -lz);
    glEnd();

    // top
    glBegin(GL_TRIANGLE_FAN);
      glNormal3f(0, 0, 1);
      glVertex3f(-lx, -ly, lz);
      glVertex3f(lx, -ly, lz);
      glVertex3f(lx, ly, lz);
      glVertex3f(-lx, ly, lz);
    glEnd();
  }

  ::PhysicalObject::drawPhysics(flags);
  glPopMatrix();
}
Example #25
0
int OglRenderArrays (CBitmap *bmP, int nFrame, CFloatVector *vertexP, int nVertices, tTexCoord2f *texCoordP,
                     tRgbaColorf *colorP, int nColors, int nPrimitive, int nWrap)
{
    int	bVertexArrays = ogl.EnableClientStates (bmP && texCoordP, colorP && (nColors == nVertices), 0, GL_TEXTURE0);

    if (bmP)
        glEnable (GL_TEXTURE_2D);
    else
        glDisable (GL_TEXTURE_2D);
    if (bmP) {
        if (bmP->Bind (1))
            return 0;
        bmP = bmP->Override (-1);
        if (bmP->Frames ())
            bmP = bmP->Frames () + nFrame;
        bmP->Texture ()->Wrap (nWrap);
    }
    if (bVertexArrays) {
        if (texCoordP)
            OglTexCoordPointer (2, GL_FLOAT, sizeof (tTexCoord2f), texCoordP);
        if (colorP) {
            if (nColors == nVertices)
                OglColorPointer (4, GL_FLOAT, sizeof (tRgbaColorf), colorP);
            else
                glColor4fv (reinterpret_cast<GLfloat*> (colorP));
        }
        OglVertexPointer (3, GL_FLOAT, sizeof (CFloatVector), vertexP);
        OglDrawArrays (nPrimitive, 0, nVertices);
        ogl.DisableClientState (GL_VERTEX_ARRAY);
        if (texCoordP)
            ogl.DisableClientState (GL_TEXTURE_COORD_ARRAY);
        if (colorP)
            ogl.DisableClientState (GL_COLOR_ARRAY);
    }
    else {
        int i = nVertices;
        glBegin (nPrimitive);
        if (colorP && (nColors == nVertices)) {
            if (bmP) {
                for (i = 0; i < nVertices; i++) {
                    glColor4fv (reinterpret_cast<GLfloat*> (colorP + i));
                    glVertex3fv (reinterpret_cast<GLfloat*> (vertexP + i));
                    glTexCoord2fv (reinterpret_cast<GLfloat*> (texCoordP + i));
                }
            }
            else {
                for (i = 0; i < nVertices; i++) {
                    glColor4fv (reinterpret_cast<GLfloat*> (colorP + i));
                    glVertex3fv (reinterpret_cast<GLfloat*> (vertexP + i));
                }
            }
        }
        else {
            if (colorP)
                glColor4fv (reinterpret_cast<GLfloat*> (colorP));
            else
                glColor3d (1, 1, 1);
            if (bmP) {
                for (i = 0; i < nVertices; i++) {
                    glVertex3fv (reinterpret_cast<GLfloat*> (vertexP + i));
                    glTexCoord2fv (reinterpret_cast<GLfloat*> (texCoordP + i));
                }
            }
            else {
                for (i = 0; i < nVertices; i++) {
                    glVertex3fv (reinterpret_cast<GLfloat*> (vertexP + i));
                }
            }
        }
        glEnd ();
    }
    return 1;
}
void CSelectedUnits::Draw()
{
	glDisable(GL_DEPTH_TEST);
	glEnable(GL_BLEND); // for line smoothing
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
	glLineWidth(cmdColors.UnitBoxLineWidth());

	if (cmdColors.unitBox[3] > 0.0f) {
		glColor4fv(cmdColors.unitBox);

		const CUnitSet* unitSet;
		if (selectedGroup != -1) {
			unitSet = &grouphandlers[gu->myTeam]->groups[selectedGroup]->units;
		} else {
			unitSet = &selectedUnits;
		}

		glBegin(GL_QUADS);
		CUnitSet::const_iterator ui;
		for (ui = unitSet->begin(); ui != unitSet->end(); ++ui) {
			const CUnit* unit = *ui;
			if (unit->isIcon) {
				continue;
			}
			const float3 pos(unit->pos + unit->speed * gu->timeOffset);
			glVertexf3(pos + float3( unit->xsize * 4, 0,  unit->ysize * 4));
			glVertexf3(pos + float3(-unit->xsize * 4, 0,  unit->ysize * 4));
			glVertexf3(pos + float3(-unit->xsize * 4, 0, -unit->ysize * 4));
			glVertexf3(pos + float3( unit->xsize * 4, 0, -unit->ysize * 4));
		}
		glEnd();
	}

	// highlight queued build sites if we are about to build something
	// (or old-style, whenever the shift key is being held down)
	if (cmdColors.buildBox[3] > 0.0f) {
		if (!selectedUnits.empty() &&
				((cmdColors.BuildBoxesOnShift() && keys[SDLK_LSHIFT]) ||
				 ((guihandler->inCommand >= 0) &&
					(guihandler->inCommand < guihandler->commands.size()) &&
					(guihandler->commands[guihandler->inCommand].id < 0)))) {
			bool myColor = true;
			glColor4fv(cmdColors.buildBox);
			std::list<CBuilderCAI*>::const_iterator bi;
			for (bi = uh->builderCAIs.begin(); bi != uh->builderCAIs.end(); ++bi) {
				CBuilderCAI* builder = *bi;
				if (builder->owner->team == gu->myTeam) {
					if (!myColor) {
						glColor4fv(cmdColors.buildBox);
						myColor = true;
					}
					builder->DrawQuedBuildingSquares();
				}
				else if (gs->AlliedTeams(builder->owner->team, gu->myTeam)) {
					if (myColor) {
						glColor4fv(cmdColors.allyBuildBox);
						myColor = false;
					}
					builder->DrawQuedBuildingSquares();
				}
			}
		}
	}

	glLineWidth(1.0f);
	glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
	glDisable(GL_BLEND);
	glEnable(GL_DEPTH_TEST);
}
Example #27
0
void glfDraw3DSolidSymbol(char s)
{
	int i, j, cur_line, flag;
	float x, y, bx, by;
	unsigned char *b; /* Face pointer   */
	float *vp;        /* Vertex pointer */
	float *tvp;       /* temp vertex pointer */
	float temp_color[4];
	GLboolean light_temp;
  
	if ((curfont<0) || (fonts[curfont] == NULL)) return;
	if (fonts[curfont]->symbols[(int)s] == NULL) return;

	b = fonts[curfont]->symbols[s]->fdata;
	vp = fonts[curfont]->symbols[s]->vdata;

	glBegin(GL_TRIANGLES);   
	glNormal3f(0, 0, 1);
	for (i=0; i<fonts[curfont]->symbols[s]->facets; i++)
	{
		b += 2;
		for (j=0; j<3; j++)
		{
			x = vp[*b*2];
			y = vp[*b*2+1];
			glVertex3f(x, y, 1+SymbolDepth);
			b--;
		}
		b += 4;
	}
	glEnd();

	b = fonts[curfont]->symbols[s]->fdata;
	vp = fonts[curfont]->symbols[s]->vdata;
  
	glBegin(GL_TRIANGLES);   
	glNormal3f(0, 0, -1);
	for (i=0; i<fonts[curfont]->symbols[s]->facets; i++)
	{
		for (j=0; j<3; j++)
		{
			x = vp[*b*2];
			y = vp[*b*2+1];
			glVertex3f(x, y, 1);
			b++;
		}
	}
	glEnd();

	flag = 0;
	glBegin(GL_QUAD_STRIP);
	tvp = fonts[curfont]->symbols[s]->vdata;
	cur_line = 0;
	for (i=0; i<fonts[curfont]->symbols[s]->vertexs; i++)
	{
		x = *tvp;
		tvp++;
		y = *tvp;
		tvp++;
		if (!flag) 
		{
			bx = x;
			by = y;
			flag = 1;
		}
		glNormal3f(x, y, 0);
		glVertex3f(x, y, 1);
		glVertex3f(x, y, 1+SymbolDepth);
		if (fonts[curfont]->symbols[s]->ldata[cur_line] == i)
		{
			glVertex3f(bx, by, 1);
			glVertex3f(bx, by, 1+SymbolDepth);
			flag = 0;
			glEnd();
			cur_line++;
			if (cur_line < fonts[curfont]->symbols[s]->lines) glBegin(GL_QUAD_STRIP);
			else break; /* No more lines */
		}
	}

	/* Draw contour, if enabled */
	if (contouring == GLF_YES) 
	{
		glGetBooleanv(GL_LIGHTING, &light_temp);
		glDisable(GL_LIGHTING);
		glGetFloatv(GL_CURRENT_COLOR, temp_color);
		glColor4f(contouring_color.r, contouring_color.g, contouring_color.b, contouring_color.a);
		glfDraw3DWiredSymbol(s);
		glColor4fv(temp_color);
		if (light_temp) glEnable(GL_LIGHTING);
	}
}
Example #28
0
void CMiniMap::DrawForReal(bool use_geo)
{
    SCOPED_TIMER("MiniMap::DrawForReal");

    //glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    glPushAttrib(GL_DEPTH_BUFFER_BIT);
    glDisable(GL_DEPTH_TEST);
    glDepthFunc(GL_LEQUAL);
    glDepthMask(GL_FALSE);
    glDisable(GL_TEXTURE_2D);
    glMatrixMode(GL_MODELVIEW);

    if (minimized) {
        if (!slaveDrawMode) {
            DrawMinimizedButton();
        }
        glPopAttrib();
        glEnable(GL_TEXTURE_2D);
        return;
    }

    // draw the frameborder
    if (!slaveDrawMode && !globalRendering->dualScreenMode && !maximized) {
        glEnable(GL_BLEND);
        DrawFrame();
        glDisable(GL_BLEND);
    }


    bool resetTextureMatrix = false;

    if (use_geo) {
        glPushMatrix();

        // switch to normalized minimap coords
        if (globalRendering->dualScreenMode) {
            glViewport(xpos, ypos, width, height);
            glScalef(width * globalRendering->pixelX, height * globalRendering->pixelY, 1.0f);
        } else {
            glTranslatef(xpos * globalRendering->pixelX, ypos * globalRendering->pixelY, 0.0f);
            glScalef(width * globalRendering->pixelX, height * globalRendering->pixelY, 1.0f);
        }

        /* FIXME: fix mouse handling too and make it fully customizable, so Lua can rotate the minimap to any angle
        CCameraController* camController = &camHandler->GetCurrentController();
        COverheadController* taCam = dynamic_cast<COverheadController*>(camController);
        SmoothController* smCam = dynamic_cast<SmoothController*>(camController);

        if ((taCam && taCam->flipped) || (smCam && smCam->flipped)) {
        	glTranslatef(1.0f, 1.0f, 0.0f);
        	glScalef(-1.0f, -1.0f, 1.0f);

        	glMatrixMode(GL_TEXTURE);
        	glPushMatrix();
        	glTranslatef(1.0f, 1.0f, 0.0f);
        	glScalef(-1.0f, -1.0f, 1.0f);
        	glMatrixMode(GL_MODELVIEW);

        	resetTextureMatrix = true;
        }*/
    }

    setSurfaceCircleFunc(DrawSurfaceCircle);
    setSurfaceSquareFunc(DrawSurfaceSquare);
    cursorIcons.Enable(false);

    glColor4f(0.6f, 0.6f, 0.6f, 1.0f);

    // don't mirror the map texture with flipped cameras
    glMatrixMode(GL_TEXTURE);
    glPushMatrix();
    glLoadIdentity();
    glMatrixMode(GL_MODELVIEW);

    // draw the map
    glDisable(GL_BLEND);
    readmap->DrawMinimap();
    glEnable(GL_BLEND);

    glMatrixMode(GL_TEXTURE);
    glPopMatrix();
    glMatrixMode(GL_MODELVIEW);

    // clip everything outside of the minimap box
    {
        const double plane0[4] = {0,-1,0,1};
        const double plane1[4] = {0,1,0,0};
        const double plane2[4] = {-1,0,0,1};
        const double plane3[4] = {1,0,0,0};

        glClipPlane(GL_CLIP_PLANE0, plane0); // clip bottom
        glClipPlane(GL_CLIP_PLANE1, plane1); // clip top
        glClipPlane(GL_CLIP_PLANE2, plane2); // clip right
        glClipPlane(GL_CLIP_PLANE3, plane3); // clip left

        glEnable(GL_CLIP_PLANE0);
        glEnable(GL_CLIP_PLANE1);
        glEnable(GL_CLIP_PLANE2);
        glEnable(GL_CLIP_PLANE3);
    }

    // switch to top-down map/world coords (z is twisted with y compared to the real map/world coords)
    glPushMatrix();
    glTranslatef(0.0f, +1.0f, 0.0f);
    glScalef(+1.0f / (gs->mapx * SQUARE_SIZE), -1.0f / (gs->mapy * SQUARE_SIZE), 1.0f);

    glEnable(GL_TEXTURE_2D);
    glEnable(GL_ALPHA_TEST);
    glAlphaFunc(GL_GREATER, 0.0f);

    {
        GML_RECMUTEX_LOCK(unit); // DrawForReal

        const std::set<CUnit*>& units = unitDrawer->GetUnsortedUnits();

        for (std::set<CUnit*>::const_iterator it = units.begin(); it != units.end(); ++it) {
            DrawUnit(*it);
        }

        // highlight the selected unit
        CUnit* unit = GetSelectUnit(GetMapPosition(mouse->lastx, mouse->lasty));
        if (unit != NULL) {
            DrawUnitHighlight(unit);
        }
    }

    glDisable(GL_ALPHA_TEST);
    glDisable(GL_TEXTURE_2D);

    glPushMatrix();
    glRotatef(-90.0f, +1.0f, 0.0f, 0.0f); // real 'world' coordinates
    glScalef(1.0f, 0.0f, 1.0f); // skip the y-coord (Lua's DrawScreen is perspective and so any z-coord in it influence the x&y, too)

    // draw the projectiles
    if (drawProjectiles) {
        glPointSize(1.0f);
        WorkaroundATIPointSizeBug();
        projectileDrawer->DrawProjectilesMiniMap();
    }

    // draw the queued commands
    //
    // NOTE: this needlessly adds to the CursorIcons list, but at least
    //       they are not drawn  (because the input receivers are drawn
    //       after the command queues)

    LuaUnsyncedCtrl::DrawUnitCommandQueues();
    if ((drawCommands > 0) && guihandler->GetQueueKeystate()) {
        selectedUnits.DrawCommands();
    }

    lineDrawer.DrawAll();

    // draw the selection shape, and some ranges
    if (drawCommands > 0) {
        guihandler->DrawMapStuff(!!drawCommands);
    }

    {
        GML_RECMUTEX_LOCK(sel); // DrawForReal

        // draw unit ranges
        const float radarSquare = radarhandler->radarDiv;
        CUnitSet& selUnits = selectedUnits.selectedUnits;
        for(CUnitSet::iterator si = selUnits.begin(); si != selUnits.end(); ++si) {
            CUnit* unit = *si;
            if (unit->radarRadius && !unit->beingBuilt && unit->activated) {
                glColor3fv(cmdColors.rangeRadar);
                DrawCircle(unit->pos, (unit->radarRadius * radarSquare));
            }
            if (unit->sonarRadius && !unit->beingBuilt && unit->activated) {
                glColor3fv(cmdColors.rangeSonar);
                DrawCircle(unit->pos, (unit->sonarRadius * radarSquare));
            }
            if (unit->jammerRadius && !unit->beingBuilt && unit->activated) {
                glColor3fv(cmdColors.rangeJammer);
                DrawCircle(unit->pos, (unit->jammerRadius * radarSquare));
            }
            // change if someone someday create a non stockpiled interceptor
            const CWeapon* w = unit->stockpileWeapon;
            if((w != NULL) && w->weaponDef->interceptor) {
                if (w->numStockpiled) {
                    glColor3fv(cmdColors.rangeInterceptorOn);
                } else {
                    glColor3fv(cmdColors.rangeInterceptorOff);
                }
                DrawCircle(unit->pos, w->weaponDef->coverageRange);
            }
        }
    }

    glPopMatrix(); // revert to the 2d xform

    if (!minimap->maximized) {
        // draw the camera frustum lines
        cam2->GetFrustumSides(0.0f, 0.0f, 1.0f, true);
        cam2->ClipFrustumLines(true, -10000.0f, 400096.0f);

        const std::vector<CCamera::FrustumLine>& negSides = cam2->negFrustumSides;
//		const std::vector<CCamera::FrustumLine>& posSides = cam2->posFrustumSides;
        std::vector<CCamera::FrustumLine>::const_iterator fli;

        CVertexArray* va = GetVertexArray();
        va->Initialize();
        va->EnlargeArrays(negSides.size() * 2, 0, VA_SIZE_2D0);

        for (fli = negSides.begin(); fli != negSides.end(); ++fli) {
            if (fli->minz < fli->maxz) {
                va->AddVertex2dQ0(fli->base + (fli->dir * fli->minz), fli->minz);
                va->AddVertex2dQ0(fli->base + (fli->dir * fli->maxz), fli->maxz);
            }
        }

        glLineWidth(2.5f);
        glColor4f(0, 0, 0, 0.5f);
        va->DrawArray2d0(GL_LINES);

        glLineWidth(1.5f);
        glColor4f(1, 1, 1, 0.75f);
        va->DrawArray2d0(GL_LINES);
        glLineWidth(1.0f);
    }


    // selection box
    glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
    CMouseHandler::ButtonPressEvt& bp = mouse->buttons[SDL_BUTTON_LEFT];
    if (selecting && fullProxy && (bp.movement > 4)) {
        const float3 oldPos = GetMapPosition(bp.x, bp.y);
        const float3 newPos = GetMapPosition(mouse->lastx, mouse->lasty);
        glColor4fv(cmdColors.mouseBox);
        glBlendFunc((GLenum)cmdColors.MouseBoxBlendSrc(),
                    (GLenum)cmdColors.MouseBoxBlendDst());
        glLineWidth(cmdColors.MouseBoxLineWidth());

        float verts[] = {
            oldPos.x, oldPos.z,
            newPos.x, oldPos.z,
            newPos.x, newPos.z,
            oldPos.x, newPos.z,
        };
        glEnableClientState(GL_VERTEX_ARRAY);
        glVertexPointer(2, GL_FLOAT, 0, verts);
        glDrawArrays(GL_LINE_LOOP, 0, 4);
        glDisableClientState(GL_VERTEX_ARRAY);

        glLineWidth(1.0f);
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    }

    DrawNotes();

    // reset 1
    if (resetTextureMatrix) {
        glMatrixMode(GL_TEXTURE_MATRIX);
        glPopMatrix();
    }
    glMatrixMode(GL_MODELVIEW);
    if (use_geo) {
        glPopMatrix();
    }

    // reset 2
    glPopMatrix();
    glPopAttrib();
    glEnable(GL_TEXTURE_2D);

    {
        //! prepare ClipPlanes for Lua's DrawInMinimap Modelview matrix

        //! quote from glClipPlane spec:
        //! "When glClipPlane is called, equation is transformed by the inverse of the modelview matrix and stored in the resulting eye coordinates.
        //!  Subsequent changes to the modelview matrix have no effect on the stored plane-equation components."
        //! -> we have to use the same modelview matrix when calling glClipPlane and later draw calls

        //! set the modelview matrix to the same as used in Lua's DrawInMinimap
        glPushMatrix();
        glLoadIdentity();
        glScalef(1.0f / width, 1.0f / height, 1.0f);

        const double plane0[4] = {0,-1,0,height};
        const double plane1[4] = {0,1,0,0};
        const double plane2[4] = {-1,0,0,width};
        const double plane3[4] = {1,0,0,0};

        glClipPlane(GL_CLIP_PLANE0, plane0); // clip bottom
        glClipPlane(GL_CLIP_PLANE1, plane1); // clip top
        glClipPlane(GL_CLIP_PLANE2, plane2); // clip right
        glClipPlane(GL_CLIP_PLANE3, plane3); // clip left

        glPopMatrix();
    }

    //! allow the LUA scripts to draw into the minimap
    eventHandler.DrawInMiniMap();

    if (use_geo && globalRendering->dualScreenMode)
        glViewport(globalRendering->viewPosX,0,globalRendering->viewSizeX,globalRendering->viewSizeY);

    //FIXME: Lua modifies the matrices w/o reseting it! (quite complexe to fix because ClearMatrixStack() makes it impossible to use glPushMatrix)
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluOrtho2D(0,1,0,1);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

    // disable ClipPlanes
    glDisable(GL_CLIP_PLANE0);
    glDisable(GL_CLIP_PLANE1);
    glDisable(GL_CLIP_PLANE2);
    glDisable(GL_CLIP_PLANE3);

    cursorIcons.Enable(true);
    setSurfaceCircleFunc(NULL);
    setSurfaceSquareFunc(NULL);
}
//------------------------------------------------------------------------------
// drawFunc()
//------------------------------------------------------------------------------
void LandingGear::drawFunc()
{
    // only do this if we don't have a rotary components
    if (haveRotary) return;

    GLfloat currentColor[4];
    GLfloat lw = 0;
    glGetFloatv(GL_CURRENT_COLOR, &currentColor[0]);
    glGetFloatv(GL_LINE_WIDTH, &lw);

    // draw the landing gear dependent on the gear state
    // gear is up
    if (gearState == 0) {
        glPushMatrix();
            glTranslatef(0, 1, 0);
            // the lines on the handle
            glColor3f(0,0,0);
            glBegin(GL_LINES);
                glVertex2f(-0.3f, -0.6f);
                glVertex2f(-0.3f, 0.6f);
                glVertex2f(-0.1f, -0.6f);
                glVertex2f(-0.1f, 0.6f);
                glVertex2f(0.1f, -0.6f);
                glVertex2f(0.1f, 0.6f);
                glVertex2f(0.3f, -0.6f);
                glVertex2f(0.3f, 0.6f);
            glEnd();
            if (inTransit) glColor3f(1, 0, 0);
            else glColor3f(0.9f, 0.9f, 0.9f);
            // the handle
            glBegin(GL_POLYGON);
                glVertex2f(-0.4f, -0.6f);
                glVertex2f(0.4f, -0.6f);
                glVertex2f(0.4f, 0.6f);
                glVertex2f(-0.4f, 0.6f);
            glEnd();
        glPopMatrix();
        // the arm
        glPushMatrix();
            glColor3f(0.3f, 0.3f, 0.3f);
            glBegin(GL_POLYGON);
                glVertex2f(-0.3f, 0);
                glVertex2f(0.3f, 0);
                glVertex2f(0.3f, 1);
                glVertex2f(-0.3f, 1);
            glEnd();
        glPopMatrix();
    }
    // gear is down
    if (gearState == 1) {
        glPushMatrix();
            glTranslatef(0, -1, 0);
            // the lines on the handle
            glColor3f(0,0,0);
            glBegin(GL_LINES);
                glVertex2f(-0.3f, -0.6f);
                glVertex2f(-0.3f, 0.6f);
                glVertex2f(-0.1f, -0.6f);
                glVertex2f(-0.1f, 0.6f);
                glVertex2f(0.1f, -0.6f);
                glVertex2f(0.1f, 0.6f);
                glVertex2f(0.3f, -0.6f);
                glVertex2f(0.3f, 0.6f);
            glEnd();
            if (inTransit) glColor3f(1, 0, 0);
            else glColor3f(0.9f, 0.9f, 0.9f);
            // the handle
            glBegin(GL_POLYGON);
                glVertex2f(-0.4f, -0.6f);
                glVertex2f(0.4f, -0.6f);
                glVertex2f(0.4f, 0.6f);
                glVertex2f(-0.4f, 0.6f);
            glEnd();
        glPopMatrix();
        // the arm
        glPushMatrix();
            glColor3f(0.3f, 0.3f, 0.3f);
            glBegin(GL_POLYGON);
                glVertex2f(-0.3f, 0);
                glVertex2f(0.3f, 0);
                glVertex2f(0.3f, -1);
                glVertex2f(-0.3f, -1);
            glEnd();
        glPopMatrix();
    }
    glColor4fv(currentColor);
    glLineWidth(lw);
}
Example #30
0
IGL_INLINE void igl::draw_floor_outline(const float * colorA, const float * colorB,
  const int GridSizeX,
  const int GridSizeY)
{
  const float SizeX = 0.5f*100./(double)GridSizeX;
  const float SizeY = 0.5f*100./(double)GridSizeY;
  float old_line_width =0;
  // old settings
  int old_lighting=0,old_color_material=0;
  glGetIntegerv(GL_LIGHTING,&old_lighting);
  glGetIntegerv(GL_COLOR_MATERIAL,&old_color_material);
  glDisable(GL_LIGHTING);

  // Set material
  const float black[] = {0.,0.,0.,1.};
  glMaterialfv(GL_FRONT, GL_AMBIENT, black);
  glMaterialfv(GL_FRONT, GL_DIFFUSE, black);
  glMaterialfv(GL_FRONT, GL_SPECULAR, black);
  glMaterialfv(GL_FRONT, GL_EMISSION, black);
  glMaterialf(GL_FRONT, GL_SHININESS,0);
  const bool use_lighting = false;
  if(use_lighting)
  {
    glEnable(GL_LIGHTING);
  }else
  {
    glDisable(GL_LIGHTING);
  }

  glLineWidth(2.0f);
  glBegin(GL_LINES);
  for (int x =-GridSizeX/2;x<=GridSizeX/2;++x)
  {
    if(x!=(GridSizeX/2))
    {
      for(int s = -1;s<2;s+=2)
      {
        int y = s*(GridSizeY/2);
        int cy = y==(GridSizeY/2) ? y-1 : y;
        if ((x+cy)&0x00000001) //modulo 2
        {
          glColor4fv(colorA);
          //glColor3f(1,0,0);
        }else
        {
          glColor4fv(colorB);
          //glColor3f(0,0,1);
        }
        glVertex3f((x+1)*SizeX,0,y*SizeY);
        glVertex3f(    x*SizeX,0,y*SizeY);
      }
    }
    if(x==-(GridSizeX/2) || x==(GridSizeX/2))
    {
      int cx = x==(GridSizeX/2) ? x-1 : x;
      for (int y =-GridSizeY/2;y<GridSizeY/2;++y)
      {
        if ((cx+y)&0x00000001) //modulo 2
        {
          glColor4fv(colorA);
          //glColor3f(1,0,0);
        }else
        {
          glColor4fv(colorB);
          //glColor3f(0,0,1);
        }
        glVertex3f(x*SizeX,0,(y+1)*SizeY);
        glVertex3f(x*SizeX,0,    y*SizeY);
      }
    }
  }
  glEnd();

  glGetFloatv(GL_LINE_WIDTH,&old_line_width);
  glLineWidth(old_line_width);
  (old_lighting ? glEnable(GL_LIGHTING) : glDisable(GL_LIGHTING));
  (old_color_material? glEnable(GL_COLOR_MATERIAL) : glDisable(GL_COLOR_MATERIAL));
}