示例#1
0
void VectorView::on_display()
{
  set_ortho_projection();
  glDisable(GL_LIGHTING);
  glDisable(GL_DEPTH_TEST);
  glDisable(GL_TEXTURE_1D);
  glPolygonMode(GL_FRONT_AND_BACK, pmode ? GL_LINE : GL_FILL);

  // initial grid point and grid step
  double gt = gs;
  if (hexa) gt *= sqrt(3.0)/2.0;

  double max_length = 0.0;

  // transform all vertices
  vec.lock_data();
  int i;
  int nv = vec.get_num_vertices();
  double4* vert = vec.get_vertices();
  double2* tvert = new double2[nv];

  for (i = 0; i < nv; i++)
  {
    tvert[i][0] = transform_x(vert[i][0]);
    tvert[i][1] = transform_y(vert[i][1]);

    // find max length of vectors
    double length = sqr(vert[i][2]) + sqr(vert[i][3]);
    if (length > max_length) max_length = length;
  }
  max_length = sqrt(max_length);

  // value range
  double min = range_min, max = range_max;
  if (range_auto) { min = vec.get_min_value(); max = vec.get_max_value(); }
  double irange = 1.0 / (max - min);
  // special case: constant solution
  if (fabs(min - max) < 1e-8) { irange = 1.0; min -= 0.5; }

  // draw all triangles
  int3* xtris = vec.get_triangles();

  if (mode != 1) glEnable(GL_TEXTURE_1D);
  glBindTexture(GL_TEXTURE_1D, gl_pallete_tex_id);
  glBegin(GL_TRIANGLES);
  glColor3f(0.95f, 0.95f, 0.95f);
  for (i = 0; i < vec.get_num_triangles(); i++)
  {
    double mag = sqrt(sqr(vert[xtris[i][0]][2]) + sqr(vert[xtris[i][0]][3]));
    glTexCoord2d((mag -min) * irange * tex_scale + tex_shift, 0.0);
    glVertex2d(tvert[xtris[i][0]][0], tvert[xtris[i][0]][1]);

    mag = sqrt(sqr(vert[xtris[i][1]][2]) + sqr(vert[xtris[i][1]][3]));
    glTexCoord2d((mag -min) * irange * tex_scale + tex_shift, 0.0);
    glVertex2d(tvert[xtris[i][1]][0], tvert[xtris[i][1]][1]);

    mag = sqrt(sqr(vert[xtris[i][2]][2]) + sqr(vert[xtris[i][2]][3]));
    glTexCoord2d((mag -min) * irange * tex_scale + tex_shift, 0.0);
    glVertex2d(tvert[xtris[i][2]][0], tvert[xtris[i][2]][1]);
  }
  glEnd();
  glDisable(GL_TEXTURE_1D);

  // draw all edges
  /*if (mode == 0) glColor3f(0.3, 0.3, 0.3);
  else*/ glColor3f(0.5, 0.5, 0.5);
  glBegin(GL_LINES);
  int3* edges = vec.get_edges();
  for (i = 0; i < vec.get_num_edges(); i++)
  {
    if (lines || edges[i][2] != 0)
    {
      glVertex2d(tvert[edges[i][0]][0], tvert[edges[i][0]][1]);
      glVertex2d(tvert[edges[i][1]][0], tvert[edges[i][1]][1]);
    }
  }
  glEnd();

  // draw dashed edges
  if (lines)
  {
    glEnable(GL_LINE_STIPPLE);
    glLineStipple(1, 0xCCCC);
    glBegin(GL_LINES);
    int2* dashes = vec.get_dashes();
    for (i = 0; i < vec.get_num_dashes(); i++)
    {
      glVertex2d(tvert[dashes[i][0]][0], tvert[dashes[i][0]][1]);
      glVertex2d(tvert[dashes[i][1]][0], tvert[dashes[i][1]][1]);
    }
    glEnd();
    glDisable(GL_LINE_STIPPLE);
  }

  // draw arrows
  if (mode != 2)
  {
    for (i = 0; i < vec.get_num_triangles(); i++)
    {
      double miny = 1e100;
      int idx, k, l1, l2, r2, r1, s;
      double lry, x;
      double mr, ml, lx, rx, xval, yval;

      double wh = output_height + gt, ww = output_width + gs;
      if ((tvert[xtris[i][0]][0] < -gs) && (tvert[xtris[i][1]][0] < -gs) && (tvert[xtris[i][2]][0] < -gs)) continue;
      if ((tvert[xtris[i][0]][0] >  ww) && (tvert[xtris[i][1]][0] >  ww) && (tvert[xtris[i][2]][0] >  ww)) continue;
      if ((tvert[xtris[i][0]][1] < -gt) && (tvert[xtris[i][1]][1] < -gt) && (tvert[xtris[i][2]][1] < -gt)) continue;
      if ((tvert[xtris[i][0]][1] >  wh) && (tvert[xtris[i][1]][1] >  wh) && (tvert[xtris[i][2]][1] >  wh)) continue;

      // find vertex with min y-coordinate
      for (k = 0; k < 3; k++)
        if (tvert[xtris[i][k]][1] < miny)
          miny = tvert[xtris[i][idx = k]][1];
      l1 = r1 = xtris[i][idx];
      l2 = xtris[i][n_vert(idx)];
      r2 = xtris[i][p_vert(idx)];

      // plane of x and y values on triangle
      double a[2], b[2], c[2], d[2];
      for (int n = 0; n < 2; n++)
      {
        a[n] = (tvert[l1][1] - tvert[l2][1])*(vert[r1][2 +n] - vert[r2][2+n]) - (vert[l1][2+n] - vert[l2][2+n])*(tvert[r1][1] - tvert[r2][1]);
        b[n] = (vert[l1][2+n] - vert[l2][2+n])*(tvert[r1][0] - tvert[r2][0]) - (tvert[l1][0] - tvert[l2][0])*(vert[r1][2+n] - vert[r2][2+n]);
        c[n] = (tvert[l1][0] - tvert[l2][0])*(tvert[r1][1] - tvert[r2][1]) - (tvert[l1][1] - tvert[l2][1])*(tvert[r1][0] - tvert[r2][0]);
        d[n] = -a[n] * tvert[l1][0] - b[n] * tvert[l1][1] - c[n] * vert[l1][2+n];
        a[n] /= c[n]; b[n] /= c[n]; d[n] /= c[n];
      }

      s = (int) ceil((tvert[l1][1] - gy)/gt);  // first step
      lry = gy + s*gt;
      bool shift = hexa && (s & 1);

      // if there are two points with min y-coordinate, switch to the next segment
      if ((tvert[l1][1] == tvert[l2][1]) || (tvert[r1][1] == tvert[r2][1]))
        if (tvert[l1][1] == tvert[l2][1])
          {l1 = l2; l2 = r2;}
        else if (tvert[r1][1] == tvert[r2][1])
          {r1 = r2; r2 = l2;}

      // slope of the left and right segment
      ml = (tvert[l1][0] - tvert[l2][0])/(tvert[l1][1] - tvert[l2][1]);
      mr = (tvert[r1][0] - tvert[r2][0])/(tvert[r1][1] - tvert[r2][1]);
      // x-coordinates of the endpoints of the first line
      lx = tvert[l1][0] + ml * (lry - (tvert[l1][1]));
      rx = tvert[r1][0] + mr * (lry - (tvert[r1][1]));

      if (lry < -gt)
      {
        k = (int) floor(-lry/gt);
        lry += gt * k;
        lx += k * ml * gt;
        rx += k * mr * gt;
      }

      // while we are in triangle
      while (((lry < tvert[l2][1]) || (lry < tvert[r2][1])) && (lry < wh))
      {
        // while we are in the segment
        while (((lry <= tvert[l2][1]) && (lry <= tvert[r2][1])) && (lry < wh))
        {
          double gz = gx;
          if (shift) gz -= 0.5*gs;
          s = (int) ceil((lx - gz)/gs);
          x = gz + s*gs;
          if (hexa) shift = !shift;

          if (x < -gs)
          {
            k = (int) floor(-x/gs);
            x += gs * k;
          }
          // go along the line
          while ((x < rx) && (x < ww))
          {
            // plot the arrow
            xval = -a[0]*x - b[0]*lry - d[0];
            yval = -a[1]*x - b[1]*lry - d[1];
            plot_arrow(x, lry, xval, yval, max, min, gs);
            x += gs;
          }
          // move to the next line
          lx += ml*gt;
          rx += mr*gt;
          lry += gt;
        }
        // change segment
        if (lry >= tvert[l2][1]) {
          l1 = l2; l2 = r2;
          ml = (tvert[l1][0] - tvert[l2][0])/(tvert[l1][1] - tvert[l2][1]);
          lx = tvert[l1][0] + ml * (lry - (tvert[l1][1]));
        }
        else {
          r1 = r2; r2 = l2;
          mr = (tvert[r1][0] - tvert[r2][0])/(tvert[r1][1] - tvert[r2][1]);
          rx = tvert[r1][0] + mr * (lry - (tvert[r1][1]));
        }
      }
    }
  }

  delete [] tvert;
  vec.unlock_data();
}
示例#2
0
/*
   A recursively called function capable of drawing the UI.
*/
static void mass_ui_draw(MASS_UI_WIN *windows, f64 gx, f64 gy, f64 gw, f64 gh, f64 fpw, f64 fph) {
    f64         ax, ay, aw, ah;
    f64         cgw, cgh;        /* changed width and height */

    /* draw the windows in order of link list */
    for (MASS_UI_WIN *cw = windows; cw; cw = (MASS_UI_WIN*)mass_ll_next(cw)) {
        glColor3f(cw->r, cw->g, cw->b);

        /* calculate absolute -1.0 to 1.0 coordinates with parent offset */
        ax = gx + cw->left * fpw;
        ay = gy + cw->top * fph;
        aw = ax + cw->width * fpw;
        ah = ay + cw->height * fph;

        /* if it is outside of parent space just dont draw any of it */
        if (ax > gw)
            continue;
        if (ay > gh)
            continue;

        /* if it extends outside of parent then clip it (but keep in mind clipping textures) */
        cgw = 1.0; /* default */
        if (aw > gw) {
            cgw = ((aw - gw) / fpw) / cw->width;
            cgw = 1.0 - cgw;
            //cgw = 1.0 - (aw - gw);  /* get pixel width delta */
            aw = gw;
            //cgw = cgw * .99;
        }

        cgh = 1.0; /* default */
        if (ah > gh) {
            cgh = ((ah - gh) / fph) / cw->height;
            cgh = 1.0 - cgh;
            ah = gh;
            //cgh = cgh * .99;
        }

        if (cw->bgimgpath) {
            /* if it can not load it the GLuint should be 0 */
            glEnable(GL_TEXTURE_2D);
            glBindTexture(GL_TEXTURE_2D, mass_ui_texman_diskload(cw->bgimgpath));
        } else {
            glDisable(GL_TEXTURE_2D);
        }

        /* draw the actual window */
        glBegin(GL_QUADS);
        glTexCoord2d(0.0, 0.0);   // 0, 0
        glVertex2d(ax, -ay);
        glTexCoord2d(cgw, 0.0);   // 1, 0
        glVertex2d(aw, -ay);
        glTexCoord2d(cgw, cgh);   // 1, 1
        glVertex2d(aw, -ah);
        glTexCoord2d(0.0, cgh);   // 0, 1
        glVertex2d(ax, -ah);
        glEnd();

        if (cw->text) {
            glColor3f(cw->tr, cw->tg, cw->tb);
            glRasterPos2d(ax, -ay - 8.0 * fph);

            for (int32 i = 0, x = 0; cw->text[x] != 0 && i < cw->width - 8; ++x, i += 8) {
                glutBitmapCharacter(GLUT_BITMAP_8_BY_13, cw->text[x]);
            }
        }
        mass_ui_draw(cw->children, ax, ay, aw, ah, fpw, fph);
    }
}
示例#3
0
void
dejongAttractor::update()
{
    if (!isSetup) {
        ofLog(OF_LOG_WARNING, "dja: update called but not yet setup");
        return;
    }

//    float cval = 0.04;//1.0/255.0;
    float cval = 1.0;
    ofDisableAlphaBlending();
    attractorFbo.begin();
    ofClear(0);
    attractorShader.begin();
    attractorShader.setUniform4f("color", cval, cval, cval, 0);
    attractorShader.setUniform1f("a", this->a);
    attractorShader.setUniform1f("b", this->b);
    attractorShader.setUniform1f("c", this->c);
    attractorShader.setUniform1f("d", this->d);
    attractorShader.setUniform1f("zoom", this->zoom);
    attractorShader.setUniform1i("nverts", this->shaderverts);
    
    ofEnableAlphaBlending();

    glBlendEquation(GL_FUNC_ADD);
// pre color blending
//    glBlendFunc(GL_ONE, GL_ONE);
    glBlendFuncSeparate(GL_ONE, GL_ZERO, GL_ONE, GL_ONE);
    
    vertvbo.draw(GL_POINTS, 0, this->nverts);
    
    attractorShader.end();
    attractorFbo.end();

    glDisable(GL_BLEND);
    
    drawFbo.begin();
    ofClear(0);
    drawShader.begin();
    drawShader.setUniformTexture("texmap", attractorFbo.getTextureReference(), 0);
    drawShader.setUniform1f("logmaxd", logmaxd);
    drawShader.setUniform1f("mindens", mindens);
    
    float w = attractorFbo.getWidth();
    float h = attractorFbo.getHeight();
    glBegin(GL_QUADS);
    glTexCoord2d(1, 1); glVertex2d(1, 1);
    glTexCoord2d(w, 1); glVertex2d(w, 1);
    glTexCoord2d(w, h); glVertex2d(w, h);
    glTexCoord2d(1, h); glVertex2d(1, h);
    glEnd();
    drawShader.end();
    drawFbo.end();
    
    if (useBlur) {
        glEnable(GL_POINT_SMOOTH);
        blurFbo.begin();
        ofClear(0);
        blurShader.begin();
        blurShader.setUniformTexture("texmap", drawFbo.getTextureReference(), 0);
        glBegin(GL_QUADS);
        glTexCoord2d(1, 1); glVertex2d(1, 1);
        glTexCoord2d(w, 1); glVertex2d(w, 1);
        glTexCoord2d(w, h); glVertex2d(w, h);
        glTexCoord2d(1, h); glVertex2d(1, h);
        glEnd();
        blurShader.end();
        blurFbo.end();
        glDisable(GL_POINT_SMOOTH);
    }
    dirty = false;
}
示例#4
0
void Game::draw() {
	glPushMatrix();
	glRotatef(ang + da, 0, 1, 0);
	glPushMatrix();
	glRotatef(225, 0, 1, 0);
	glScalef(3.0, 3.0, 3.0);
	glTranslatef(-2.5, 0, -2.5);
//	cout << selectorPos[0] << selectorPos[1] << endl;
//	cout << "over " << over << endl;
	if (over) {
		glPushMatrix();
		glTranslatef(0, 3, 2.5);
		glScalef(0.005, 0.005, 0.005);
		glColor3f(0.5, 0.5, 1.0);		// azul
		glutStrokeCharacter(GLUT_STROKE_ROMAN, 'P');
		glutStrokeCharacter(GLUT_STROKE_ROMAN, 'L');
		glutStrokeCharacter(GLUT_STROKE_ROMAN, 'A');
		glutStrokeCharacter(GLUT_STROKE_ROMAN, 'Y');
		glutStrokeCharacter(GLUT_STROKE_ROMAN, 'E');
		glutStrokeCharacter(GLUT_STROKE_ROMAN, 'R');
		glutStrokeCharacter(GLUT_STROKE_ROMAN, ' ');
		glutStrokeCharacter(GLUT_STROKE_ROMAN, '0' + over);
		glutStrokeCharacter(GLUT_STROKE_ROMAN, ' ');
		glutStrokeCharacter(GLUT_STROKE_ROMAN, 'W');
		glutStrokeCharacter(GLUT_STROKE_ROMAN, 'I');
		glutStrokeCharacter(GLUT_STROKE_ROMAN, 'N');
		glutStrokeCharacter(GLUT_STROKE_ROMAN, 'S');
		glPopMatrix();
		glPushMatrix();
		glTranslatef(5, 2, 2.5);
		glScalef(0.005, 0.005, 0.005);
		glRotatef(180, 0, 1, 0);
		glColor3f(0.5, 0.5, 1.0);		// azul
		glutStrokeCharacter(GLUT_STROKE_ROMAN, 'P');
		glutStrokeCharacter(GLUT_STROKE_ROMAN, 'L');
		glutStrokeCharacter(GLUT_STROKE_ROMAN, 'A');
		glutStrokeCharacter(GLUT_STROKE_ROMAN, 'Y');
		glutStrokeCharacter(GLUT_STROKE_ROMAN, 'E');
		glutStrokeCharacter(GLUT_STROKE_ROMAN, 'R');
		glutStrokeCharacter(GLUT_STROKE_ROMAN, ' ');
		glutStrokeCharacter(GLUT_STROKE_ROMAN, '0' + over);
		glutStrokeCharacter(GLUT_STROKE_ROMAN, ' ');
		glutStrokeCharacter(GLUT_STROKE_ROMAN, 'W');
		glutStrokeCharacter(GLUT_STROKE_ROMAN, 'I');
		glutStrokeCharacter(GLUT_STROKE_ROMAN, 'N');
		glutStrokeCharacter(GLUT_STROKE_ROMAN, 'S');
		glPopMatrix();

	}
//	end();
	if (state != 0 && !over)
		glPushName(-1);
	for (int i = 0; i < 5; ++i) {
		glPushMatrix();
		if (state != 0 && !over)
			glLoadName(i);

		for (int j = 0; j < 5; ++j) {
			glPushMatrix();
			glTranslatef(i, 0, j);
			glRotatef(90, 1, 0, 0);
			glTranslatef(0.1, 0.1, 0);
			glScalef(0.8, 0.8, 0.8);
			if (state != 0 && !over)
				glPushName(j);

			glBegin(GL_QUADS);
			glTexCoord2d(0, 0);
			glVertex3d(0, 0, 0);
			glTexCoord2d(0, 1);
			glVertex3d(0, 1, 0);
			glTexCoord2d(1, 1);
			glVertex3d(1, 1, 0);
			glTexCoord2d(1, 0);
			glVertex3d(1, 0, 0);

			glEnd();

			if (state != 0 && !over)
				glPopName();
			glPopMatrix();
		}
		glPopMatrix();
	}
	if (state != 0 && !over)
		glPopName();
	if (selected == true) {
		glPushMatrix();
		glTranslatef(selectorPos[0] + 0.5, 0.1, selectorPos[1] + 0.5);
		glRotatef(-90, 1, 0, 0);
		app->apply();
		GLUquadric *botD = gluNewQuadric();
		gluQuadricTexture(botD, GL_TRUE);
		gluDisk(botD, 0, 0.5, 20, 1);
		glPopMatrix();
	}
	if (state == 0 && !over) {
		glPushName(-1);
		for (unsigned int i = player; i < pawn.size(); ++i += 1) {
			glPushMatrix();
			glLoadName(i);
			pawn[i].draw();
			glPopMatrix();

		}
		glPopName();
		pawn[0].draw();
		for (unsigned int i = player - 1; i < pawn.size(); ++i += 1) {
			glPushMatrix();
			pawn[i].draw();
			glPopMatrix();

		}
	} else {
		for (unsigned int i = 0; i < pawn.size(); ++i) {
			glPushMatrix();
			pawn[i].draw();
			glPopMatrix();

		}
	}
	glPopMatrix();
}
示例#5
0
///Create a display list coresponding to the give character.
void make_dlist ( FT_Face face, char ch, GLuint list_base, GLuint * tex_base ) {

	//The first thing we do is get FreeType to render our character
	//into a bitmap.  This actually requires a couple of FreeType commands:

	//Load the Glyph for our character.
	if(FT_Load_Glyph( face, FT_Get_Char_Index( face, ch ), FT_LOAD_DEFAULT ))
		throw std::runtime_error("FT_Load_Glyph failed");

	//Move the face's glyph into a Glyph object.
    FT_Glyph glyph;
    if(FT_Get_Glyph( face->glyph, &glyph ))
		throw std::runtime_error("FT_Get_Glyph failed");

	//Convert the glyph to a bitmap.
	FT_Glyph_To_Bitmap( &glyph, ft_render_mode_normal, 0, 1 );
    FT_BitmapGlyph bitmap_glyph = (FT_BitmapGlyph)glyph;

	//This reference will make accessing the bitmap easier
	FT_Bitmap& bitmap=bitmap_glyph->bitmap;

	//Use our helper function to get the widths of
	//the bitmap data that we will need in order to create
	//our texture.
	int width = next_p2( bitmap.width );
	int height = next_p2( bitmap.rows );

	//Allocate memory for the texture data.
	GLubyte* expanded_data = new GLubyte[ 2 * width * height];

	//Here we fill in the data for the expanded bitmap.
	//Notice that we are using two channel bitmap (one for
	//luminocity and one for alpha), but we assign
	//both luminocity and alpha to the value that we
	//find in the FreeType bitmap. 
	//We use the ?: operator so that value which we use
	//will be 0 if we are in the padding zone, and whatever
	//is the the Freetype bitmap otherwise.
	for(int j=0; j <height;j++) {
		for(int i=0; i < width; i++){
            expanded_data[2*(i+j*width)] = 255;
			expanded_data[2*(i+j*width)+1] = 
				(i>=bitmap.width || j>=bitmap.rows) ?
				0 : bitmap.buffer[i + bitmap.width*j];
		}
	}


	//Now we just setup some texture paramaters.
    glBindTexture( GL_TEXTURE_2D, tex_base[ch]);
	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);

	//Here we actually create the texture itself, notice
	//that we are using GL_LUMINANCE_ALPHA to indicate that
	//we are using 2 channel data.
    glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, width, height,
		  0, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, expanded_data );

	//With the texture created, we don't need to expanded data anymore
    delete [] expanded_data;

	//So now we can create the display list
	glNewList(list_base+ch,GL_COMPILE);

	glBindTexture(GL_TEXTURE_2D,tex_base[ch]);

	//first we need to move over a little so that
	//the character has the right amount of space
	//between it and the one before it.
	glTranslatef(bitmap_glyph->left,0,0);

	//Now we move down a little in the case that the
	//bitmap extends past the bottom of the line 
	//(this is only true for characters like 'g' or 'y'.
	glPushMatrix();
	glTranslatef(0,bitmap_glyph->top-bitmap.rows,0);

	//Now we need to account for the fact that many of
	//our textures are filled with empty padding space.
	//We figure what portion of the texture is used by 
	//the actual character and store that information in 
	//the x and y variables, then when we draw the
	//quad, we will only reference the parts of the texture
	//that we contain the character itself.
	float	x=(float)bitmap.width / (float)width,
			y=(float)bitmap.rows / (float)height;

	//Here we draw the texturemaped quads.
	//The bitmap that we got from FreeType was not 
	//oriented quite like we would like it to be,
	//so we need to link the texture to the quad
	//so that the result will be properly aligned.
	glBegin(GL_QUADS);
	glTexCoord2d(0,0); glVertex2f(0,bitmap.rows);
	glTexCoord2d(0,y); glVertex2f(0,0);
	glTexCoord2d(x,y); glVertex2f(bitmap.width,0);
	glTexCoord2d(x,0); glVertex2f(bitmap.width,bitmap.rows);
	glEnd();
	glPopMatrix();
	glTranslatef(face->glyph->advance.x >> 6 ,0,0);


	//increment the raster position as if we were a bitmap font.
	//(only needed if you want to calculate text length)
	//glBitmap(0,0,0,0,face->glyph->advance.x >> 6,0,NULL);

	//Finnish the display list
	glEndList();
}
示例#6
0
文件: chunk.cpp 项目: eatfears/blocks
void Chunk::drawTile(const BlockInWorld &pos, Block* block, char side) const
{
    GLdouble
            x_coord = pos.bx - 0.5,
            y_coord = pos.by,
            z_coord = pos.bz - 0.5;

    GLdouble offset_x, offset_y;
    m_World.m_MaterialLib.getTextureOffsets(offset_x, offset_y, block->material, block->visible, side);

    static const GLdouble space = 0.002;
    switch(side)
    {
    case TOP:
    {
        Light::softLight(m_World, *this, pos, side, 0);
        glTexCoord2d(0.0625 - space + offset_x, 0.0 + space + offset_y);
        glVertex3d(x_coord, y_coord + 1, z_coord);

        Light::softLight(m_World, *this, pos, side, 1);
        glTexCoord2d(0.0 + space + offset_x, 0.0 + space + offset_y);
        glVertex3d(x_coord, y_coord + 1, z_coord + 1);

        Light::softLight(m_World, *this, pos, side, 2);
        glTexCoord2d(0.0 + space + offset_x, 0.0625 - space + offset_y);
        glVertex3d(x_coord + 1, y_coord + 1, z_coord + 1);

        Light::softLight(m_World, *this, pos, side, 3);
        glTexCoord2d(0.0625 - space + offset_x, 0.0625 - space + offset_y);
        glVertex3d(x_coord + 1, y_coord + 1, z_coord);
    }
        break;
    case BOTTOM:
    {
        Light::softLight(m_World, *this, pos, side, 4);
        glTexCoord2d(0.0625 - space + offset_x, 0.0 + space + offset_y);
        glVertex3d(x_coord, y_coord, z_coord);

        Light::softLight(m_World, *this, pos, side, 7);
        glTexCoord2d(0.0625 - space + offset_x, 0.0625 - space + offset_y);
        glVertex3d(x_coord + 1, y_coord, z_coord);

        Light::softLight(m_World, *this, pos, side, 6);
        glTexCoord2d(0.0 + space + offset_x, 0.0625 - space + offset_y);
        glVertex3d(x_coord + 1, y_coord, z_coord + 1);

        Light::softLight(m_World, *this, pos, side, 5);
        glTexCoord2d(0.0 + space + offset_x, 0.0 + space + offset_y);
        glVertex3d(x_coord, y_coord, z_coord + 1);
    }
        break;
    case RIGHT:
    {
        Light::softLight(m_World, *this, pos, side, 7);
        glTexCoord2d(0.0625 - space + offset_x, 0.0625 - space + offset_y);
        glVertex3d(x_coord + 1, y_coord, z_coord);

        Light::softLight(m_World, *this, pos, side, 3);
        glTexCoord2d(0.0625 - space + offset_x, 0.0 + space + offset_y);
        glVertex3d(x_coord + 1, y_coord + 1, z_coord);

        Light::softLight(m_World, *this, pos, side, 2);
        glTexCoord2d(0.0 + space + offset_x, 0.0 + space + offset_y);
        glVertex3d(x_coord + 1, y_coord + 1, z_coord + 1);

        Light::softLight(m_World, *this, pos, side, 6);
        glTexCoord2d(0.0 + space + offset_x, 0.0625 - space + offset_y);
        glVertex3d(x_coord + 1, y_coord, z_coord + 1);
    }
        break;
    case LEFT:
    {
        Light::softLight(m_World, *this, pos, side, 4);
        glTexCoord2d(0.0 + space + offset_x, 0.0625 - space + offset_y);
        glVertex3d(x_coord, y_coord, z_coord);

        Light::softLight(m_World, *this, pos, side, 5);
        glTexCoord2d(0.0625 - space + offset_x, 0.0625 - space + offset_y);
        glVertex3d(x_coord, y_coord, z_coord + 1);

        Light::softLight(m_World, *this, pos, side, 1);
        glTexCoord2d(0.0625 - space + offset_x, 0.0 + space + offset_y);
        glVertex3d(x_coord, y_coord + 1, z_coord + 1);

        Light::softLight(m_World, *this, pos, side, 0);
        glTexCoord2d(0.0 + space + offset_x, 0.0 + space + offset_y);
        glVertex3d(x_coord, y_coord + 1, z_coord);
    }
        break;
    case BACK:
    {
        Light::softLight(m_World, *this, pos, side, 5);
        glTexCoord2d(0.0 + space + offset_x, 0.0625 - space + offset_y);
        glVertex3d(x_coord, y_coord, z_coord + 1);

        Light::softLight(m_World, *this, pos, side, 6);
        glTexCoord2d(0.0625 - space + offset_x, 0.0625 - space + offset_y);
        glVertex3d(x_coord + 1, y_coord, z_coord + 1);

        Light::softLight(m_World, *this, pos, side, 2);
        glTexCoord2d(0.0625 - space + offset_x, 0.0 + space + offset_y);
        glVertex3d(x_coord + 1, y_coord + 1, z_coord + 1);

        Light::softLight(m_World, *this, pos, side, 1);
        glTexCoord2d(0.0 + space + offset_x, 0.0 + space + offset_y);
        glVertex3d(x_coord, y_coord + 1, z_coord + 1);
    }
        break;
    case FRONT:
    {
        Light::softLight(m_World, *this, pos, side, 4);
        glTexCoord2d(0.0625 - space + offset_x, 0.0625 - space + offset_y);
        glVertex3d(x_coord, y_coord, z_coord);

        Light::softLight(m_World, *this, pos, side, 0);
        glTexCoord2d(0.0625 - space + offset_x, 0.0 + space + offset_y);
        glVertex3d(x_coord, y_coord + 1, z_coord);

        Light::softLight(m_World, *this, pos, side, 3);
        glTexCoord2d(0.0 + space + offset_x, 0.0 + space + offset_y);
        glVertex3d(x_coord + 1, y_coord + 1, z_coord);

        Light::softLight(m_World, *this, pos, side, 7);
        glTexCoord2d(0.0 + space + offset_x, 0.0625 - space + offset_y);
        glVertex3d(x_coord + 1, y_coord, z_coord);
    }
        break;
    }
}
示例#7
0
int DrawGLScene(GLvoid)
{
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);//wyzerowanie bufora kolorow i glebokosci	
	glBindFramebuffer(GL_FRAMEBUFFER, FBO->OutName());//tu zaczynam FBO
	glLoadIdentity();

	//unsetShader();

	float proba = yrota / (180 * 90);

	glPushMatrix();
	glUseProgramObjectARB(0);
	glTranslated(0, -2, 0);
	glRotatef(xrota / 180, 0, 1 - proba, proba);
	glRotatef(yrota / 180, 1, 0, 0);

	
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	
	skyBox();
///--------------------------------------->	glUseProgramObjectARB(p);
 if(LIGHTS)
 	podstawowy_shader->Use();
	//system("pause");
	glPopMatrix();
	glTranslatef(-25, -30, ze);
	glRotatef(xrota / 180, 0, 1 - proba, proba);
	glRotatef(yrota / 180, 1, 0, 0);
	static float r = 0;
	glUniform3f(glGetUniformLocation(podstawowy_shader->Out(), "lightPos"), 40 + 50 * sin(r += 0.01), 50, 150);
	glUniform3f(glGetUniformLocation(podstawowy_shader->Out(), "mambient"), opcje[0], opcje[0], opcje[0]);
	glUniform3f(glGetUniformLocation(podstawowy_shader->Out(), "mdiffuse"), opcje[1], opcje[1], opcje[1]);
	glUniform3f(glGetUniformLocation(podstawowy_shader->Out(), "mspecular"), opcje[2], opcje[2], opcje[2]);
	glUniform3f(glGetUniformLocation(podstawowy_shader->Out(), "lambient"), opcje[0], opcje[0], opcje[0]);
	glUniform3f(glGetUniformLocation(podstawowy_shader->Out(), "ldiffuse"), opcje[1] * 2, opcje[1] * 2, opcje[1] * 2);
	glUniform3f(glGetUniformLocation(podstawowy_shader->Out(), "lspecular"), opcje[2] * 2, opcje[2] * 2, opcje[2] * 2);
	glUniform1f(glGetUniformLocation(podstawowy_shader->Out(), "shininess"), opcje[3] * 50);
	menu();	
	glBindFramebuffer(GL_FRAMEBUFFER, 0);
	glUseProgramObjectARB(0);
 if (BLOOM)
 {
  glBindFramebuffer(GL_FRAMEBUFFER, pingpong->OutNamePong()[0]);
  bright_shader->Use();
 }
	glActiveTexture(GL_TEXTURE0);
	
	glBindTexture(GL_TEXTURE_2D, FBO->OutColor());
	glUniform1i(glGetUniformLocation(bright_shader->Out(), "texture"), 0);
	glUniform2f(glGetUniformLocation(bright_shader->Out(), "pixelSize"), 1.0 / width, 1.0 / height);
	glLoadIdentity();
	glOrtho(-1, 1, -1, 1, 0, 1);
	glNormal3f(0.0, 0.0, 1.0);
	glBegin(GL_TRIANGLE_STRIP);//podobno wydajniej niz quad
	glNormal3f(0.0, 0.0, 1.0);
	glTexCoord2d(0, 0);	glVertex3d(-1.885, -0.965, 2.25);
	glTexCoord2d(1, 0); glVertex3d(1.915, -0.965, 2.25);
	glTexCoord2d(0, 1); glVertex3d(-1.885, 1.035, 2.25);
	glTexCoord2d(1, 1); glVertex3d(1.915, 1.035, 2.25);
	glEnd();

	glBindFramebuffer(GL_FRAMEBUFFER, 0);

 if (BLOOM)
 {
  blur_shader->Use();
  GLuint amount = 6;
  GLboolean horizontal = false, first_iteration = true;
  glActiveTexture(GL_TEXTURE1);
  glBindTexture(GL_TEXTURE_2D, FBO->OutDepth());
  glUniform1i(glGetUniformLocation(blur_shader->Out(), "depth"), 1);

  for (GLuint i = 0; i < amount; i++)
  {
   glBindFramebuffer(GL_FRAMEBUFFER, pingpong->OutNamePong()[horizontal]);
   glUniform1i(glGetUniformLocation(blur_shader->Out(), "horizontal"), horizontal);
   glActiveTexture(GL_TEXTURE0);
   glBindTexture(GL_TEXTURE_2D, first_iteration ? pingpong->OutColorPong()[0] : pingpong->OutColorPong()[!horizontal]);
   glUniform1i(glGetUniformLocation(blur_shader->Out(), "texture"), 0);


   //RENDER HERE
   glLoadIdentity();
   glOrtho(-1, 1, -1, 1, 0, 1);
   glNormal3f(0.0, 0.0, 1.0);
   glBegin(GL_TRIANGLE_STRIP);
   glNormal3f(0.0, 0.0, 1.0);
   glTexCoord2d(0, 0);	glVertex3d(-1.885, -0.965, 2.25);
   glTexCoord2d(1, 0); glVertex3d(1.915, -0.965, 2.25);
   glTexCoord2d(0, 1); glVertex3d(-1.885, 1.035, 2.25);
   glTexCoord2d(1, 1); glVertex3d(1.915, 1.035, 2.25);
   glEnd();
   //ENDRENDERINGUNG
   horizontal = !horizontal;
   if (first_iteration)
    first_iteration = false;
  }
  glBindFramebuffer(GL_FRAMEBUFFER, 0);
 }
	glLoadIdentity();
	glOrtho(-1, 1, -1, 1, 0, 1);

 if(BLOOM)
	 blend_shader->Use();


	glActiveTexture(GL_TEXTURE1);
	glBindTexture(GL_TEXTURE_2D, pingpong->OutColorPong()[1]);
 glActiveTexture(GL_TEXTURE0);
 glBindTexture(GL_TEXTURE_2D, FBO->OutColor());
	glUniform1i(glGetUniformLocation(blend_shader->Out(), "scene"), 0);
	glUniform1i(glGetUniformLocation(blend_shader->Out(), "bloomBlur"), 1);
	glNormal3f(0.0, 0.0, 1.0);
	glBegin(GL_TRIANGLE_STRIP);//podobno wydajniej niz quad
	glNormal3f(0.0, 0.0, 1.0);
	glTexCoord2d(0, 0);	glVertex3d(-1.885, -0.965, 2.25);
	glTexCoord2d(1, 0); glVertex3d(1.915, -0.965, 2.25);
	glTexCoord2d(0, 1); glVertex3d(-1.885, 1.035, 2.25);
	glTexCoord2d(1, 1); glVertex3d(1.915, 1.035, 2.25);
	glEnd();

	return 1;
}
示例#8
0
void GPU_framebuffer_blur(GPUFrameBuffer *fb, GPUTexture *tex, GPUFrameBuffer *blurfb, GPUTexture *blurtex)
{
	float scaleh[2] = {1.0f/GPU_texture_opengl_width(blurtex), 0.0f};
	float scalev[2] = {0.0f, 1.0f/GPU_texture_opengl_height(tex)};

	GPUShader *blur_shader = GPU_shader_get_builtin_shader(GPU_SHADER_SEP_GAUSSIAN_BLUR);
	int scale_uniform, texture_source_uniform;

	if (!blur_shader)
		return;

	scale_uniform = GPU_shader_get_uniform(blur_shader, "ScaleU");
	texture_source_uniform = GPU_shader_get_uniform(blur_shader, "textureSource");
		
	/* Blurring horizontally */

	/* We do the bind ourselves rather than using GPU_framebuffer_texture_bind() to avoid
	 * pushing unnecessary matrices onto the OpenGL stack. */
	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, blurfb->object);

	GPU_shader_bind(blur_shader);
	GPU_shader_uniform_vector(blur_shader, scale_uniform, 2, 1, (float *)scaleh);
	GPU_shader_uniform_texture(blur_shader, texture_source_uniform, tex);
	glViewport(0, 0, GPU_texture_opengl_width(blurtex), GPU_texture_opengl_height(blurtex));

	/* Peparing to draw quad */
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	glMatrixMode(GL_TEXTURE);
	glLoadIdentity();
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();

	glDisable(GL_DEPTH_TEST);

	GPU_texture_bind(tex, 0);

	/* Drawing quad */
	glBegin(GL_QUADS);
	glTexCoord2d(0, 0); glVertex2f(1, 1);
	glTexCoord2d(1, 0); glVertex2f(-1, 1);
	glTexCoord2d(1, 1); glVertex2f(-1, -1);
	glTexCoord2d(0, 1); glVertex2f(1, -1);
	glEnd();
		
	/* Blurring vertically */

	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb->object);
	glViewport(0, 0, GPU_texture_opengl_width(tex), GPU_texture_opengl_height(tex));
	GPU_shader_uniform_vector(blur_shader, scale_uniform, 2, 1, (float *)scalev);
	GPU_shader_uniform_texture(blur_shader, texture_source_uniform, blurtex);
	GPU_texture_bind(blurtex, 0);

	glBegin(GL_QUADS);
	glTexCoord2d(0, 0); glVertex2f(1, 1);
	glTexCoord2d(1, 0); glVertex2f(-1, 1);
	glTexCoord2d(1, 1); glVertex2f(-1, -1);
	glTexCoord2d(0, 1); glVertex2f(1, -1);
	glEnd();

	GPU_shader_unbind();
}
void CachedSvgItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
    if (painter->paintEngine()->type() != QPaintEngine::OpenGL &&
        painter->paintEngine()->type() != QPaintEngine::OpenGL2) {
        // Fallback to direct painting
        QGraphicsSvgItem::paint(painter, option, widget);
        return;
    }

    QRectF br = boundingRect();
    QTransform transform    = painter->worldTransform();
    qreal sceneScale        = transform.map(QLineF(0, 0, 1, 0)).length();

    bool stencilTestEnabled = glIsEnabled(GL_STENCIL_TEST);
    bool scissorTestEnabled = glIsEnabled(GL_SCISSOR_TEST);

    painter->beginNativePainting();

    if (stencilTestEnabled) {
        glEnable(GL_STENCIL_TEST);
    }
    if (scissorTestEnabled) {
        glEnable(GL_SCISSOR_TEST);
    }

    bool dirty = false;
    if (!m_texture) {
        glGenTextures(1, &m_texture);
        m_context = const_cast<QGLContext *>(QGLContext::currentContext());

        dirty     = true;
    }

    if (!qFuzzyCompare(sceneScale, m_scale)) {
        m_scale = sceneScale;
        dirty   = true;
    }

    int textureWidth  = (int(br.width() * m_scale) + 3) & ~3;
    int textureHeight = (int(br.height() * m_scale) + 3) & ~3;

    if (dirty) {
        // qDebug() << "re-render image";

        QImage img(textureWidth, textureHeight, QImage::Format_ARGB32);
        {
            img.fill(Qt::transparent);
            QPainter p;
            p.begin(&img);
            p.setRenderHints(painter->renderHints());
            p.translate(br.topLeft());
            p.scale(m_scale, m_scale);
            QGraphicsSvgItem::paint(&p, option, 0);
            p.end();

            img = img.rgbSwapped();
        }

        glEnable(GL_TEXTURE_2D);

        glBindTexture(GL_TEXTURE_2D, m_texture);
        glTexImage2D(
            GL_TEXTURE_2D,
            0,
            GL_RGBA,
            textureWidth,
            textureHeight,
            0,
            GL_RGBA,
            GL_UNSIGNED_BYTE,
            img.bits());

        glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
        glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
        glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
        glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

        glDisable(GL_TEXTURE_2D);

        dirty = false;
    }

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

    glBindTexture(GL_TEXTURE_2D, m_texture);

    // texture may be slightly large than svn image, ensure only used area is rendered
    qreal tw = br.width() * m_scale / textureWidth;
    qreal th = br.height() * m_scale / textureHeight;

    glBegin(GL_QUADS);
    glTexCoord2d(0, 0); glVertex3d(br.left(), br.top(), -1);
    glTexCoord2d(tw, 0); glVertex3d(br.right(), br.top(), -1);
    glTexCoord2d(tw, th); glVertex3d(br.right(), br.bottom(), -1);
    glTexCoord2d(0, th); glVertex3d(br.left(), br.bottom(), -1);
    glEnd();
    glDisable(GL_TEXTURE_2D);

    painter->endNativePainting();
}
示例#10
0
void Font::makeDisplayList(FT_Face face, char ch) {
    // Load Glyph for character
    if (FT_Load_Glyph(face, FT_Get_Char_Index(face, ch), FT_LOAD_DEFAULT))
        throw std::runtime_error("FT_Load_Glyph failed");

    // Move Glyph into object
    FT_Glyph glyph;
    if (FT_Get_Glyph(face->glyph, &glyph))
        throw std::runtime_error("FT_Get_Glyph failed");

    // Convert Glyph to Bitmap
    FT_Glyph_To_Bitmap(&glyph, ft_render_mode_normal, 0, 1);
    FT_BitmapGlyph bitmap_glyph = (FT_BitmapGlyph)glyph;
    FT_Bitmap &bitmap = bitmap_glyph->bitmap;

    // Resize to OpenGL power of 2 and two channels (luminosity and alpha)
    int width = nextPow2(bitmap.width);
    int height = nextPow2(bitmap.rows);
    GLubyte *expandedData = new GLubyte[2 * width * height];
    for (int y = 0; y < height; y++) {
        for (int x = 0; x < width; x++) {
            int pos = 2 * (x + y*width);
            expandedData[pos] = expandedData[pos+1] =
                                    (x >= bitmap.width || y >= bitmap.rows) ?
                                    0 : bitmap.buffer[x + bitmap.width * y];
        }
    }

    // Create OpenGL texture
    glBindTexture(GL_TEXTURE_2D, m_textures[ch]);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0,
                 GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, expandedData);

    delete[] expandedData;

    // Now we create the Display List
    glNewList(m_displayLists+ch, GL_COMPILE);
    glBindTexture(GL_TEXTURE_2D, m_textures[ch]);
    glPushMatrix();

    // Center character correctly
    glTranslatef(bitmap_glyph->left, 0, 0);
    glTranslatef(0, bitmap_glyph->top - bitmap.rows, 0);

    // Calculate real size versus padding space
    float x = float(bitmap.width) / float(width);
    float y = float(bitmap.rows) / float(height);

    // Draw the quad
    glBegin(GL_QUADS);
    glTexCoord2d(0, 0);
    glVertex2f(0, bitmap.rows);
    glTexCoord2d(0, y);
    glVertex2f(0, 0);
    glTexCoord2d(x, y);
    glVertex2f(bitmap.width, 0);
    glTexCoord2d(x, 0);
    glVertex2f(bitmap.width, bitmap.rows);
    glEnd();
    glPopMatrix();
    glTranslatef(face->glyph->advance.x >> 6, 0, 0);

    // Increment the raster position as if it were a bitmap font
    // glBitmap(0, 0, 0, 0, face->glyph->advance.x >> 6, 0, NULL);

    glEndList();
}
示例#11
0
文件: Renderer.cpp 项目: jnz/Lynx
// gets called every frame to draw the scene
void CRenderer::Update(const float dt, const uint32_t ticks)
{
    CObj* obj, *localctrl;
    int localctrlid;
    OBJITER iter;
    matrix_t m;
    vec3_t dir, up, side;
    CFrustum frustum;
    CWorld* world;

    localctrl = m_world->GetLocalController();
    localctrlid = m_world->GetLocalObj()->GetID();
    world = m_world->GetInterpWorld();

    const vec3_t campos = localctrl->GetOrigin();
    const quaternion_t camrot = localctrl->GetRot();

    m.SetCamTransform(campos, camrot);
    m.GetVec3Cam(&dir, &up, &side);
    dir = -dir;
    frustum.Setup(campos, dir, up, side,
                  RENDERER_FOV, (float)m_width/(float)m_height,
                  PLANE_NEAR,
                  PLANE_FAR);

    // light floating above the players head
    const vec3_t lightpos0(campos + vec3_t(0,25.0f,0));
    const quaternion_t lightrot0(quaternion_t(vec3_t::xAxis, -90.0f*lynxmath::DEGTORAD));
    const float lightpos0_4f[4] = {lightpos0.x, lightpos0.y, lightpos0.z, 1};
    glLightfv(GL_LIGHT0, GL_POSITION, lightpos0_4f);
    if(m_shaderactive)
    {
        if(m_useShadows)
        {
            glUseProgram(0); // draw shadowmap with fixed function pipeline
            PrepareShadowMap(lightpos0,
                    lightrot0,
                    world,
                    localctrlid); // the player is the light
        }
        glUseProgram(m_program); // activate shader
    }

    glMatrixMode(GL_MODELVIEW);
    glLoadMatrixf(m.pm);

    glClear(GL_DEPTH_BUFFER_BIT);
    glClear(GL_COLOR_BUFFER_BIT);

    glActiveTexture(GL_TEXTURE0); // normal texture channel

    if(m_shaderactive)
    {
        glUniform1i(m_tex, 0); // good old textures: GL_TEXTURE0
        glUniform1i(m_normalMap, 1); // normal maps are GL_TEXTURE1
        glUniform1i(m_lightmap, 2); // lightmap

        if(m_useShadows)
        {
            glUniform1i(m_shadowMapUniform, 7);
            glActiveTexture(GL_TEXTURE7); // shadow mapping texture GL_TEXTURE7
            glBindTexture(GL_TEXTURE_2D, m_depthTextureId);
            glActiveTexture(GL_TEXTURE0);
        }

#ifdef DRAW_NORMALS
        glUseProgram(0); // use fixed pipeline for this debug mode
#endif
    }

    // Main drawing
    DrawScene(frustum, world, localctrlid, false);

    if(m_shaderactive)
        glUseProgram(0); // don't use shader for particles

    // Particle Draw
    glDisable(GL_LIGHTING);
    glDepthMask(false);
    for(iter=world->ObjBegin();iter!=world->ObjEnd();++iter)
    {
        obj = (*iter).second;

        if(obj->GetMesh())
        {
            // Animate mesh is done in the particle loop
            // and not in DrawScene, because DrawScene
            // can be called multiple times per frame
            obj->GetMesh()->Animate(obj->GetMeshState(), dt);
        }

        if(obj->GetID() == localctrlid || !obj->GetParticleSystem())
            continue;

        // Update/animate the particles, depending on dt and the current position.
        obj->GetParticleSystem()->Update(dt, ticks, obj->GetOrigin());

        // Draw the particles. FIXME: this should use a frustum test
        obj->GetParticleSystem()->Render(side, up, dir);
    }
    glDepthMask(true);
    glColor4f(1,1,1,1);
    glEnable(GL_LIGHTING);

#ifdef DRAW_NORMALS
    // Draw vertex normals of level geometry (not face normals)
    if(world && world->GetBSP())
    {
        glDisable(GL_DEPTH_TEST);
        glDisable(GL_LIGHTING);
        world->GetBSP()->RenderNormals();
        glEnable(GL_LIGHTING);
        glEnable(GL_DEPTH_TEST);
    }
#endif

    // Draw weapon
    if(m_shaderactive) // use shader for weapon
        glUseProgram(m_program);

    CModelMD5* viewmodel;
    md5_state_t* viewmodelstate;
    m_world->m_hud.GetModel(&viewmodel, &viewmodelstate);
    glDisable(GL_LIGHTING);
    if(viewmodel)
    {
        glClear(GL_DEPTH_BUFFER_BIT);
        glPushMatrix();
          glLoadIdentity();
          viewmodel->Render(viewmodelstate);
          viewmodel->Animate(viewmodelstate, dt);
        glPopMatrix();
    }
    glEnable(GL_LIGHTING);

    // Draw HUD
    if(m_shaderactive)
        glUseProgram(0); // no shader for HUD

    glDisable(GL_DEPTH_TEST);
    glDisable(GL_LIGHTING);
    glMatrixMode(GL_PROJECTION);
    glPushMatrix();
    glLoadIdentity();
    glOrtho(0, m_width, m_height, 0, 0, 1);
    glMatrixMode(GL_MODELVIEW);
    glPushMatrix();
    glLoadIdentity();
    glColor4f(1,1,1,1);
    glBindTexture(GL_TEXTURE_2D, m_crosshair);

    // Draw center crosshair
    glBegin(GL_QUADS);
        glTexCoord2d(0,1);
        glVertex3f((m_width-m_crosshair_width)*0.5f, (m_height-m_crosshair_height)*0.5f,0.0f);
        glTexCoord2d(0,0);
        glVertex3f((m_width-m_crosshair_width)*0.5f, (m_height+m_crosshair_height)*0.5f,0.0f);
        glTexCoord2d(1,0);
        glVertex3f((m_width+m_crosshair_width)*0.5f, (m_height+m_crosshair_height)*0.5f,0.0f);
        glTexCoord2d(1,1);
        glVertex3f((m_width+m_crosshair_width)*0.5f, (m_height-m_crosshair_height)*0.5f,0.0f);
    glEnd();

    // draw HUD text: score, health...
    char hudtextbuf[64];
    sprintf(hudtextbuf, "Frags: %i", m_world->m_hud.score);
    m_font.DrawGL(10.0f, m_height - 30.0f, 0.0f, hudtextbuf);
    sprintf(hudtextbuf, "%i", m_world->m_hud.health);
    m_font.DrawGL(10.0f, m_height - 35.0f - (float)m_font.GetHeight(), 0.0f, hudtextbuf);

#ifdef DRAW_SHADOWMAP // draw a small window with the scene from the light POV
    if(m_shaderactive)
    {
        //glBindTexture(GL_TEXTURE_2D, m_depthTextureId);
        glBindTexture(GL_TEXTURE_2D, g_fboShadowCamColor);
        const float shadowmap_debug_width = 200.0f;
        const float shadowmap_debug_height = shadowmap_debug_width*(float)m_height/(float)m_width;
        glBegin(GL_QUADS);
            glTexCoord2d(0,1); // upper left
            glVertex3f(0.0f, 0.0f, 0.0f);
            glTexCoord2d(0,0); //lower left
            glVertex3f(0.0f, shadowmap_debug_height, 0.0f);
            glTexCoord2d(1,0); //lower right
            glVertex3f(shadowmap_debug_width, shadowmap_debug_height, 0.0f);
            glTexCoord2d(1,1); // upper right
            glVertex3f(shadowmap_debug_width, 0.0f, 0.0f);
        glEnd();
    }
#endif

    glBindTexture(GL_TEXTURE_2D, 0);
    glMatrixMode(GL_PROJECTION);
    glPopMatrix();
    glMatrixMode(GL_MODELVIEW);
    glPopMatrix();
    glEnable(GL_LIGHTING);
    glEnable(GL_DEPTH_TEST);
}
示例#12
0
GLvoid DrawSphere(float R, int nDivs)
{
	if(R < 0 || nDivs <= 1)
		return;
	int nLat = 2 * nDivs;
	int nLon = 4 * nDivs;
	float
		u = 0, v = 0, v0 = 0, du = 1.0f/nLon, dv = 1.0f/nLat, 
		N[3], 
		lat = -0.5*PI, lon = 0, r = 0, r0 = 0, 
		dlat = PI/nLat, dlon = 2*PI/nLon,
		clat, slat, 
		clat0 = 0, slat0 = -1;
	bool bStart = true, bEnd = false;
	glBegin(GL_TRIANGLE_STRIP); // Start Drawing Quads
	for(int i = 0; i < nLat; i++)
	{
		// lat update
		if( i == nLat - 1 )
		{
			bEnd = true;
			r = 0;
			lat = 0.5*PI;
			clat = 0;
			slat = 1;
		}
		else
		{
			r = min(nLat - i - 1, i + 1) * dv;
			lat += dlat;
			clat = cosf(lat);
			slat = sinf(lat);
		}
		
		float u0 = 0, lon = 0, u = 0;

		N[0] = clat0;
		N[1] = 0;
		N[2] = slat0;
		glNormal3d(N[0], N[1], N[2]);
		glTexCoord2d(0.5f + r0, 0.5f);
		glVertex3d(N[0]*R, N[1]*R, N[2]*R);

		N[0] = clat;
		N[1] = 0;
		N[2] = slat;
		glNormal3d(N[0], N[1], N[2]);
		glTexCoord2d(0.5f + r, 0.5f);
		glVertex3d(N[0]*R, N[1]*R, N[2]*R);

		bool bEven = true;
		for(int j = 0; j < nLon; j++)
		{
			// lon update
			float clon, slon;
			if( j == nLon - 1 )
			{
				u = 1;
				lon = 2*PI;
				clon = 1;
				slon = 0;
			}
			else
			{
				u += du;
				lon += dlon;
				clon = cosf(lon);
				slon = sinf(lon);
			}
			
			///////////////////////////////////////////
			// 
			//		(u, v+dv)	(u+du, v+dv)
			//		P3----------P2	lat
			//		|			|
			//		|			|	/\
			//		|			|
			//		P0----------P1	lat0
			//		(u, v)		(u+du, v)	
			//		lon0	>	lon
			//
			///////////////////////////////////////////
			
			bEven = !bEven;
			if( !bStart || bEven )
			{
				N[0] = clon*clat0;
				N[1] = slon*clat0;
				N[2] = slat0;
				glNormal3d(N[0], N[1], N[2]);
				glTexCoord2d(0.5f + r0 * clon, 0.5f + r0 * slon);
				glVertex3d(N[0]*R, N[1]*R, N[2]*R);
			}

			if( !bEnd || bEven )
			{
				N[0] = clon*clat;
				N[1] = slon*clat;
				N[2] = slat;
				glNormal3d(N[0], N[1], N[2]);
				glTexCoord2d(0.5f + r * clon, 0.5f + r * slon);
				glVertex3d(N[0]*R, N[1]*R, N[2]*R);
			}
		}
		clat0 = clat;
		slat0 = slat;
		v0 = v;
		r0 = r;
		bStart = false;
	}
	glEnd();
}
示例#13
0
文件: vGL.c 项目: gfacciol/omniflip
void display()
{
   ImObj current = Controller.curr;
   float zoom = Controller.GZOOM;


   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);


   glMatrixMode (GL_PROJECTION);
   glLoadIdentity ();
   glOrtho (0, current.w*zoom, current.h*zoom, 0, -1, 1);
   glMatrixMode (GL_MODELVIEW);



   if(1){

      // TODO: THE TEXTURE DOES NOT NEED TO BE CREATED AND DESTROYED AT EACH DISPLAY CYCLE
      // allocate a texture name
      GLuint texture;
      glGenTextures( 1, &texture);

      // select our current texture
      glBindTexture( GL_TEXTURE_2D, texture );

      // select modulate to mix texture with color for shading
      glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
      // when texture area is small, bilinear filter the closest mipmap
      glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
      // when texture area is large, bilinear filter the first mipmap
      glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);


      float* data2   = current.x;
      int width      = current.w;
      int height     = current.h;

      // SCALE THE RANGE

      glPixelTransferf( GL_RED_BIAS,   Controller.GSHIFT);
      glPixelTransferf( GL_GREEN_BIAS, Controller.GSHIFT);
      glPixelTransferf( GL_BLUE_BIAS,  Controller.GSHIFT);

      glPixelTransferf( GL_RED_SCALE,   1./Controller.GSCALE);
      glPixelTransferf( GL_GREEN_SCALE, 1./Controller.GSCALE);
      glPixelTransferf( GL_BLUE_SCALE,  1./Controller.GSCALE);

      // build our texture mipmaps
      if(current.dim ==3)
           glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width,height, 0, GL_RGB, GL_FLOAT, data2);
//         gluBuild2DMipmaps( GL_TEXTURE_2D, 3, width, height, GL_RGB , GL_FLOAT, data2 );
      if(current.dim ==1)
           glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, width,height, 0, GL_LUMINANCE, GL_FLOAT, data2);
//         gluBuild2DMipmaps( GL_TEXTURE_2D, 3, width, height, GL_LUMINANCE , GL_FLOAT, data2 );
      if(current.dim ==4)
           glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width,height, 0, GL_RGBA, GL_FLOAT, data2);
//         gluBuild2DMipmaps( GL_TEXTURE_2D, 3, width, height, GL_RGBA , GL_FLOAT, data2 );
      if(current.dim ==2)
           glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE_ALPHA, width,height, 0, GL_LUMINANCE_ALPHA, GL_FLOAT, data2);
 //        gluBuild2DMipmaps( GL_TEXTURE_2D, 3, width, height, GL_LUMINANCE_ALPHA , GL_FLOAT, data2 );  



      glEnable( GL_TEXTURE_2D );
      glBegin( GL_QUADS );
      glColor3f(1.0, 1.0, 1.0);
      glTexCoord2d(0.0,0.0); glVertex3d(0,0,0);
      glTexCoord2d(1.0,0.0); glVertex3d(width *zoom,0,0);
      glTexCoord2d(1.0,1.0); glVertex3d(width *zoom ,height*zoom,0);
      glTexCoord2d(0.0,1.0); glVertex3d(0,height*zoom,0);
      glEnd();
      glDisable( GL_TEXTURE_2D );
      glDeleteTextures( 1, &texture );
   }

   // write text
   if(0){
      //  glClear(GL_COLOR_BUFFER_BIT);
      char teststr[1024];
      //glClearColor(0, 0, 0, 1);
      glColor3f(0.0, 1.0, 0.0);

      glPushMatrix();

      glTranslatef(-.5, -.5, 0);

      sprintf(teststr, "Keys 1 to 6 display objects");
      outputText(0.,0.,teststr);

      glPopMatrix();

   }


   glutSwapBuffers();
}
示例#14
0
void DebugDrawing3D::draw2()
{
  glPushAttrib(GL_ENABLE_BIT | GL_LIGHTING_BIT);
  glPushMatrix();

  if(flip)
    glRotated(180.f, 0, 0, 1);

  // Convert mm to m.
  glScaled(0.001, 0.001, 0.001);

  // Custom scaling.
  glScaled(scaleX, scaleY, scaleZ);

  // Custom rotation.
  if(rotateX != 0) glRotated(toDegrees(rotateX), 1, 0, 0);
  if(rotateY != 0) glRotated(toDegrees(rotateY), 0, 1, 0);
  if(rotateZ != 0) glRotated(toDegrees(rotateZ), 0, 0, 1);

  // Custom translation.
  glTranslated(transX, transY, transZ);

  //
  //glDisable(GL_LIGHTING);
  glEnable(GL_NORMALIZE);
  glEnable(GL_BLEND);
  glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

  // Draw all polygons/triangles.
  std::vector<Polygon>::iterator p;
  for(p = polygons.begin(); p != polygons.end(); ++p)
  {
    glColor4ub(p->color.r, p->color.g, p->color.b, p->color.a);
    glBegin(GL_TRIANGLES);
    glVertex3d(p->points[0].x, p->points[0].y, p->points[0].z);
    glVertex3d(p->points[1].x, p->points[1].y, p->points[1].z);
    glVertex3d(p->points[2].x, p->points[2].y, p->points[2].z);
    glEnd();
  }

  // Draw all lines.
  if(!lines.empty())
  {
    glPushAttrib(GL_LINE_BIT);
    std::vector<Line>::iterator l;
    for(l = lines.begin(); l != lines.end(); ++l)
    {
      glLineWidth(l->width);
      glColor4ub(l->color.r, l->color.g, l->color.b, l->color.a);
      glBegin(GL_LINES);
      glVertex3d(l->points[0].x, l->points[0].y, l->points[0].z);
      glVertex3d(l->points[1].x, l->points[1].y, l->points[1].z);
      glEnd();
    }
    glPopAttrib();
  }

  // Draw all points.
  if(!dots.empty())
  {
    glPushAttrib(GL_POINT_BIT);
    std::vector<Dot>::iterator d;
    for(d = dots.begin(); d != dots.end(); ++d)
    {
      // Since each point may have a different size we can't handle all
      // points in a single glBegin(GL_POINTS).
      // ( glPointSize is not allowed in a glBegin(...). )
      glPointSize(d->width);
      glColor4ub(d->color.r, d->color.g, d->color.b, d->color.a);
      glBegin(GL_POINTS);
      glVertex3d(d->point.x, d->point.y, d->point.z);
      glEnd();
    }
    glPopAttrib();
  }

  // draw spheres
  std::vector<Sphere>::iterator s;
  for(s = spheres.begin(); s != spheres.end(); ++s)
  {
    glColor4ub(s->color.r, s->color.g, s->color.b, s->color.a);
    glPushMatrix();
    glTranslated(s->point.x, s->point.y, s->point.z);
    GLUquadric* q = gluNewQuadric();
    gluSphere(q, s->radius, 16, 16);
    gluDeleteQuadric(q);
    glPopMatrix();
  }

  // draw cylinders
  std::vector<Cylinder>::iterator c;
  for(c = cylinders.begin(); c != cylinders.end(); ++c)
  {
    glColor4ub(c->color.r, c->color.g, c->color.b, c->color.a);

    glPushMatrix();
    glTranslated(c->point.x, c->point.y, c->point.z);
    if(c->rotation.x != 0)
      glRotated(toDegrees(c->rotation.x), 1, 0, 0);
    if(c->rotation.y != 0)
      glRotated(toDegrees(c->rotation.y), 0, 1, 0);
    if(c->rotation.z != 0)
      glRotated(toDegrees(c->rotation.z), 0, 0, 1);
    glTranslated(0, 0, -c->height / 2);
    GLUquadric* q = gluNewQuadric();
    gluCylinder(q, c->baseRadius, c->topRadius, c->height, 16, 1);
    glRotated(180, 0, 1, 0);
    if(c->baseRadius > 0.f)
      gluDisk(q, 0, c->baseRadius, 16, 1);
    glRotated(180, 0, 1, 0);
    glTranslated(0, 0, c->height);
    if(c->topRadius > 0.f)
      gluDisk(q, 0, c->topRadius, 16, 1);
    gluDeleteQuadric(q);
    glPopMatrix();
  }

  // Draw all quads.
  std::vector<Quad>::iterator q;
  for(q = quads.begin(); q != quads.end(); ++q)
  {
    glColor4ub(q->color.r, q->color.g, q->color.b, q->color.a);
    glBegin(GL_QUADS);

    const Vector3<>& p1 = q->points[0];
    const Vector3<>& p2 = q->points[1];
    const Vector3<>& p3 = q->points[2];
    const Vector3<>& p4 = q->points[3];
    Vector3<> u(p2.x - p1.x, p2.y - p1.y, p2.z - p1.z);
    Vector3<> v(p3.x - p1.x, p3.y - p1.y, p3.z - p1.z);
    Vector3<> n(u.y * v.z - u.z * v.y, u.z * v.x - u.x * v.z, u.x * v.y - u.y * v.x);
    n.normalize();

    glNormal3fv(&n.x);
    glVertex3fv(&p1.x);
    glVertex3fv(&p2.x);
    glVertex3fv(&p3.x);
    glVertex3fv(&p4.x);
    glEnd();
  }

  // draw 3d images
  if(!images.empty())
  {
    glPushAttrib(GL_TEXTURE_BIT);
    glDisable(GL_CULL_FACE);
    glEnable(GL_TEXTURE_2D);
    glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
    std::vector<Image3D>::iterator i;
    for(i = images.begin(); i != images.end(); ++i)
    {
      GLuint t;
      glGenTextures(1, &t);
      glBindTexture(GL_TEXTURE_2D, t);

      int width, height;
      char* imageData = copyImage(*i->image, width, height);
      glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB,
                   width, height,
                   0, GL_RGB, GL_UNSIGNED_BYTE, imageData);

      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
      delete [] imageData;

      glPushMatrix();
      glTranslated(i->point.x, i->point.y, i->point.z);
      if(i->rotation.x != 0)
        glRotated(toDegrees(i->rotation.x), 1, 0, 0);
      if(i->rotation.y != 0)
        glRotated(toDegrees(i->rotation.y), 0, 1, 0);
      if(i->rotation.z != 0)
        glRotated(toDegrees(i->rotation.z), 0, 0, 1);
      glBegin(GL_QUADS);
      float right = (float) i->image->resolutionWidth / width;
      float top = (float) i->image->resolutionHeight / height;
      glTexCoord2d(right, top);
      glVertex3d(0, -i->width / 2, i->height / 2);
      glTexCoord2d(0, top);
      glVertex3d(0, i->width / 2, i->height / 2);
      glTexCoord2d(0, 0);
      glVertex3d(0, i->width / 2, -i->height / 2);
      glTexCoord2d(right, 0);
      glVertex3d(0, -i->width / 2, -i->height / 2);
      glEnd();
      glPopMatrix();
      glDeleteTextures(1, &t);
    }
    glPopAttrib();
  }

  //
  glPopAttrib();
  glPopMatrix();
}
示例#15
0
void MyWindow::texcube() const
{
	glEnable(GL_TEXTURE_2D);
	// Front Face
	glBindTexture(GL_TEXTURE_2D, _textures[4]);
	glBegin(GL_QUADS);
		glNormal3f(0.0f,0.0f,1.0f);
		glTexCoord2d(0.0, 0.0);		glVertex3d(-1.0, -1.0,  1.0);
		glTexCoord2d(1.0, 0.0);		glVertex3d( 1.0, -1.0,  1.0);
		glTexCoord2d(1.0, 1.0);		glVertex3d( 1.0,  1.0,  1.0);
		glTexCoord2d(0.0, 1.0);		glVertex3d(-1.0,  1.0,  1.0);
	glEnd();
	// Back Face
	glBindTexture(GL_TEXTURE_2D, _textures[5]);
	glBegin(GL_QUADS);
		glNormal3f(0.0f,0.0f,-1.0f);
		glTexCoord2d(1.0, 0.0);		glVertex3d(-1.0, -1.0, -1.0);
		glTexCoord2d(1.0, 1.0);		glVertex3d(-1.0,  1.0, -1.0);
		glTexCoord2d(0.0, 1.0);		glVertex3d( 1.0,  1.0, -1.0);
		glTexCoord2d(0.0, 0.0);		glVertex3d( 1.0, -1.0, -1.0);
	glEnd();
	// Top Face
	glBindTexture(GL_TEXTURE_2D, _textures[2]);
	glBegin(GL_QUADS);
		glNormal3f(0.0f,1.0f,0.0f);
		glTexCoord2d(0.0, 1.0);		glVertex3d(-1.0,  1.0, -1.0);
		glTexCoord2d(0.0, 0.0);		glVertex3d(-1.0,  1.0,  1.0);
		glTexCoord2d(1.0, 0.0);		glVertex3d( 1.0,  1.0,  1.0);
		glTexCoord2d(1.0, 1.0);		glVertex3d( 1.0,  1.0, -1.0);
	glEnd();
	// Bottom Face
	glBindTexture(GL_TEXTURE_2D, _textures[3]);
	glBegin(GL_QUADS);
		glNormal3f(0.0f,-1.0f,0.0f);
		glTexCoord2d(1.0, 1.0);		glVertex3d(-1.0, -1.0, -1.0);
		glTexCoord2d(0.0, 1.0);		glVertex3d( 1.0, -1.0, -1.0);
		glTexCoord2d(0.0, 0.0);		glVertex3d( 1.0, -1.0,  1.0);
		glTexCoord2d(1.0, 0.0);		glVertex3d(-1.0, -1.0,  1.0);
	glEnd();
	// Right face
	glBindTexture(GL_TEXTURE_2D, _textures[1]);
	glBegin(GL_QUADS);
		glNormal3f(1.0f,0.0f,0.0f);
		glTexCoord2d(1.0, 0.0);		glVertex3d( 1.0, -1.0, -1.0);
		glTexCoord2d(1.0, 1.0);		glVertex3d( 1.0,  1.0, -1.0);
		glTexCoord2d(0.0, 1.0);		glVertex3d( 1.0,  1.0,  1.0);
		glTexCoord2d(0.0, 0.0);		glVertex3d( 1.0, -1.0,  1.0);
	glEnd();
	// Left Face
	glBindTexture(GL_TEXTURE_2D, _textures[0]);
	glBegin(GL_QUADS);
		glNormal3f(-1.0f,0.0f,0.0f);
		glTexCoord2d(0.0, 0.0);		glVertex3d(-1.0, -1.0, -1.0);
		glTexCoord2d(1.0, 0.0);		glVertex3d(-1.0, -1.0,  1.0);
		glTexCoord2d(1.0, 1.0);		glVertex3d(-1.0,  1.0,  1.0);
		glTexCoord2d(0.0, 1.0);		glVertex3d(-1.0,  1.0, -1.0);
	glEnd();
	glDisable(GL_TEXTURE_2D);
}
CD_APPLET_PRE_INIT_END


GLuint cd_mail_load_cube_calllist (void)
{
	GLuint iCallList = glGenLists (1);
	glNewList(iCallList, GL_COMPILE); // Go pour la compilation de la display list
	glPolygonMode (GL_FRONT, GL_FILL);
	
	double a = .5 / sqrt (2);
	glBegin(GL_QUADS);
	// Front Face (note that the texture's corners have to match the quad's corners)
  //glColor3f(1.0f,0.5f,0.0f);
	glNormal3f(0,0,1);
	glTexCoord2d(0., 0.); glVertex3f(-a,  a,  a);  // Bottom Left Of The Texture and Quad
	glTexCoord2d(1., 0.); glVertex3f( a,  a,  a);  // Bottom Right Of The Texture and Quad
	glTexCoord2d(1., 1.); glVertex3f( a, -a,  a);  // Top Right Of The Texture and Quad
	glTexCoord2d(0., 1.); glVertex3f(-a, -a,  a);  // Top Left Of The Texture and Quad
	// Back Face
	glNormal3f(0,0,-1);
	glTexCoord2d(1., 0.); glVertex3f( -a, a, -a);  // Bottom Right Of The Texture and Quad
	glTexCoord2d(1., 1.); glVertex3f( -a, -a, -a);  // Top Right Of The Texture and Quad
	glTexCoord2d(0., 1.); glVertex3f(a, -a, -a);  // Top Left Of The Texture and Quad
	glTexCoord2d(0., 0.); glVertex3f(a, a, -a);  // Bottom Left Of The Texture and Quad
	// Top Face
  //glColor3f(1.0f,0.f,1.0f);
	glNormal3f(0,1,0);
	glTexCoord2d(0., 1.); glVertex3f(-a,  a,  a);  // Top Left Of The Texture and Quad
	glTexCoord2d(0., 0.); glVertex3f(-a,  a, -a);  // Bottom Left Of The Texture and Quad
	glTexCoord2d(1., 0.); glVertex3f( a,  a, -a);  // Bottom Right Of The Texture and Quad
	glTexCoord2d(1., 1.); glVertex3f( a,  a,  a);  // Top Right Of The Texture and Quad
	// Bottom Face
	glNormal3f(0,-1,0);
	glTexCoord2d(1., 1.); glVertex3f( a, -a, -a);  // Top Right Of The Texture and Quad
	glTexCoord2d(0., 1.); glVertex3f(-a, -a, -a);  // Top Left Of The Texture and Quad
	glTexCoord2d(0., 0.); glVertex3f(-a, -a,  a);  // Bottom Left Of The Texture and Quad
	glTexCoord2d(1., 0.); glVertex3f( a, -a,  a);  // Bottom Right Of The Texture and Quad
	// Right face
  //glColor3f(0.f,0.5f,1.0f);
	glNormal3f(1,0,0);
	glTexCoord2d(1., 0.);  glVertex3f( a,  a, -a);  // Bottom Right Of The Texture and Quad
	glTexCoord2d(1., 1.);  glVertex3f( a, -a, -a);  // Top Right Of The Texture and Quad
	glTexCoord2d(0., 1.);  glVertex3f( a, -a,  a);  // Top Left Of The Texture and Quad
	glTexCoord2d(0., 0.);  glVertex3f( a,  a,  a);  // Bottom Left Of The Texture and Quad
	// Left Face
	glNormal3f(-1,0,0);
	glTexCoord2d(0., 0.);  glVertex3f(-a,  a, -a);  // Bottom Left Of The Texture and Quad
	glTexCoord2d(1., 0.);  glVertex3f(-a,  a,  a);  // Bottom Right Of The Texture and Quad
	glTexCoord2d(1., 1.);  glVertex3f(-a, -a,  a);  // Top Right Of The Texture and Quad
	glTexCoord2d(0., 1.);  glVertex3f(-a, -a, -a);  // Top Left Of The Texture and Quad
	glEnd();
	
	glEndList(); // Fini la display list
	return iCallList;
}
示例#17
0
文件: vector.cpp 项目: jkotur/planetz
void glTexCoord2v( const Vector3& v  )
{
	glTexCoord2d( v.x , v.y );
}
示例#18
0
static void draw_particles(particles particle[], int max, float slowdown, float xspeed, float yspeed, int x, int y, int z,
   int r, int g, int b, float life, float scale) {

   glShadeModel(GL_SMOOTH);                        // Enables Smooth Shading
   glEnable(GL_BLEND);                         // Enable Blending
   glBlendFunc(GL_SRC_ALPHA,GL_ONE);                   // Type Of Blending To Perform
   glHint(GL_PERSPECTIVE_CORRECTION_HINT,GL_NICEST);           // Really Nice Perspective Calculations
   glHint(GL_POINT_SMOOTH_HINT,GL_NICEST);                 // Really Nice Point Smoothing

   float white[] = {1,1,1,1};
   float Emission[]  = {0.0,0.0,0.01*emission,1.0};
   glMaterialfv(GL_FRONT_AND_BACK,GL_SHININESS,shinyvec);
   glMaterialfv(GL_FRONT_AND_BACK,GL_SPECULAR,white);
   glMaterialfv(GL_FRONT_AND_BACK,GL_EMISSION,Emission);

   ambient = 100;
   float Glowiness[]   = {0.01*ambient ,0.01*ambient ,0.01*ambient ,1.0};
   float Diffuse[]   = {0.01*diffuse ,0.01*diffuse ,0.01*diffuse ,1.0};
   float Specular[]  = {0.01*specular,0.01*specular,0.01*specular,1.0};

   glPushMatrix();
   
   glScaled(scale, scale, scale);
   glTranslated(x,y,z);
   glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,mode?GL_REPLACE:GL_MODULATE);
   glEnable(GL_TEXTURE_2D);                        // Enable Texture Mapping
   glBindTexture(GL_TEXTURE_2D,texture[4]);                // Select Our Texture

    //  OpenGL should normalize normal vectors
   glEnable(GL_NORMALIZE);
   //  Enable lighting
   glEnable(GL_LIGHTING);
   //  Location of viewer for specular calculations
   glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER,local);
   //  glColor sets ambient and diffuse color materials
   glColorMaterial(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE);
   glEnable(GL_COLOR_MATERIAL);
   //  Enable light 0
   glEnable(light);

   // draw that sucker
   for (loop=0; loop < max; loop++) {
      if (particle[loop].active) {
         float x=particle[loop].x;
         float y=particle[loop].y;
         float z=particle[loop].z;

         glColor4f(particle[loop].r, particle[loop].g, particle[loop].b, particle[loop].life);

         glBegin(GL_TRIANGLE_STRIP);  
         glTexCoord2d(1,1); glVertex3f(x+0.02f,y+0.02f,z); // Top Right
         glTexCoord2d(0,1); glVertex3f(x-0.02f,y+0.02f,z); // Top Left
         glTexCoord2d(1,0); glVertex3f(x+0.02f,y-0.02f,z); // Bottom Right
         glTexCoord2d(0,0); glVertex3f(x-0.02f,y-0.02f,z); // Bottom Left
         glEnd();

         particle[loop].x += particle[loop].xi / (slowdown * 1000);
         particle[loop].y += particle[loop].yi / (slowdown * 1000);
         particle[loop].z += particle[loop].zi / (slowdown * 1000);

         particle[loop].xi += particle[loop].xg;
         particle[loop].yi += particle[loop].yg;
         particle[loop].zi += particle[loop].zg;

         particle[loop].life -= particle[loop].fade;
         if (particle[loop].b < 1) {
            particle[loop].b += 0.005;
         }

         if (particle[loop].r < 1) {
            particle[loop].r += 0.005;
         }

         if (particle[loop].g < 1) {
            particle[loop].g += 0.005;
         }

         if (particle[loop].life < 0.0f) {
            particle[loop].life = life;
            particle[loop].fade = (float)(rand()%100)/1000.0f+0.003f;
            particle[loop].r = r;
            particle[loop].g = g;
            particle[loop].b = b;
            particle[loop].x = 0.0f;
            particle[loop].y = 0.0f;
            particle[loop].z = 0.0f; 
            particle[loop].xi = xspeed + (float)((rand()%60)-32.0f);
            particle[loop].yi = yspeed + (float)((rand()%60)-32.0f);
            particle[loop].zi = (float)((rand()%60)-32.0f);
         }

         float Position[]  = {x,y,z,1.0};

         glLightfv(light,GL_AMBIENT, Glowiness);
         glLightfv(light,GL_DIFFUSE ,Diffuse);
         glLightfv(light,GL_SPECULAR,Specular);
         glLightfv(light,GL_POSITION,Position);
      }
   }

   glDisable(GL_TEXTURE_2D);
   glDisable(GL_BLEND);  
   glPopMatrix();
}
GUIscrollbar::GUIscrollbar(int x, int y, int h, int m, Functor1<int>clicked):GUIframe(x,y,SB_WIDTH,h), click(clicked), maximum(m)
{
	position=0;
	name="scrollbar";
	downInControl=false;
	
	static GLuint tex=0;
	if(!tex)
		tex=Texture("bitmaps\\scrollbar.bmp");
	glBindTexture(GL_TEXTURE_2D, tex);
	
	
	displayList=glGenLists(1);

	glNewList(displayList, GL_COMPILE);


	const double t=SB_WIDTH;
	const double s=64;
	
	#define coordx(a) ((double)(a)/(double)16)
	#define coordy(a) ((double)(a)/(double)64)
	
	glBindTexture(GL_TEXTURE_2D, tex);


	glBegin(GL_QUADS);
	// #
	// .
	// .
		glTexCoord2d(0.0f, 0.0f);
		glVertex3f(0, 0, 0);
		glTexCoord2d(0.0f, coordy(t));
		glVertex3f(0, t, 0);
		glTexCoord2d(coordx(t), coordy(t));
		glVertex3d(t, t, 0);					
		glTexCoord2d(coordx(t), 0.0f);
		glVertex3f(t, 0, 0);

	// .
	// .
	// #
		glTexCoord2d(0.0f, coordy(s-t));
		glVertex3f(0, h-t, 0);
		glTexCoord2d(0.0f, coordy(s));
		glVertex3f(0, h, 0);
		glTexCoord2d(coordx(t), coordy(s));
		glVertex3d(t, h, 0);					
		glTexCoord2d(coordx(t), coordy(s-t));
		glVertex3f(t, h-t, 0);

	// .
	// #
	// .
		glTexCoord2d(0.0f, coordy(t));
		glVertex3f(0, t, 0);
		glTexCoord2d(0.0f, coordy(s-t));
		glVertex3f(0, h-t, 0);
		glTexCoord2d(coordx(t), coordy(s-t));
		glVertex3d(t, h-t, 0);
		glTexCoord2d(coordx(t), coordy(t));
		glVertex3f(t, t, 0);
	glEnd();

	glEndList();
	
}
示例#20
0
void GUItable::PrivateDraw()
{
	glDisable(GL_TEXTURE_2D);
		glColor4f(0.0, 0.0, 0.0, GUI_TRANS);	
	glBegin(GL_QUADS);		
		glTexCoord2d(0.0f, 0.0f);
		glVertex3f(10, 10, 0);
		glTexCoord2d(0.0f, 1.0);		
		glVertex3f(10, h-10, 0);		
		glTexCoord2d(1.0, 1.0);		
		glVertex3d(w-10, h-10, 0);
		glTexCoord2d(1.0f, 0.0f);		
		glVertex3f(w-10, 10, 0);		
	glEnd();
	glColor3f(1.0, 1.0, 1.0);
	glEnable(GL_TEXTURE_2D);
	glCallList(displayList);
	
	int inSet=16;
	
	if(w<200)
		inSet=0;

	glColor4f(1.0,1.0,1.0,1.0f);
	
	if(!header.empty())
	{
		int size=header.size();
		float headerPos=0;

		for(int i=0; i<size; i++)
		{
			header[i].position=headerPos*w+inSet;
			guifont->PrintColor(header[i].position, 10, header[i].title);

			headerPos+=header[i].size;
		}
		
		glBindTexture(GL_TEXTURE_2D, 0);
		glBegin(GL_LINES);
			glVertex3f(max(4., inSet/2.0), 10+rowHeight, 0);
			glVertex3f(width-max(4., inSet/2.0), 10+rowHeight, 0);		
		glEnd();

		for(int i=0; i<numLines && (i+position)<numEntries; i++)
		{
			if((i+position)==selected)
				glColor4f(1.0,0.4f,0.4f,1.0f);

			string line=data[i+position];
			size_t tabPos=line.find("\t");
			int j=0;

			while(tabPos!=string::npos)
			{
				string contents=line.substr(0, tabPos);

				guifont->Print(header[j].position, (i+2)*rowHeight, contents);

				line=line.substr(tabPos+1, string::npos);
				tabPos=line.find("\t");
				j++;
			}
			guifont->Print(header[j].position, (i+2)*rowHeight, line.substr(0, tabPos));

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

		}
	}
	else
	{
		for(int i=0; i<numLines && (i+position)<numEntries; i++)
		{
			if((i+position)==selected)
				glColor4f(1.0,0.4f,0.4f,1.0f);

			guifont->Print(inSet, (i+1)*rowHeight, data[i+position]);			
			glColor4f(1.0,1.0,1.0,1.0f);
		}
	}
}
示例#21
0
void kvadar(double ax, double ay, double az) {
  glEnable(GL_TEXTURE_2D);
  glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);

  glBindTexture(GL_TEXTURE_2D, tekstura[0]);
  glBegin(GL_QUAD_STRIP);
    glTexCoord2d(0.0, 1.0); glVertex3d(0.0, 0.0, az);
    glTexCoord2d(0.0, 0.0); glVertex3d(0.0, 0.0, 0.0);
    glTexCoord2d(0.5, 1.0); glVertex3d(ax, 0.0, az);
    glTexCoord2d(0.5, 0.0); glVertex3d(ax, 0.0, 0.0);
    glTexCoord2d(1.0, 1.0); glVertex3d(ax, ay, az);
    glTexCoord2d(1.0, 0.0); glVertex3d(ax, ay, 0.0);
    glTexCoord2d(1.5, 1.0); glVertex3d(0.0, ay, az);
    glTexCoord2d(1.5, 0.0); glVertex3d(0.0, ay, 0.0);
    glTexCoord2d(2.0, 1.0); glVertex3d(0.0, 0.0, az);
    glTexCoord2d(2.0, 0.0); glVertex3d(0.0, 0.0, 0.0);
  glEnd();

  glBindTexture(GL_TEXTURE_2D, tekstura[1]);
  glBegin(GL_QUADS);
    glTexCoord2d(0.0, 0.0); glVertex3d(0.0, 0.0, 0.0);
    glTexCoord2d(0.0, 1.0); glVertex3d(0.0, ay, 0.0);
    glTexCoord2d(1.0, 1.0); glVertex3d(ax, ay, 0.0);
    glTexCoord2d(1.0, 0.0); glVertex3d(ax, 0.0, 0.0);
    glTexCoord2d(0.0, 0.0); glVertex3d(0.0, 0.0, az);
    glTexCoord2d(1.0, 0.0); glVertex3d(ax, 0.0, az);
    glTexCoord2d(1.0, 1.0); glVertex3d(ax, ay, az);
    glTexCoord2d(0.0, 1.0);  glVertex3d(0.0, ay, az);
  glEnd();

  glDisable(GL_TEXTURE_2D);
} // kvadar
示例#22
0
		void display()
		{
			mMediaSource->idle();

			// Check whether the texture needs to be recreated.
			if(mMediaSource->textureValid())
			{
				if(
					(mAppTextureWidth != mMediaSource->getTextureWidth() ||	mAppTextureHeight != mMediaSource->getTextureHeight()) &&
					(mAppWindowWidth == mMediaSource->getWidth() && mAppWindowHeight == mMediaSource->getHeight())
				)
				{
					// Attempt to (re)create the texture
					createTexture();
				}
			}
						
			// clear screen
			glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

			glLoadIdentity();
			
			if(mAppTexture != 0)
			{
				// use the browser texture
				glBindTexture( GL_TEXTURE_2D, mAppTexture );

				// If dirty, update the texture.
				LLRect dirtyRect;
				if(!mMediaSource->textureValid())
				{
//					LL_DEBUGS("media_plugin_test") << "Resize in progress, skipping update..." << LL_ENDL;
				}
				else if(mAppWindowWidth != mMediaSource->getWidth() || mAppWindowHeight != mMediaSource->getHeight())
				{
					// A resize is in progress.  Just wait for it...
				}
				else if(mMediaSource->getDirty(&dirtyRect))
				{
					// grab the page
					const unsigned char* pixels = mMediaSource->getBitsData();
					if ( pixels )
					{
						// write them into the texture
						
						// Paranoia: intersect dirtyRect with (0, 0, mAppTextureWidth, mAppTextureHeight)?

						int x_offset = dirtyRect.mLeft;
						int y_offset = dirtyRect.mBottom;
						int width = dirtyRect.mRight - dirtyRect.mLeft;
						int height = dirtyRect.mTop - dirtyRect.mBottom;

						LL_DEBUGS("media_plugin_test") << "Updating, dirty rect is (" 
							<< dirtyRect.mLeft << ", " 
							<< dirtyRect.mTop << ", " 
							<< dirtyRect.mRight << ", " 
							<< dirtyRect.mBottom << "), update params are: (" 
							<< x_offset << ", " 
							<< y_offset << ", " 
							<< width << ", " 
							<< height << ")" 
							<< LL_ENDL; 
						
						// Offset the pixels pointer properly
						pixels += (y_offset * mMediaSource->getTextureDepth() * mMediaSource->getTextureWidth());
						pixels += (x_offset * mMediaSource->getTextureDepth());
						
						glPixelStorei(GL_UNPACK_ROW_LENGTH, mMediaSource->getTextureWidth());
						
						glTexSubImage2D( GL_TEXTURE_2D, 0, 
							x_offset, 
							y_offset,
							width, 
							height,
							mMediaSource->getTextureFormatPrimary(), 
							mMediaSource->getTextureFormatType(), 
							pixels );
						
						mMediaSource->resetDirty();
					}
				}
				
				// scale the texture so that it fits the screen
				GLdouble media_texture_x = mAppWindowWidth / (double)mAppTextureWidth;
				GLdouble media_texture_y = mAppWindowHeight / (double)mAppTextureHeight;

				// draw the single quad full screen (orthographic)

				glEnable( GL_TEXTURE_2D );
				glColor3f( 1.0f, 1.0f, 1.0f );
				glBegin( GL_QUADS );
				if(mAppTextureCoordsOpenGL)
				{
					// Render the texture as per opengl coords (where 0,0 is at the lower left)
					glTexCoord2d( 0, 0 );
					glVertex2d( 0, 0 );

					glTexCoord2d( 0 , media_texture_y );
					glVertex2d( 0, mAppWindowHeight);

					glTexCoord2d( media_texture_x, media_texture_y );
					glVertex2d( mAppWindowWidth , mAppWindowHeight);

					glTexCoord2d( media_texture_x, 0 );
					glVertex2d( mAppWindowWidth, 0 );
				}
				else
				{
					// Render the texture the "other way round" (where 0,0 is at the upper left)
					glTexCoord2d( 0, media_texture_y );
					glVertex2d( 0, 0 );

					glTexCoord2d( 0 , 0 );
					glVertex2d( 0, mAppWindowHeight);

					glTexCoord2d( media_texture_x, 0 );
					glVertex2d( mAppWindowWidth , mAppWindowHeight);

					glTexCoord2d( media_texture_x, media_texture_y );
					glVertex2d( mAppWindowWidth, 0 );
				}
				glEnd();

			}
			
			glutSwapBuffers();
		};
示例#23
0
文件: Text.cpp 项目: firej/OGL2
Text::RESULT Font::LOAD( const char*FileName )
{
	iff::tag_t	tagb;								// Буферная переменная
	DWORD		sizeb;								// Буфер для чтения размера
	void	*	texture	=	NULL;					// Буфер для хранения текстуры
	DWORD		tsize	=	NULL;

	FILE * f = fopen (FileName,"rb");
	if (!f)	return Text::FILE_NOT_EXIST;
	tagb.i = iff::GetTAG(f);
	if (tagb.i != ID_FORM)	return Text::BAD_FORMAT;
	sizeb = iff::GetDWORD(f);						// Читаем размер

	tagb.i = iff::GetTAG(f);						// Читаем формат файла
	if (tagb.i != iff::FONTFORMATNAME.i)	return Text::BAD_FORMAT;
	do	{
		tagb.i = iff::GetTAG(f);
		if (feof(f)) break;
		if (tagb.i == iff::FONTTEXTURE.i)
		{
			sizeb	=	iff::GetDWORD(f);
			texture	=	new char[sizeb];
			tsize	=	sizeb;
			iff::GetBuffer(f,texture,sizeb);
		}
		else
		if (tagb.i == iff::FONTGLYPHBLOCK.i)
		{
			sizeb = iff::GetDWORD(f);
			iff::GetBuffer(f,this->lfg,sizeb);
		}
		else iff::read_unknow_chunk(f);
	}
	while(!feof(f));
	fclose(f);										// Файл отработан!
// Создание самого шрифта
	// Загрузка текстуры
		// Создание пути к текстуре из пути к шрифту (они должны быть в одной папке)
	if (!texture)	return Text::BAD_FORMAT;
	T = new TextureClass;
	if (T->LoadL(IL_PNG,texture,tsize))
	{
		delete	T;
		delete	[]	texture;
		return Text::BAD_FORMAT;
	}
	delete	[]	texture;
	// Создание дисплейных списков
	Base = glGenLists(256);
	int sym;
	for ( int i = 0 ; i < 16 ; i++ )
	{
		for ( int j = 0 ; j < 16 ; j++ )
		{
			sym = i*16+j+1;
			glNewList(Base+sym,GL_COMPILE);
			glTranslatef(lfg[sym].A,0,0);
			glBegin(GL_QUADS);
				glTexCoord2d((j  )*0.0625,(i+15.0/16.0)*0.0625f);		// Точка в текстуре (Левая нижняя)
				glVertex2i	( 0,15);									// Координаты вершины (Левая нижняя)
				glTexCoord2d((j+15.0/16.0)*0.0625,(i+15.0/16.0)*0.0625);// Точка на текстуре (Правая нижняя)
				glVertex2i	(15,15);									// Координаты вершины (Правая нижняя)
				glTexCoord2d((j+15.0/16.0)*0.0625,(i  )*0.0625);		// Точка текстуры (Верхняя правая)
				glVertex2i	(15, 0);									// Координаты вершины (Верхняя правая)
				glTexCoord2d((j  )*0.0625,(i  )*0.0625);				// Точка текстуры (Верхняя левая)
	            glVertex2i	( 0, 0);									// Координаты вершины (Верхняя левая)
			glEnd();
			glTranslatef(lfg[sym].B,0,0);
			//glTranslated(10.0,0.0,0.0);
			glEndList();
		};
	};
	return Text::OK;
};
示例#24
0
//--------------------------------------------------------------
void testApp::update(){

    int w = ofGetWidth();
	int h = ofGetHeight();
    
    updateTimer.reset();
    updateTimer.start();
    
    if (debugFboOn) {
        //begin debug stuff
        debugFbo.begin();
        ofClear(0);
        int w = parts_res;
        int h = parts_res;

        debugShader.begin();
    //    debugShader.setUniformTexture("tex1", partsFbo.dst->getTextureReference(), 0);
        debugShader.setUniformTexture("tex1", randtex, 0);
        debugShader.setUniformTexture("tex2", dja.getTextureReference(), 1);
        
        ofSetColor(255,255,255,255);
        glBegin(GL_QUADS);
        glTexCoord2d(0, 0); glVertex2d(0, 0);
        glTexCoord2d(w, 0); glVertex2d(w, 0);
        glTexCoord2d(w, h); glVertex2d(w, h);
        glTexCoord2d(0, h); glVertex2d(0, h);
        glEnd();
        debugShader.end();
        debugFbo.end();

        //end debug stuff
    }
    
#ifdef USE_KINECT
    
    kinect.update();
    
	if(kinect.isFrameNew()) {
		
		// load grayscale depth image from the kinect source
		grayImage.setFromPixels(kinect.getDepthPixels(), kinect.width, kinect.height);
		
		// we do two thresholds - one for the far plane and one for the near plane
		// we then do a cvAnd to get the pixels which are a union of the two thresholds
        grayThreshNear = grayImage;
        grayThreshFar = grayImage;
        grayThreshNear.threshold(nearThreshold, true);
        grayThreshFar.threshold(farThreshold);
        cvAnd(grayThreshNear.getCvImage(), grayThreshFar.getCvImage(), grayImage.getCvImage(), NULL);
		grayImage.flagImageChanged();
		
        //min size (arg 2)
        //how many blogs (arg 4)
		contourFinder.findContours(grayImage, 8000, (kinect.width*kinect.height)/2, 2, false);

        ofVec2f tmp0, tmp1;
        float pi_fact = PI;
        
        switch (contourFinder.nBlobs) {
            case 1:
                tmp0 = blob_to_data(contourFinder.blobs[0], 0);
                if (tmp0.x != 0 && tmp0.y != 0) {
                    a = tmp0.x * pi_fact;
                    b = tmp0.y * pi_fact;
                    c = -a;
                    d = -b;
                    dja.setParam(a, b, c, d);
                    needDraw = true;
                }
                break;
            case 2:
                tmp0 = blob_to_data(contourFinder.blobs[0], 0);
                tmp1 = blob_to_data(contourFinder.blobs[1], 1);
                
                if (tmp0.x != 0 && tmp0.y != 0) {
                    a = tmp0.x * pi_fact;
                    b = tmp0.y * pi_fact;
                    needDraw = true;
                }
//                else {
//                    a = 0.5 * PI;
//                    b = 0.5 * PI;
//                }
                

                if (tmp1.x != 0 && tmp1.y != 0) {
                    c = -tmp1.x * pi_fact;
                    d = -tmp1.y * pi_fact;
                    needDraw = true;
                }
                
                if (needDraw)
                    dja.setParam(a, b, c, d);

                break;
        }

    }
#endif
    
    if (needDraw) {
        dja.setZoom(zoom);
        djaTimer.reset();
        djaTimer.start();
        dja.update();
        djaTimer.stop();
//        printf("update: dja.update took %.03f\n", djaTimer.diff());

        curlTimer.reset();
        curlTimer.start();
        cf.build(dja.getTextureReference());
        curlTimer.stop();
//        printf("update: cf.build took %.03f\n", curlTimer.diff());

        
        //update velfbo based on the curl
        velTimer.reset();
        velTimer.start();
        velFbo.dst->begin();
//        ofClear(0);
        
        velshader.begin();
        velshader.setUniformTexture("partloc", partsFbo.src->getTextureReference(), 0);
        velshader.setUniformTexture("curltex", cf.getTextureReference(), 1);
        velshader.setUniformTexture("veltex", velFbo.src->getTextureReference(), 2);
        
        w = h = parts_res;
        glBegin(GL_QUADS);
        glTexCoord2f(0, 0); glVertex2f(0, 0);
        glTexCoord2f(w, 0); glVertex2f(w, 0);
        glTexCoord2f(w, h); glVertex2f(w, h);
        glTexCoord2f(0, h); glVertex2f(0, h);
        glEnd();
        velshader.end();
        velFbo.dst->end();
        velFbo.swap();
        velTimer.stop();
        needDraw = false;
    }
    
//    w = ofGetWidth();
//    h = ofGetHeight();

    w = renderFbo.getWidth();
    h = renderFbo.getHeight();
    
    posTimer.reset();
    posTimer.start();
    //update particle locations based on the velocity map
    partsFbo.dst->begin();
    ofClear(0);
    posshader.begin();
    posshader.setUniformTexture("u_posloc", partsFbo.src->getTextureReference(), 0);
    posshader.setUniformTexture("u_randtex", randtex, 1);
    posshader.setUniformTexture("denstex", dja.getTextureReference(), 2);
    posshader.setUniformTexture("veltex", velFbo.src->getTextureReference(), 3);
    posshader.setUniform2f("u_screen", (float)w, (float)h);
    posshader.setUniform1f("u_part_life", part_life);
    posshader.setUniform1f("speed", speed);
    posshader.setUniform1f("widthOffset", (float)width_offset);
    
    ofSetColor(255,255,255,255);
    
    w = h = parts_res;
    glBegin(GL_QUADS);
    glTexCoord2f(0, 0); glVertex2f(0, 0);
    glTexCoord2f(w, 0); glVertex2f(w, 0);
    glTexCoord2f(w, h); glVertex2f(w, h);
    glTexCoord2f(0, h); glVertex2f(0, h);
    glEnd();
    
    posshader.end();
    partsFbo.dst->end();
    partsFbo.swap();
    
    posTimer.stop();
//    printf("update: partloc %.3f\n", posTimer.diff());
    
    colorTimer.reset();
    colorTimer.start();
    
    //update colors
    colorFbo.dst->begin();
    ofClear(0);
    colorShader.begin();
    colorShader.setUniformTexture("partloc", partsFbo.src->getTextureReference(), 0);
    colorShader.setUniformTexture("colortex", dja.getTextureReference(), 1);
    colorShader.setUniformTexture("prevcol", colorFbo.src->getTextureReference(), 2);
    colorShader.setUniform2f("screen", parts_res, parts_res);
    colorShader.setUniform2f("tex", dja.getWidth(), dja.getHeight());
    w = h = parts_res;
    glBegin(GL_QUADS);
    glTexCoord2f(0, 0); glVertex2f(0, 0);
    glTexCoord2f(w, 0); glVertex2f(w, 0);
    glTexCoord2f(w, h); glVertex2f(w, h);
    glTexCoord2f(0, h); glVertex2f(0, h);
    glEnd();
    
    colorShader.end();
    colorFbo.dst->end();
    colorFbo.swap();
    
    colorTimer.stop();
//    printf("update: colors %.3f\n", colorTimer.diff());
    
    renderTimer.reset();
    renderTimer.start();
    
    //turn on alpha blending.
    ofEnableAlphaBlending();
    ofPushMatrix();
    renderFbo.begin();
    ofClear(0, 0, 0, 0);
    
    if (drawOverlay) {
        //draw the background
        w = ofGetWidth();
        h = ofGetHeight();
        dja.getTextureReference().bind();
        glBegin(GL_QUADS);
        glTexCoord2f(0, 0); glVertex2f(0, 0);
        glTexCoord2f(w, 0); glVertex2f(w, 0);
        glTexCoord2f(w, h); glVertex2f(w, h);
        glTexCoord2f(0, h); glVertex2f(0, h);
        glEnd();
        dja.getTextureReference().unbind();
    }
    
    if (drawParts) {
        
        w = renderFbo.getWidth();
        h = renderFbo.getHeight();
        partsTimer.reset();
        partsTimer.start();
        glPointSize(pointSize);
        if (pointSmoothing)
            glEnable(GL_POINT_SMOOTH);
        partshader.begin();
        
        partshader.setUniformTexture("partloc", partsFbo.dst->getTextureReference(), 0);
        partshader.setUniformTexture("colortex", colorFbo.src->getTextureReference(), 1);
        //these 2 not used right now but i expect that will come
        partshader.setUniform2f("screensize", w, h);
        partshader.setUniform2f("colsz", dja.getWidth(), dja.getHeight());
        partshader.setUniform1f("widthOffset", (float)width_offset);
        //send the vertex data
        parts_vbo.draw(GL_POINTS, 0, numParticles);

        partshader.end();

        if (pointSmoothing)
            glDisable(GL_POINT_SMOOTH);
        
        partsTimer.stop();
    }
    
    renderFbo.end();
    ofPopMatrix();
    renderTimer.stop();
//    printf("update: render %.3f\n", renderTimer.diff());
    
    updateTimer.stop();
//    printf("update: full update time: %.3f\n", updateTimer.diff());
    
    ofDisableAlphaBlending();
}
示例#25
0
///Create a display list corresponding to the given character.
///glyph_id = actual font glyph id (32 bits), ch = id for printing to screen (16 bits)
void font_data::make_dlist(uint glyph_id, ushort ch) {

	// get the texture reference
	m.alloc(ch);
	GLuint tex = m.get_t(ch);

	// Translate Win-1252 with additions to Unicode
	if (remapflag) {
		if (glyph_id >= 16 && glyph_id < 32) glyph_id = unichar_low[glyph_id-16];
		else if (glyph_id >= 128 && glyph_id < 160) glyph_id = unichar_high[glyph_id-128];
	}

	// Load the Glyph for our character.
	if (FT_Load_Glyph(face, FT_Get_Char_Index(face, glyph_id), FT_LOAD_DEFAULT))
		throw std::runtime_error("FT_Load_Glyph failed");

	// Move the face's glyph into a Glyph object.
    FT_Glyph glyph;
    if (FT_Get_Glyph(face->glyph, &glyph))
		throw std::runtime_error("FT_Get_Glyph failed");

	// Convert the glyph to a bitmap.
	FT_Glyph_To_Bitmap(&glyph, ft_render_mode_normal, 0, 1);
    FT_BitmapGlyph bitmap_glyph = (FT_BitmapGlyph) glyph;

	// This reference will make accessing the bitmap easier
	FT_Bitmap& bitmap=bitmap_glyph->bitmap;

	// Use our helper function to get the widths of
	// the bitmap data that we will need in order to create
	// our texture.
	// The max(2, ...) is used to correct for OpenGL, which 
	// apparently does not like to have rows less than 4 bytes
	// long.  Probably a packing thing.
	int width = max(2, next_p2(bitmap.width));
	int height = next_p2(bitmap.rows);

	// Allocate memory (temporarily) for the texture data.
	GLubyte* expanded_data = new GLubyte[2 * width * height];

	// Here we fill in the data for the expanded bitmap.
	// Notice that we are using two channel bitmap (one for
	// luminocity and one for alpha).
	// Luma always 255.  Alpha stays alpha.
	// (unless of course, it is premultiplied, which in OpenGL it is not.)
	// We use the ?: operator so that value which we use
	// will be 0 if we are in the padding zone, and whatever
	// is the Freetype bitmap otherwise.
	for (int j = 0; j < height; j++) {
		for (int i = 0; i < width; i++) {
			expanded_data[ 2*(i+j*width)   ] = 255;
			expanded_data[ 2*(i+j*width)+1 ] = 
				(i >= bitmap.width || j >= bitmap.rows) ?
				0 : bitmap.buffer[i + bitmap.width*j];
		}
	}

	// Now we just setup some texture paramaters.
    glBindTexture(GL_TEXTURE_2D, tex);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

	// Here we actually create the texture itself, notice
	// that we are using GL_LUMINANCE_ALPHA to indicate that
	// we are using 2 channel data.
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height,
		  0, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, expanded_data);


	// With the texture created, we don't need the expanded data anymore
    delete [] expanded_data;

	// So now we can create the display list
	glNewList(list_base + ch, GL_COMPILE);

	glBindTexture(GL_TEXTURE_2D, tex);

	//glPushMatrix();

	// First we need to move over a little so that
	// the character has the right amount of space
	// between it and the one before it.
	//glTranslatef((float) bitmap_glyph->left,0,0);

	// Now we move down a little in the case that the
	// bitmap extends past the bottom of the line 
	// (this is only true for characters like 'g' or 'y'.
	//glTranslatef(0,(float)bitmap_glyph->top-bitmap.rows,0);
	float left_pad = (float) bitmap_glyph->left;
	float bot_pad = (float) bitmap.rows-bitmap_glyph->top;
	glTranslatef(left_pad, -bot_pad, 0);

	// Now we need to account for the fact that many of
	// our textures are filled with empty padding space.
	// We figure what portion of the texture is used by 
	// the actual character and store that information in 
	// the x and y variables, then when we draw the
	// quad, we will only reference the parts of the texture
	// that we contain the character itself.
	float	x = (float) bitmap.width / (float) width,
			y = (float) bitmap.rows / (float) height;

	// Here we draw the texturemapped quads.
	// The bitmap that we got from FreeType was not 
	// oriented quite like we would like it to be,
	// so we need to link the texture to the quad
	// so that the result will be properly aligned.
	glBegin(GL_QUADS);
	glTexCoord2d(0, 0); glVertex2f(0, (float) bitmap.rows);
	glTexCoord2d(0, y); glVertex2f(0, 0);
	glTexCoord2d(x, y); glVertex2f((float) bitmap.width, 0);
	glTexCoord2d(x, 0); glVertex2f((float) bitmap.width, (float) bitmap.rows);
	glEnd();
	//glPopMatrix();

	// Get width, round, and translate
	short ch_width = (short)(face->glyph->linearHoriAdvance >> 16);
	if (face->glyph->linearHoriAdvance & 0x8000) ++ch_width;
	//glTranslatef(ch_width, 0, 0);
	glTranslatef(ch_width-left_pad, bot_pad, 0);

	// The two ways to do width:
	// face->glyph->linearHoriAdvance >> 16
	// face->glyph->advance.x >> 6 
	
	// Finish the display list
	glEndList();

	// Store the width of this character
	m.set_w(ch, ch_width);
}
示例#26
0
文件: hemidome.c 项目: lpsoares/jinx
void sp_draw(int sp_F_width, int sp_F_height)
{
	int i,j;
	double delta;
	
	delta= 1.0/ (RES-1); 

 	glPushAttrib(GL_ALL_ATTRIB_BITS);
	
	glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);

	/* BEGIN: Draw The Fisheye View */

	glViewport(0,0, sp_F_width, sp_F_height);
	glDisable(GL_LIGHTING);
	glShadeModel(GL_FLAT);

	//glDrawBuffer(GL_BACK);
	
	//glClearColor(0.5,0.5,0.5,0.0);
    //glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);	
	
	
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	glOrtho(-1.0, 1.0, -0.5, 1.0,-100,100);
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();

	glPushMatrix();

	glDisable(GL_TEXTURE_2D);

	// Front
	glColor3f(0.5,0.5,0.5);

	glBegin(GL_TRIANGLE_STRIP);
	glVertex3d(-1,-1,-0.5);
	glVertex3d( 1,-1,-0.5);
	glVertex3d(-1, 1,-0.5);
	glVertex3d( 1, 1,-0.5);
	glEnd();

	glEnable(GL_TEXTURE_2D);
	glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
	
	for(j=0; j < RES-1 ; j++)
	{
		glBindTexture(GL_TEXTURE_2D, textureid[0]);
		glBegin(GL_TRIANGLE_STRIP);
		for(i=0; i < RES-1; i++)
			{
				glTexCoord2d((i)*delta,(j+1)*delta);				
				glVertex2d(F[i][j+1].x, F[i][j+1].y);
				glTexCoord2d((i)*delta,(j)*delta);				
				glVertex2d(F[i][j].x, F[i][j].y);
				glTexCoord2d((i+1)*delta,(j+1)*delta);				
				glVertex2d(F[i+1][j+1].x, F[i+1][j+1].y);
				glTexCoord2d((i+1)*delta,(j+1)*delta);				
				glVertex2d(F[i+1][j+1].x, F[i+1][j+1].y);
				glTexCoord2d((i)*delta,(j)*delta);				
				glVertex2d(F[i][j].x, F[i][j].y);
				glTexCoord2d((i+1)*delta,(j)*delta);				
				glVertex2d(F[i+1][j].x, F[i+1][j].y);

			}
		glEnd();
		

	}

	// Left 
	glColor3f(0.0,1.0,1.0);
	for(j=0; j < RES-1; j++)
	{
		glBindTexture(GL_TEXTURE_2D, textureid[1]);
		glBegin(GL_TRIANGLE_STRIP);
		for(i=0; i < ((RES+1)/2)-1; i++)
			{
				glTexCoord2d(0.5+(i)*delta,(j+1)*delta);
				glVertex2d(L[i][j+1].x, L[i][j+1].y);
				glTexCoord2d(0.5+(i)*delta,(j)*delta);
				glVertex2d(L[i][j].x, L[i][j].y);
				glTexCoord2d(0.5+(i+1)*delta,(j+1)*delta);
				glVertex2d(L[i+1][j+1].x, L[i+1][j+1].y);
				glTexCoord2d(0.5+(i+1)*delta,(j+1)*delta);
				glVertex2d(L[i+1][j+1].x, L[i+1][j+1].y);
				glTexCoord2d(0.5+(i)*delta,(j)*delta);
				glVertex2d(L[i][j].x, L[i][j].y);
				glTexCoord2d(0.5+(i+1)*delta,(j)*delta);
				glVertex2d(L[i+1][j].x, L[i+1][j].y);
			}
		glEnd();
	}

	// Right
	glColor3f(0.5,0.0,1.0);
	for(j=0; j < RES-1; j++)
	{
		glBindTexture(GL_TEXTURE_2D, textureid[2]);
		glBegin(GL_TRIANGLE_STRIP);
		for(i=0; i < ((RES+1)/2)-1; i++)
			{
				glTexCoord2d((i)*delta,(j+1)*delta);
				glVertex2d(R[i][j+1].x, R[i][j+1].y);
				glTexCoord2d((i)*delta,(j)*delta);
				glVertex2d(R[i][j].x, R[i][j].y);
				glTexCoord2d((i+1)*delta,(j+1)*delta);
				glVertex2d(R[i+1][j+1].x, R[i+1][j+1].y);
				glTexCoord2d((i+1)*delta,(j+1)*delta);
				glVertex2d(R[i+1][j+1].x, R[i+1][j+1].y);
				glTexCoord2d((i)*delta,(j)*delta);
				glVertex2d(R[i][j].x, R[i][j].y);
				glTexCoord2d((i+1)*delta,(j)*delta);
				glVertex2d(R[i+1][j].x, R[i+1][j].y);
			}
		glEnd();
	}

	// Top 
	glColor3f(0.0,1.0,0.0);
	for(j=0; j < ((RES+1)/2)-1; j++)
	{
		glBindTexture(GL_TEXTURE_2D, textureid[3]);
		glBegin(GL_TRIANGLE_STRIP);
		for(i=0; i < RES-1; i++)
			{
				glTexCoord2d((i)*delta,(j+1)*delta);
				glVertex2d(T[i][j+1].x, T[i][j+1].y);
				glTexCoord2d((i)*delta,(j)*delta);
				glVertex2d(T[i][j].x, T[i][j].y);
				glTexCoord2d((i+1)*delta,(j+1)*delta);
				glVertex2d(T[i+1][j+1].x, T[i+1][j+1].y);
				glTexCoord2d((i+1)*delta,(j+1)*delta);
				glVertex2d(T[i+1][j+1].x, T[i+1][j+1].y);
				glTexCoord2d((i)*delta,(j)*delta);
				glVertex2d(T[i][j].x, T[i][j].y);
				glTexCoord2d((i+1)*delta,(j)*delta);
				glVertex2d(T[i+1][j].x, T[i+1][j].y);

			}
		glEnd();
	}

	// Bottom 
	glColor3f(1.0,1.0,0.0);
	for(j=0; j < ((RES+1)/2)-1; j++)
	{
		glBindTexture(GL_TEXTURE_2D, textureid[4]);
		glBegin(GL_TRIANGLE_STRIP);
		for(i=0; i < RES-1; i++)
			{
				glTexCoord2d((i)*delta,0.5+(j+1)*delta);
				glVertex2d(B[i][j+1].x, B[i][j+1].y);
				glTexCoord2d((i)*delta,0.5+(j)*delta);
				glVertex2d(B[i][j].x, B[i][j].y);
				glTexCoord2d((i+1)*delta,0.5+(j+1)*delta);
				glVertex2d(B[i+1][j+1].x, B[i+1][j+1].y);
				glTexCoord2d((i+1)*delta,0.5+(j+1)*delta);
				glVertex2d(B[i+1][j+1].x, B[i+1][j+1].y);
				glTexCoord2d((i)*delta,0.5+(j)*delta);
				glVertex2d(B[i][j].x, B[i][j].y);
				glTexCoord2d((i+1)*delta,0.5+(j)*delta);
				glVertex2d(B[i+1][j].x, B[i+1][j].y);

			}
		glEnd();
	
	}

	glFlush();
	glDisable(GL_TEXTURE_2D);
	
	glPopMatrix();

	glPopAttrib();

/* END: Draw The Fisheye View */

}
示例#27
0
void gl_tex_coord_2d(float x, float y) {
  glTexCoord2d(x, y);
}
示例#28
0
void glTexCoord2(const TVector2d& vec) {
	glTexCoord2d(vec.x, vec.y);
}
示例#29
0
void compile_man(){
	cube = glGenLists(1);
	glNewList(cube,GL_COMPILE); 
		
		//glTranslatef(-0.5,-0.5,-0.5);

		glBegin(GL_QUADS);
		//top
			glNormal3f(0.0, 1.0, 0.0);
			glTexCoord2d(0.0,1.0); glVertex3f(-0.5,0.5,-0.5);
			glTexCoord2d(1.0,1.0); glVertex3f(-0.5,0.5,0.5);
			glTexCoord2d(1.0,0.0); glVertex3f(0.5,0.5,0.5);
			glTexCoord2d(0.0,0.0); glVertex3f(0.5,0.5,-0.5);

		//base
			glNormal3f(0.0, -1.0, 0.0);
			glTexCoord2d(0.0,0.0); glVertex3f(0.5,-0.5,-0.5);
			glTexCoord2d(1.0,0.0); glVertex3f(0.5,-0.5,0.5);
			glTexCoord2d(1.0,1.0); glVertex3f(-0.5,-0.5,0.5);
			glTexCoord2d(0.0,1.0); glVertex3f(-0.5,-0.5,-0.5);

		//back
			glNormal3f(0.0, 0.0, -1.0);
			glTexCoord2d(0.0,0.0); glVertex3f(-0.5,0.5,-0.5);
			glTexCoord2d(1.0,0.0); glVertex3f(0.5,0.5,-0.5);
			glTexCoord2d(1.0,1.0); glVertex3f(0.5,-0.5,-0.5);
			glTexCoord2d(0.0,1.0); glVertex3f(-0.5,-0.5,-0.5);	

		//left
			glNormal3f(-1.0, 0.0, 0.0);
			glTexCoord2d(0.0,0.0); glVertex3f(-0.5,0.5,0.5);
			glTexCoord2d(1.0,0.0); glVertex3f(-0.5,0.5,-0.5);
			glTexCoord2d(1.0,1.0); glVertex3f(-0.5,-0.5,-0.5);
			glTexCoord2d(0.0,1.0); glVertex3f(-0.5,-0.5,0.5);

		//right
			glNormal3f(1.0, 0.0, 0.0);
			glTexCoord2d(0.0,0.0); glVertex3f(0.5,-0.5,0.5);
			glTexCoord2d(1.0,0.0); glVertex3f(0.5,-0.5,-0.5);
			glTexCoord2d(1.0,1.0); glVertex3f(0.5,0.5,-0.5);
			glTexCoord2d(0.0,1.0); glVertex3f(0.5,0.5,0.5);
		
		//front
			glNormal3f(0.0, 0.0, 1.0);
			glTexCoord2d(0.0,0.0); glVertex3f(-0.5,-0.5,0.5);
			glTexCoord2d(1.0,0.0); glVertex3f(0.5,-0.5,0.5);
			glTexCoord2d(1.0,1.0); glVertex3f(0.5,0.5,0.5);
			glTexCoord2d(0.0,1.0); glVertex3f(-0.5,0.5,0.5);
		glEnd();
	glEndList();
	
	t3 = glGenLists(1);
	glNewList(t3,GL_COMPILE);
		glPushMatrix();
		glScalef(1.2,1.2,0.4);
		glCallList(cube);
		glPopMatrix();
	glEndList();

	t2 = glGenLists(1);
	glNewList(t2,GL_COMPILE);		
		glPushMatrix();
		glScalef(1.4,0.4,0.6);
		glCallList(cube);
		glPopMatrix();		
	glEndList();

	t1 = glGenLists(1);
	glNewList(t1,GL_COMPILE);
		glPushMatrix();
		glScalef(1.6,1.6,0.8);
		glCallList(cube);
		glPopMatrix();
	glEndList();

	Sh = glGenLists(1);
	glNewList(Sh,GL_COMPILE);
		glPushMatrix();
		glScalef(0.3,0.3,0.3);
		glCallList(cube);
		glPopMatrix();
	glEndList();

	UArm = glGenLists(1);
	glNewList(UArm,GL_COMPILE);
		glPushMatrix();
		glScalef(0.3,1.0,0.3);
		glCallList(cube);
		glPopMatrix();
	glEndList();

	Elbow = glGenLists(1);
	glNewList(Elbow,GL_COMPILE);
		glPushMatrix();
		glScalef(0.3,0.3,0.3);
		glCallList(cube);
		glPopMatrix();
	glEndList();

	LArm = glGenLists(1);
	glNewList(LArm,GL_COMPILE);
		glPushMatrix();
		glScalef(0.3,1.0,0.3);
		glCallList(cube);
		glPopMatrix();
	glEndList();

	Wrist = glGenLists(1);
	glNewList(Wrist,GL_COMPILE);
		glPushMatrix();
		glScalef(0.3,0.3,0.3);
		glCallList(cube);
		glPopMatrix();
	glEndList();

	Hand = glGenLists(1);
	glNewList(Hand,GL_COMPILE);
		glPushMatrix();
		glScalef(0.5,0.5,0.5);
		glCallList(cube);
		glPopMatrix();
	glEndList();

	Hip = glGenLists(1);
	glNewList(Hip,GL_COMPILE);
		glPushMatrix();
		glScalef(0.3,0.3,0.3);
		glCallList(cube);
		glPopMatrix();
	glEndList();

	Thigh = glGenLists(1);
	glNewList(Thigh,GL_COMPILE);
		glPushMatrix();
		glScalef(0.3,1.0,0.3);
		glCallList(cube);
		glPopMatrix();
	glEndList();

	Knee = glGenLists(1);
	glNewList(Knee,GL_COMPILE);
		glPushMatrix();
		glScalef(0.3,0.3,0.3);
		glCallList(cube);
		glPopMatrix();
	glEndList();

	Leg = glGenLists(1);
	glNewList(Leg,GL_COMPILE);
		glPushMatrix();
		glScalef(0.3,1.0,0.3);
		glCallList(cube);
		glPopMatrix();
	glEndList();

	Ankle = glGenLists(1);
	glNewList(Ankle,GL_COMPILE);
		glPushMatrix();
		glScalef(0.3,0.3,0.3);
		glCallList(cube);
		glPopMatrix();
	glEndList();


	Foot = glGenLists(1);
	glNewList(Foot,GL_COMPILE);
		glPushMatrix();
		glScalef(0.3,0.3,0.6);
		glCallList(cube);
		glPopMatrix();
	glEndList();

	Neck = glGenLists(1);
	glNewList(Neck,GL_COMPILE);
		glPushMatrix();
		glScalef(0.3,0.3,0.3);
		glCallList(cube);
		glPopMatrix();
	glEndList();

	Head = glGenLists(1);
	glNewList(Head,GL_COMPILE);
		glPushMatrix();
		glBegin(GL_QUADS);
		//top
			glTexCoord2d(0.1+0.0/2,2.0/3);; glVertex3f(-0.5,0.5,-0.5);
			glTexCoord2d(0.1+1.0/2,2.0/3); glVertex3f(-0.5,0.5,0.5);
			glTexCoord2d(0.1+1.0/2,3.0/3); glVertex3f(0.5,0.5,0.5);
			glTexCoord2d(0.1+0.0/2,3.0/3); glVertex3f(0.5,0.5,-0.5);

		//base

			glTexCoord2d(0.1+1.0/2,0.0/3); glVertex3f(0.5,-0.5,-0.5);
			glTexCoord2d(0.1+1.0/2,1.0/3); glVertex3f(0.5,-0.5,0.5);
			glTexCoord2d(0.1+0.0/2,1.0/3); glVertex3f(-0.5,-0.5,0.5);
			glTexCoord2d(0.1+0.0/2,0.0/3); glVertex3f(-0.5,-0.5,-0.5);

		//back

			glTexCoord2d(0.1+0.0/2,2.0/3); glVertex3f(-0.5,0.5,-0.5);
			glTexCoord2d(0.1+1.0/2,2.0/3); glVertex3f(0.5,0.5,-0.5);
			glTexCoord2d(0.1+1.0/2,1.0/3); glVertex3f(0.5,-0.5,-0.5);
			glTexCoord2d(0.1+0.0/2,1.0/3); glVertex3f(-0.5,-0.5,-0.5);	

		//left

			glTexCoord2d(0.1+2.0/2,2.0/3); glVertex3f(-0.5,0.5,0.5);
			glTexCoord2d(0.1+1.0/2,2.0/3); glVertex3f(-0.5,0.5,-0.5);
			glTexCoord2d(0.1+1.0/2,1.0/3); glVertex3f(-0.5,-0.5,-0.5);
			glTexCoord2d(0.1+2.0/2,1.0/3); glVertex3f(-0.5,-0.5,0.5);

		//right

			glTexCoord2d(0.1+1.0/2,2.0/3); glVertex3f(0.5,-0.5,0.5);
			glTexCoord2d(0.1+2.0/2,2.0/3); glVertex3f(0.5,-0.5,-0.5);
			glTexCoord2d(0.1+2.0/2,3.0/3); glVertex3f(0.5,0.5,-0.5);
			glTexCoord2d(0.1+1.0/2,3.0/3); glVertex3f(0.5,0.5,0.5);
		
		//front

			glTexCoord2d(0.1+1.0/2,0.0/3); glVertex3f(-0.5,-0.5,0.5);
			glTexCoord2d(0.1+2.0/2,0.0/3); glVertex3f(0.5,-0.5,0.5);
			glTexCoord2d(0.1+2.0/2,1.0/3); glVertex3f(0.5,0.5,0.5);
			glTexCoord2d(0.1+1.0/2,1.0/3); glVertex3f(-0.5,0.5,0.5);
		
		glEnd();
		glPopMatrix();
	glEndList();

}
示例#30
0
void FireworksFrame::Display()
{
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	/* 摄像机 */

	float viewDistance = 10; //镜头与物体之间的距离;上帝视角:拉远镜头
	if (viewMode) //第一人称
	{
		//m_camera0->SetEyePos(-200, 100, 0); //看烟花
		m_camera0->SetEyePos(-5, 5, 5);
		m_camera0->SetViewAngleWithEyeFixed(viewAngleY, viewAngleZ);
	}
	else //上帝视角
	{
		m_camera0->SetTargetPos(0, 0, 0);
		m_camera0->SetViewAngleWithTargetFixed(viewDistance, viewAngleY, viewAngleZ);
	}
	m_camera0->UpdatePerspective(75, 1.3); //必须放在这才能启动摄像机!
	m_camera0->Apply();

	//显示文字
	char *string = "HAPPY NEW YEAR";
	font.glPrint(4, 5, string);

	string = "FGHIJ";
	font3D.glPrint(3, 0, string);

	/* 物体渲染 */
	/* 先绘制【不透明物体】! */
	//这五个属性如果不为(false, true, TEXTURE, GL_CCW, GL_TRIANGLES)才需要指定!
	m_axis->SetRenderMode(false, false, COLOR, GL_CCW, GL_LINES);
	m_axis->Render();

	glEnable(GL_TEXTURE_2D);
	t.Apply();

	glBegin(GL_TRIANGLE_STRIP);

	glTexCoord2d(1, 1); glVertex3f(1500, 1500, -1500);
	glTexCoord2d(0, 1); glVertex3f(1500, 1500, 1500);
	glTexCoord2d(1, 0); glVertex3f(-1500, 1500, -1500);
	glTexCoord2d(0, 0); glVertex3f(-1500, 1500, 1500);

	glEnd();


	/* 其他逻辑计算 */
	if (isShoot)
		Shoot();

	m_fireworksListIter = m_fireworksList.begin();
	while (true)
	{
		if (m_fireworksListIter == m_fireworksList.end())
		{
			//如果列表为空,迭代器直接等于list.end();
			//上一次循环中,调用erase()方法,删除迭代器当前指向的元素,有可能导致迭代器增加至list.end()
			//上一次循环中,迭代器++也可能导致迭代器增加至list.end();
			break;
		}

		if (!(*m_fireworksListIter)->m_arrParticles[69].GetActive()) //迭代器解引用
		{
			delete(*m_fireworksListIter);
			m_fireworksListIter = m_fireworksList.erase(m_fireworksListIter);//erase:使作为参数的迭代器失效,返回指向该迭代器下一参数的迭代器
		}

		if (m_fireworksListIter != m_fireworksList.end()) //确保迭代器没有越界!
			m_fireworksListIter++;
	}

	/* 【透明物体】必须在绘制完不透明物体之后才能正确绘制!! */
	//粒子系统
	glDisable(GL_DEPTH_TEST);
	glDisable(GL_TEXTURE_2D); //测试粒子系统没有使用纹理!

	for (m_fireworksListIter = m_fireworksList.begin(); m_fireworksListIter != m_fireworksList.end(); m_fireworksListIter++)
	{
		if ((*m_fireworksListIter)->m_arrParticles[50].GetActive())
		{
			(*m_fireworksListIter)->Render();
			(*m_fireworksListIter)->Run();
		}
	}
	glEnable(GL_DEPTH_TEST);
	glColor3f(1, 1, 1); //恢复纹理底层颜色!!

	glFlush();
	glutSwapBuffers();
}