Exemplo n.º 1
0
void FlowShower::draw()
{
	update();
	setOrthoView();
	glClear(GL_COLOR_BUFFER_BIT);

	float invRatio = float(game->getResY()) / float(game->getResX());
	float hs = 0.02f; //mouse horizontal size
	//float vs = hs * invRatio; //mouse vertical size
	float x = float(game->getMouseX()) / float(game->getResX());
	float y = 1.0f - float(game->getMouseY()) / float(game->getResY());
	float left = (1.0f - invRatio) / 2.0f;
	float right = 1.0f - left;
	float osx = (x - left) / (right - left);

	if (painting && (game->isLeftDown() || game->isMiddleDown()
			|| game->isKeyDown('n') || game->isRightDown()))
	{
		flower.bindMat();

		glDisable(GL_TEXTURE_2D);

		if (game->isLeftDown())
			glColor3f(0.1, 0.0f, 0.0f);
		else if (game->isMiddleDown() || game->isKeyDown('m'))
			glColor3f(0.2, 0.0f, 0.0f);
		else if (game->isRightDown())
			glColor3f(0.0, 0.0f, 0.0f);

		/*glBegin(GL_QUADS);
		osx -= 1.0f;
		oldMouseOSX -= 1.0f;
		for (int j = 0; j < 3; j++)
		{
			glVertex2f(osx - hs, y - hs);
			glVertex2f(osx + hs, y - hs);
			glVertex2f(osx + hs, y + hs);
			glVertex2f(osx - hs, y + hs);

			glVertex2f(osx + hs, y - hs);
			glVertex2f(osx - hs, y - hs);
			glVertex2f(oldMouseOSX - hs, oldMouseY - hs);
			glVertex2f(oldMouseOSX + hs, oldMouseY - hs);

			glVertex2f(osx + vs, y + hs);
			glVertex2f(osx + vs, y - hs);
			glVertex2f(oldMouseOSX + hs, oldMouseY - hs);
			glVertex2f(oldMouseOSX + hs, oldMouseY + hs);

			glVertex2f(osx - vs, y + hs);
			glVertex2f(osx + vs, y + hs);
			glVertex2f(oldMouseOSX + hs, oldMouseY + hs);
			glVertex2f(oldMouseOSX - hs, oldMouseY + hs);

			glVertex2f(osx - vs, y - hs);
			glVertex2f(osx - vs, y + hs);
			glVertex2f(oldMouseOSX - hs, oldMouseY + hs);
			glVertex2f(oldMouseOSX - hs, oldMouseY - hs);
			osx += 1.0f;
			oldMouseOSX += 1.0f;
		}
		glEnd();*/

		drawMouseOffScreen();

		osx -= 2.0f;
		oldMouseOSX -= 2.0f;
		Fbo::unbind();
	}
	if (game->isKeyDown('g'))
	{
		flower.bindMat();
		glColor3f(0.0f, 0.0f, 0.0f);
		glDisable(GL_BLEND);
		glBegin(GL_QUADS);
		glTexCoord2f(0.0f, 0.0f);
		glVertex2f(0.0f, 0.0f);
		glTexCoord2f(1.0f, 0.0f);
		glVertex2f(1.0f, 0.0f);
		glTexCoord2f(1.0f, 1.0f);
		glVertex2f(1.0f, 1.0f);
		glTexCoord2f(0.0f, 1.0f);
		glVertex2f(0.0f, 1.0f);
		glEnd();

		Fbo::unbind();
	}
	if (!paused)
		flower.iterate(iterations, this);

	if (streamlining)
	{
		flower.bindVel();
		float sx = float(game->getMouseX()) / float(game->getResY());
		float sy = 1.0f - float(game->getMouseY()) / float(game->getResY());
		float x = (sx-0.5* float(game->getResX())/ float(game->getResY()))/scale+ viewX;
		float y = (sy-0.5)/scale+ viewY;
		if(x>0)
			x=x-static_cast<int>(x);
		else
			x=x-static_cast<int>(x)+1.0f;
		if(y>0)
			y=y-static_cast<int>(y);
		else
			y=y-static_cast<int>(y)+1.0f;

		slx[0] = x;
		sly[0] = y;
		while (slx[0] < 0.0f)
			slx[0] += 1.0f;
		while (sly[0] < 0.0f)
			sly[0] += 1.0f;
		while (slx[0] >= 1.0f)
			slx[0] -= 1.0f;
		while (sly[0] >= 1.0f)
			sly[0] -= 1.0f;
		for (int i = 1; i < slpnum; i++)
		{
			float pixel[3], xv, yv;
			float px = slx[i - 1], py = sly[i - 1];
			while (px < 0.0f)
				px += 1.0f;
			while (py < 0.0f)
				py += 1.0f;
			while (px >= 1.0f)
				px -= 1.0f;
			while (py >= 1.0f)
				py -= 1.0f;
			//glReadPixels(int(px*float(size)),int(py*float(size)),1,1,GL_RGB,GL_FLOAT,(void *)pixel);
			getSpeed(size, pixel, px, py);
			xv = pixel[0];
			yv = pixel[1];
			float v = sqrt(xv * xv + yv * yv);
			if (v == 0.0f)
				v = 1.0f;
			float dl = 0.005f/scale;

			getSpeed(size, pixel, px + dl * xv / v / 2.0f, py + dl * yv / v
					/ 2.0f);
			xv = pixel[0];
			yv = pixel[1];
			v = sqrt(xv * xv + yv * yv);
			if (v == 0.0f)
				v = 1.0f;

			slx[i] = slx[i - 1] + dl * xv / v;
			sly[i] = sly[i - 1] + dl * yv / v;

		}
		Fbo::unbind();
	}

	if (game->isRightDown() && !painting)
	{
		flower.bindInk();
		Shader::disable();
		glActiveTextureARB(GL_TEXTURE2_ARB);
		glDisable(GL_TEXTURE_2D);
		glActiveTextureARB(GL_TEXTURE1_ARB);
		glDisable(GL_TEXTURE_2D);
		glActiveTextureARB(GL_TEXTURE0_ARB);
		glDisable(GL_TEXTURE_2D);

		glColor3f(inkRed*(1.0f-inkNew)+inkRedNew*inkNew,inkGreen*(1.0f-inkNew)+inkGreenNew*inkNew,inkBlue*(1.0f-inkNew)+inkBlueNew*inkNew);
		//	glColor3f(1.0,1.0,1.0);
		drawMouseOffScreen();
		Fbo::unbind();
	}
	if (game->isKeyDown('t'))
	{
		if(!coordInk)
		{
			flower.bindInk();
			Shader::disable();
			glActiveTextureARB(GL_TEXTURE2_ARB);
			glDisable(GL_TEXTURE_2D);
			glActiveTextureARB(GL_TEXTURE1_ARB);
			glDisable(GL_TEXTURE_2D);
			glActiveTextureARB(GL_TEXTURE0_ARB);
			glDisable(GL_TEXTURE_2D);

			glColor3f(0.0f, 0.0f, 0.0f);
			glBegin(GL_QUADS);
			glVertex2f(0.0f, 0.0f);
			glVertex2f(1.0f, 0.0f);
			glVertex2f(1.0f, 1.0f);
			glVertex2f(0.0f, 1.0f);
			glEnd();
			Fbo::unbind();
		}
		else
		{
			TexGroup::getSingleton()->bind(flowerTex, 0);
			initFromFGMat.enable();
			flower.bindInk();

			glBegin(GL_QUADS);
			glTexCoord2f(0.0f, 0.0f);
			glVertex2f(0.0f, 0.0f);
			glTexCoord2f(1.0f, 0.0f);
			glVertex2f(1.0f, 0.0f);
			glTexCoord2f(1.0f, 1.0f);
			glVertex2f(1.0f, 1.0f);
			glTexCoord2f(0.0f, 1.0f);
			glVertex2f(0.0f, 1.0f);
			glEnd();
			Fbo::unbind();
			Shader::disable();
		}
	}
	if (game->isKeyDown('r'))
	{
		flower.bindVel();
		Shader::disable();
		glActiveTextureARB(GL_TEXTURE2_ARB);
		glDisable(GL_TEXTURE_2D);
		glActiveTextureARB(GL_TEXTURE1_ARB);
		glDisable(GL_TEXTURE_2D);
		glActiveTextureARB(GL_TEXTURE0_ARB);
		glDisable(GL_TEXTURE_2D);

		glColor3f(0.0f, 0.0f, 0.0f);
		glBegin(GL_QUADS);
		glVertex2f(0.0f, 0.0f);
		glVertex2f(1.0f, 0.0f);
		glVertex2f(1.0f, 1.0f);
		glVertex2f(0.0f, 1.0f);
		glEnd();
		Fbo::unbind();
	}
	displayResult();


	float sx = float(game->getMouseX()) / float(game->getResY());
	float sy = 1.0f - float(game->getMouseY()) / float(game->getResY());
	x = (sx-0.5* float(game->getResX())/ float(game->getResY()))/scale+ viewX;
	y = (sy-0.5)/scale+ viewY;
	if(x>0)
		x=x-static_cast<int>(x);
	else
		x=x-static_cast<int>(x)+1.0f;
	if(y>0)
		y=y-static_cast<int>(y);
	else
		y=y-static_cast<int>(y)+1.0f;
	float s = 0.02/scale;
	oldx1=x - s;
	oldx2=x + s;
	oldy1=y - s;
	oldy2=y + s;
}
void Particle::Render(Camera* camera, unsigned int i, bool drawAxes)
{
    switch( this->_type )
    {
    case BillBoard:
        break;
    case VectorAligned:
        break;
    case ScreenFacing:
    default:
    {
        Vector3f particleToCamera = camera->GetPosition()-this->_position;
        this->_depth = particleToCamera.Length();

        Vector3f cameraYAxis = camera->GetEulerRotation()*Vector3f(sin(this->_rotation), cos(this->_rotation), 0.0f);
        Vector3f localX = cameraYAxis.Cross(particleToCamera);
        Vector3f localY = particleToCamera.Cross(localX);

        localX.Normalize();
        localY.Normalize();

        // Set blend mode
        switch( this->_blendMode )
        {
        case Subtractive:
            glBlendFunc(GL_ONE_MINUS_SRC_ALPHA, GL_ONE);
            break;
        case Additive:
            glBlendFunc(GL_SRC_ALPHA, GL_ONE);
            break;
        case Normal:
        default:
            glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
            break;
        }

        // Evaluate animators
        float t = 1.0f-this->_life/this->_maxLife;

        Vector2f size = this->_size->GetValue(t);

        // Bind texture
        if( this->_texture )
        {
            glBindTexture(GL_TEXTURE_2D, this->_texture->GetTextureName());
        }

        // Render
        glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
        glBegin(GL_QUADS);

        glColor4f(this->_color.r, this->_color.g, this->_color.b, this->_color.a);

        // TODO (Viet Nguyen): Get rid of texture coordinate hacks!!!!

        glTexCoord2f(0.0f, 0.0f);
        glVertex3fv((float*)
                    (this->_position+(-localX)*size.width+(-localY)*size.height));

        glTexCoord2f(1.0f/4.0f/*!!!!*/, 0.0f);
        glVertex3fv((float*)
                    (this->_position+localX*size.width+(-localY)*size.height));

        glTexCoord2f(1.0f/4.0f/*!!!!*/, 1.0f);
        glVertex3fv((float*)
                    (this->_position+localX*size.width+localY*size.height));

        glTexCoord2f(0.0f, 1.0f);
        glVertex3fv((float*)
                    (this->_position+(-localX)*size.width+localY*size.height));

        glEnd();

        // Unbind texture
        if( this->_texture)
        {
            glBindTexture(GL_TEXTURE_2D, 0);
        }

        if( drawAxes )
        {
            glBegin(GL_LINES);
            glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);

            glColor4f(1.0f, 0.0f, 0.0f, 1.0f);
            glVertex3fv((float*)(this->_position));
            glVertex3fv((float*)(this->_position+localX*size.width));

            glColor4f(0.0f, 1.0f, 0.0f, 1.0f);
            glVertex3fv((float*)(this->_position));
            glVertex3fv((float*)(this->_position+localY*size.height));

            glEnd();
        }
    }
    }
}
Exemplo n.º 3
0
static void
draw_frame (ModeInfo *mi, image_frame *frame, time_t now, Bool body_p)
{
  carousel_state *ss = &sss[MI_SCREEN(mi)];
  int wire = MI_IS_WIREFRAME(mi);

  GLfloat texw  = frame->current.geom.width  / (GLfloat) frame->current.tw;
  GLfloat texh  = frame->current.geom.height / (GLfloat) frame->current.th;
  GLfloat texx1 = frame->current.geom.x / (GLfloat) frame->current.tw;
  GLfloat texy1 = frame->current.geom.y / (GLfloat) frame->current.th;
  GLfloat texx2 = texx1 + texw;
  GLfloat texy2 = texy1 + texh;
  GLfloat aspect = ((GLfloat) frame->current.geom.height /
                    (GLfloat) frame->current.geom.width);

  glBindTexture (GL_TEXTURE_2D, frame->current.texid);

  glPushMatrix();

  /* Position this image on the wheel.
   */
  glRotatef (frame->theta, 0, 1, 0);
  glTranslatef (0, 0, frame->r);

  /* Scale down the image so that all N frames fit on the wheel
     without bumping in to each other.
  */
  {
    GLfloat t, s;
    switch (ss->nframes)
      {
      case 1:  t = -1.0; s = 1.7; break;
      case 2:  t = -0.8; s = 1.6; break;
      case 3:  t = -0.4; s = 1.5; break;
      case 4:  t = -0.2; s = 1.3; break;
      default: t =  0.0; s = 6.0 / ss->nframes; break;
      }
    glTranslatef (0, 0, t);
    glScalef (s, s, s);
  }

  /* Center this image on the wheel plane.
   */
  glTranslatef (-0.5, -(aspect/2), 0);

  /* Move as per the "zoom in and out" setting.
   */
  if (zoom_p)
    {
      double x, y, z;
      /* Only use the Z component of the rotator for in/out position. */
      get_position (frame->rot, &x, &y, &z, !ss->button_down_p);
      glTranslatef (0, 0, z/2);
    }

  /* Compute the "drop in and out" state.
   */
  switch (frame->mode)
    {
    case EARLY:
      abort();
      break;
    case NORMAL:
      if (!ss->button_down_p &&
          now >= frame->expires &&
          ss->loads_in_progress == 0)  /* only load one at a time */
        load_image (mi, frame);
      break;
    case LOADING:
      break;
    case OUT:
      if (--frame->mode_tick <= 0) {
        image swap = frame->current;
        frame->current = frame->loading;
        frame->loading = swap;

        frame->mode = IN;
        frame->mode_tick = fade_ticks / speed;
      }
      break;
    case IN:
      if (--frame->mode_tick <= 0)
        frame->mode = NORMAL;
      break;
    default:
      abort();
    }

  /* Now translate for current in/out state.
   */
  if (frame->mode == OUT || frame->mode == IN)
    {
      GLfloat t = (frame->mode == OUT
                   ? frame->mode_tick / (fade_ticks / speed)
                   : (((fade_ticks / speed) - frame->mode_tick + 1) /
                      (fade_ticks / speed)));
      t = 5 * (1 - t);
      if (frame->from_top_p) t = -t;
      glTranslatef (0, t, 0);
    }

  if (body_p)					/* Draw the image quad. */
    {
      if (! wire)
        {
          glColor3f (1, 1, 1);
          glNormal3f (0, 0, 1);
          glEnable (GL_TEXTURE_2D);
          glBegin (GL_QUADS);
          glNormal3f (0, 0, 1);
          glTexCoord2f (texx1, texy2); glVertex3f (0, 0, 0);
          glTexCoord2f (texx2, texy2); glVertex3f (1, 0, 0);
          glTexCoord2f (texx2, texy1); glVertex3f (1, aspect, 0);
          glTexCoord2f (texx1, texy1); glVertex3f (0, aspect, 0);
          glEnd();
        }

      /* Draw a box around it.
       */
      glLineWidth (2.0);
      glColor3f (0.5, 0.5, 0.5);
      glDisable (GL_TEXTURE_2D);
      glBegin (GL_LINE_LOOP);
      glVertex3f (0, 0, 0);
      glVertex3f (1, 0, 0);
      glVertex3f (1, aspect, 0);
      glVertex3f (0, aspect, 0);
      glEnd();

    }
  else					/* Draw a title under the image. */
    {
      XCharStruct e;
      int sw, sh;
      GLfloat scale = 0.05;
      char *title = frame->current.title ? frame->current.title : "(untitled)";
      texture_string_metrics (ss->texfont, title, &e, 0, 0);
      sw = e.width;
      sh = e.ascent + e.descent;

      glTranslatef (0, -scale, 0);

      scale /= sh;
      glScalef (scale, scale, scale);

      glTranslatef (((1/scale) - sw) / 2, 0, 0);
      glColor3f (1, 1, 1);

      if (!wire)
        {
          glEnable (GL_TEXTURE_2D);
          print_texture_string (ss->texfont, title);
        }
      else
        {
          glBegin (GL_LINE_LOOP);
          glVertex3f (0,  0,  0);
          glVertex3f (sw, 0,  0);
          glVertex3f (sw, sh, 0);
          glVertex3f (0,  sh, 0);
          glEnd();
        }
    }

  glPopMatrix();
}
Exemplo n.º 4
0
void label_draw(struct label *l)
{
	char *text;
	const struct glyph *g;
	float x, y;
	int spacing;

	x = 0;
	y = 0;

	glColor3f(1.0, 1.0, 1.0);

	glPushMatrix();
	glLoadIdentity();

	glTranslatef(l->x, l->y, 0);
	glEnable(GL_TEXTURE_2D);
	glEnable(GL_BLEND);
	glBlendFunc(GL_ONE, GL_ONE);

	text = l->text;

	spacing = l->font->spacing;

	while (*text) {
		if (*text == ' ') {
			x += 3*spacing;

			text++;
		} else {

			g = font_get_glyph(l->font, *text);

			if (g == NULL)
				panic("Cannot load glyph for '%c'.", *text);

			glBindTexture(GL_TEXTURE_2D, g->texture);

			glBegin(GL_QUADS);

			glTexCoord2f(0.0, 0.0);
			glVertex2f(x, y);

			glTexCoord2f(1.0, 0.0);
			glVertex2f(x + g->width, y);

			glTexCoord2f(1.0, 1.0);
			glVertex2f(x + g->width, g->height);

			glTexCoord2f(0.0, 1.0);
			glVertex2f(x, g->height);

			x += g->width + spacing;

			glEnd();

			text++;
		}
	}

	glDisable(GL_TEXTURE_2D);
	glDisable(GL_BLEND);
	
	glPopMatrix();
	SDL_GL_SwapBuffers();
}
Exemplo n.º 5
0
static void
redraw(void)
{
  int i;

  glDepthMask(GL_TRUE);
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

  glPushMatrix();
  glRotatef(15.0, 1.0, 0.0, 0.0);
  glRotatef(angle, 0.0, 1.0, 0.0);


  /* Draw the floor. */
/*  glEnable(GL_TEXTURE_2D);*/
  glColor3f(0.1, 0.5, 1.0);
  glBegin(GL_QUADS);
    glTexCoord2f(0.0, 0.0);
    glVertex3f(-EDGE, -0.05, -EDGE);
    glTexCoord2f(20.0, 0.0);
    glVertex3f(EDGE, -0.05, -EDGE);
    glTexCoord2f(20.0, 20.0);
    glVertex3f(EDGE, -0.05, EDGE);
    glTexCoord2f(0.0, 20.0);
    glVertex3f(-EDGE, -0.05, EDGE);
  glEnd();

  /* Allow particles to blend with each other. */
  glDepthMask(GL_FALSE);

  if (blend)
     glEnable(GL_BLEND);

  if (sprite) {
     glEnable(GL_TEXTURE_2D);
#ifdef GL_ARB_point_sprite
     glEnable(GL_POINT_SPRITE_ARB);
#endif
  }

  glColor3f(1,1,1);
  glBegin(GL_POINTS);
    for (i=0; i<numPoints; i++) {
      /* Draw alive particles. */
      if (colorList[i] != DEAD) {
        if (!sprite) glColor4fv(colorSet[colorList[i]]);
        glVertex3fv(pointList[i]);
      }
    }
  glEnd();

  glDisable(GL_TEXTURE_2D);
#ifdef GL_ARB_point_sprite
  glDisable(GL_POINT_SPRITE_ARB);
#endif
  glDisable(GL_BLEND);

  glPopMatrix();

  glutSwapBuffers();
}
Exemplo n.º 6
0
//Peter: Used great billboard drawing trick from http://www.lighthouse3d.com/opengl/billboarding/index.php?billCheat.
void Sprite::draw(Vec3d &location)
{

	GLfloat left = convertScale(mTexPosition.X(), 0, mpTexture->getWidth(), 0.0f, 1.0f);
	GLfloat right = convertScale(mTexPosition.X() + mSize.X(), 0, mpTexture->getWidth(), 0.0f, 1.0f);

	GLfloat up = convertScale(mTexPosition.Y() + mSize.Y(), 0, mpTexture->getHeight(), 1.0f, 0.0f);
	GLfloat down = convertScale(mTexPosition.Y(), 0, mpTexture->getHeight(), 1.0f, 0.0f);

	glPushMatrix();

	glTranslatef(location.X, location.Y, location.Z);

	glPushMatrix();

	//glTranslatef(mpTexture->getRatio()*0.5,0,0);

	mpTexture->setAsActiveTexture();

	float modelview[16];
	int i,j;

	// save the current modelview matrix
	glPushMatrix();

	// get the current modelview matrix
	glGetFloatv(GL_MODELVIEW_MATRIX , modelview);

	// undo all rotations
	// beware all scaling is lost as well 
	for( i=0; i<3; i++ ) 
		for( j=0; j<3; j++ ) 
		{
			if ( i==j )
				modelview[i*4+j] = 1.0;
			else
				modelview[i*4+j] = 0.0;
		}

	// set the modelview with no rotations and scaling
	glLoadMatrixf(modelview);

	glBegin(GL_QUADS);
	// Front Face
	glColor3f(1,1,1);

	glTexCoord2f(left,up);
	glVertex3f(0.0f, -0.5f, 0.0f);              // Top Left

	glTexCoord2f(right,up);
	glVertex3f( /*mpTexture->getRatio()*/(mSize.X()/mSize.Y())*1.0f, -0.5f, 0.0f);              // Top Right

	glTexCoord2f(right,down);
	glVertex3f( /*mpTexture->getRatio()*/(mSize.X()/mSize.Y())*1.0f,0.5f, 0.0f);              // Bottom Right

	glTexCoord2f(left,down);
	glVertex3f(0.0f,0.5f, 0.0f);              // Bottom Left

	glEnd();

	glPopMatrix();

	// restores the modelview matrix
	glPopMatrix();

	glPopMatrix();
}
Exemplo n.º 7
0
void GLStrokeRenderer::RenderStrokeRep(StrokeRep *iStrokeRep) const
{
  CHECK_FOR_ERROR;

  glPushAttrib(GL_COLOR_BUFFER_BIT);
  Stroke::MediumType strokeType = iStrokeRep->getMediumType();
  // int averageTextureAlpha=0.5; //default value
  // if (strokeType==OIL_STROKE)
    // averageTextureAlpha=0.75; 
  // if (strokeType>=NO_BLEND_STROKE)
    // averageTextureAlpha=1.0; 
  // if (strokeType<0)
    // {
      // renderNoTexture(iStrokeRep);
      // return;
    // }
  int i;
  glDisable(GL_CULL_FACE);
  glDisable(GL_LIGHTING);
  glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
  glShadeModel(GL_SMOOTH);
  glDisable(GL_DEPTH_TEST);
    
  glEnable(GL_BLEND);
  //  glDisable(GL_BLEND);

  if(strokeType==Stroke::DRY_MEDIUM)
    {
      glBlendEquation(GL_MIN);  //changed this from GL_MAX in order to work for a black background image instead of white
    }
  else if(strokeType==Stroke::OPAQUE_MEDIUM || strokeType==Stroke::DRY_MEDIUM)
    {
      glBlendEquation(GL_FUNC_ADD);
      //glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

      //      glBlendEquationSeparate(GL_FUNC_ADD, GL_FUNC_REVERSE_SUBTRACT);
      glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA,
			  GL_ONE_MINUS_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    }
  else
    {
            glBlendEquation(GL_FUNC_ADD);
      //      glBlendFunc(GL_SRC_ALPHA, GL_ONE);

      //      glBlendEquationSeparate(GL_FUNC_ADD, GL_FUNC_SUBTRACT);
      glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE,
			  GL_ONE_MINUS_SRC_ALPHA, GL_ONE);

      //      printf("using opaque\n");
    }


  //  glBlendFunc(GL_ONE, GL_ZERO);

  //  glDisable(GL_TEXTURE_2D);
  glEnable(GL_BLEND);
  //glDisable(GL_BLEND);
  //  glDisable(GL_TEXTURE_1D);
  glEnable(GL_TEXTURE_2D);


  glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
  //glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);

  //first texture, basically the only one for lighter strokes
  glBindTexture(GL_TEXTURE_2D, iStrokeRep->getTextureId()); 
  //glBindTexture(GL_TEXTURE_2D, _textureManager.getPaperTextureIndex()); 


  // TODO:   READ BACK PIXEL TRANSFER, PIXEL MAP, MATRICES, ETC.
  /*
  // loop over transfer functions and print out glIsEnabled()
  GLenum funcs[] = { GL_TEXTURE_1D,
                     GL_INDEX_LOGIC_OP, 
                     GL_COLOR_LOGIC_OP,
		     GL_COLOR_MATERIAL,
		     GL_COLOR_SUM,
		     GL_COLOR_TABLE,
		     GL_CONVOLUTION_1D,
		     GL_CONVOLUTION_2D,
		     GL_INDEX_LOGIC_OP,
		     GL_MAP1_COLOR_4,
		     GL_MAP1_INDEX,
		     GL_MAP1_TEXTURE_COORD_1,
		     GL_MAP1_TEXTURE_COORD_2,
		     GL_MAP1_TEXTURE_COORD_3,
		     GL_MAP1_TEXTURE_COORD_4,
		     GL_MAP2_INDEX,
		     GL_POST_COLOR_MATRIX_COLOR_TABLE,
		     GL_POST_CONVOLUTION_COLOR_TABLE,
		     GL_SEPARABLE_2D };
  for(int i =0; i<17;i++)
    printf("[(%d) %0X: %s]\n", i, funcs[i], (glIsEnabled(funcs[i]) ? "ENABLED" : "disabled"));

  
  GLfloat cmat[16];
  glGetFloatv(GL_COLOR_MATRIX, cmat);
  printf("color matrix: %f %f %f %f; %f %f %f %f; %f %f %f %f; %f %f %f %f\n",
	 cmat[0], cmat[1], cmat[2], cmat[3], cmat[4],cmat[5], cmat[6], cmat[7], cmat[8],
	 cmat[9], cmat[10], cmat[11], cmat[12], cmat[13], cmat[14], cmat[15]);*/


  //      static bool printed = false;

  //      if (!printed)
  //{
	  //	  printf("first point:(%f, %f) ",svRep->point2d()[0], svRep->point2d()[1]);
	  /*
	  printf("glstrokerenderer: (outputWidth = %d, outputHeight = %d)\n", outputWidth, outputHeight);
	  double matrix[16];
	  glGetDoublev(GL_MODELVIEW_MATRIX, matrix);
	  printf("Modelview= [%f %f %f %f; %f %f %f %f; %f %f %f %f; %f %f %f %f]'\n", 
		 matrix[0], matrix[1], matrix[2], matrix[3],matrix[4],matrix[5],matrix[6],matrix[7],matrix[8],matrix[9], 
		 matrix[10],matrix[11],matrix[12],matrix[13],matrix[14],matrix[15]);  
	  glGetDoublev(GL_PROJECTION_MATRIX, matrix);
	  printf("Projection= [%f %f %f %f; %f %f %f %f; %f %f %f %f; %f %f %f %f]'\n", 
		 matrix[0], matrix[1], matrix[2], matrix[3],matrix[4],matrix[5],matrix[6],matrix[7],matrix[8],matrix[9], 
		 matrix[10],matrix[11],matrix[12],matrix[13],matrix[14],matrix[15]);

	  double viewp[4];
	  glGetDoublev(GL_VIEWPORT, viewp);
	  printf("GL1: Viewport = [%f %f %f %f]\n", viewp[0], viewp[1], viewp[2], viewp[3]);
	  */



	  //	  printed = true;
  //	}
      /*
  glDisable(GL_TEXTURE_2D);
  glDisable(GL_BLEND);

  glColor4f(1,.5,.2,.5);
  glBegin(GL_TRIANGLES);
  glVertex2f(0,0);
  glVertex2f(100,50);
  glVertex2f(50,100);
  glEnd();
  
  glEnable(GL_TEXTURE_2D);
  glEnable(GL_BLEND);
      */

      //  glViewport(0,0,outputWidth, outputHeight);
  
  vector<Strip*>& strips = iStrokeRep->getStrips();
  for(vector<Strip*>::iterator s=strips.begin(), send=strips.end();
  s!=send;
  ++s){
    Strip::vertex_container& vertices = (*s)->vertices();



    glBegin(GL_TRIANGLE_STRIP);
    for(Strip::vertex_container::iterator v=vertices.begin(), vend=vertices.end();
    v!=vend;
    ++v){
      StrokeVertexRep * svRep = (*v);
      Vec3r color = svRep->color();
      real alpha = svRep->alpha();
      glColor4f(complementColor(color[0]), complementColor(color[1]), 
      		complementColor(color[2]), alpha);
      //      glColor4f(1,0,0,1);
      
      static bool printed2 = false;
      /*
      if (!printed2)
	{
	  printf("first point: (%f, %f)\n", svRep->point2d()[0], svRep->point2d()[1]);
	  printed2 =true;
	}
      */

      glTexCoord2f(svRep->texCoord()[0],svRep->texCoord()[1] );
      glVertex2f(svRep->point2d()[0], svRep->point2d()[1]);
    }  
    glEnd();
  }
//  if (strokeType>=NO_BLEND_STROKE) return;
  //  //return;
  //
  //  //second texture, the complement, for stronger strokes
  //  glBindTexture(GL_TEXTURE_2D, _textureManager.getTextureIndex(2*strokeType+1)); 
  //  glBegin(GL_TRIANGLE_STRIP);
  //  for(i=0; i<_sizeStrip; i++)
  //  {
  //    glColor4f(complementColor(_color[i][0]), 
  //      complementColor(_color[i][1]), 
  //      complementColor(_color[i][2]), _alpha[i]);
  //    glTexCoord2f(_texCoord[i][0],_texCoord[i][1] );
  //    glVertex2f(_vertex[i][0], _vertex[i][1]);
  //  }
  //  glEnd();

  /*
	  double viewp[4];
	  glGetDoublev(GL_VIEWPORT, viewp);
	  printf("GL2: Viewport = [%f %f %f %f]\n", viewp[0], viewp[1], viewp[2], viewp[3]);
  */

  glPopAttrib();

  CHECK_FOR_ERROR;
}
Exemplo n.º 8
0
	void Graphics::RenderPathMesh(const std::vector<Node*> &nodes, int cells, float size, bool flipX, bool flipY)
	{
		glBegin(GL_QUADS);
		for (int i = 0; i < nodes.size()-1; i++)
		{
			if (nodes[i]->variant != -1 && nodes[i]->variant < cells)
			{
				Vector2 diff1;
				Vector2 perp1;

				/*
				if (i-1 >= 0)
				{
					diff1 = points[i] - points[i-1];
					perp1 = diff1.GetNormalized().GetPerpendicularLeft();
					//diff1 = points[i + 1] - points[i];
					//perp1 = perp1*0.5f + diff1.GetNormalized().GetPerpendicularLeft()*0.5f;
				}
				else
				{
					diff1 = points[i + 1] - points[i];
					perp1 = diff1.GetNormalized().GetPerpendicularLeft();
				}
				*/

				diff1 = nodes[i + 1]->position - nodes[i]->position;
				perp1 = diff1.GetNormalized().GetPerpendicularLeft();

				Vector2 diff2;
				Vector2 perp2 = perp1;
			
				if (i+2 < nodes.size())
				{
					diff2 = nodes[i+2]->position - nodes[i+1]->position;
					perp2 = diff2.GetNormalized().GetPerpendicularLeft();
				}
				else
				{
					perp2 = perp1;
				}
			
				Vector2 pos1 = nodes[i]->position;
				Vector2 pos2 = nodes[i+1]->position;
			
				Vector2 texOffset = Vector2::zero;
				Vector2 texScale = Vector2::one * 1.0f/(float)cells;
				texOffset.x = (nodes[i]->variant % (cells)) * texScale.x;
				texOffset.y = (int)(nodes[i]->variant / (cells)) * texScale.y;

				if (flipY)
				{
					texOffset.y = 1.0f - texOffset.y;
					texScale.y = - texScale.y;
					//printf("%f, %f\n", texOffset.y, texScale.y);
				}
			
				Graphics::SetColor(nodes[i]->color);
				glTexCoord2f(texOffset.x, texOffset.y);
				Vertex(pos1 - perp1 * nodes[i]->scale.y * size * 0.5f);

				Graphics::SetColor(nodes[i+1]->color);
				glTexCoord2f(texOffset.x + texScale.x, texOffset.y);
				Vertex(pos2 - perp2 * nodes[i+1]->scale.y * size * 0.5f);

				Graphics::SetColor(nodes[i+1]->color);
				glTexCoord2f(texOffset.x + texScale.x, texOffset.y + texScale.y);
				Vertex(pos2 + perp2 * nodes[i+1]->scale.y * size * 0.5f);

				Graphics::SetColor(nodes[i]->color);
				glTexCoord2f(texOffset.x, texOffset.y + texScale.y);
				Vertex(pos1 + perp1 * nodes[i]->scale.y * size * 0.5f);
			}
		}
		glEnd();
	}
Exemplo n.º 9
0
void init_site()
{
   list = glGenLists(NLIST);

   glNewList(list, GL_COMPILE);
   for (int v = 0; v< (NUM_PANELS_FLOOR*4);)
   {
      bool text = (v < 4);
      // unbind the texture
      //glDisable(GL_TEXTURE_2D); //doesn't work
      if (v == 4)
      {
         // make the sides of the pool the fog color
         glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, fogColor);
         glColor3f ( fogColor[0], fogColor[1],  fogColor[2]) ;
      }
      else if (text)
      {
         glEnable(GL_TEXTURE_2D);
         glBindTexture(GL_TEXTURE_2D, texName[0]);
      }

      glBegin(GL_QUADS);
      if (text) glTexCoord2f(0.0, 0.0);
      glVertex3f(vertices[v].x, vertices[v].y, vertices[v].z);
      v++;
      if (text) glTexCoord2f(1.0, 0.0);
      glVertex3f(vertices[v].x, vertices[v].y, vertices[v].z);
      v++;
      if (text) glTexCoord2f(1.0, 1.0);
      glVertex3f(vertices[v].x, vertices[v].y, vertices[v].z);
      v++;
      if (text) glTexCoord2f(0.0, 1.0);
      glVertex3f(vertices[v].x, vertices[v].y, vertices[v].z);
      v++;
      glEnd();
      if (text) glDisable(GL_TEXTURE_2D);

   }

   glEndList();


   glNewList(list+1, GL_COMPILE);

   // material reacts to light
   const float orange_boards[] = { 0.5f, 0.25f, 0.0f };
   glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, orange_boards);
   glColor3f (orange_boards[0], orange_boards[1], orange_boards[2]) ;

   for (int i = 0; i< NUM_BOARDS; i++)
   {
      glTranslatef(b_positions[i].x, b_positions[i].y, b_positions[i].z);
      glRotatef(b_rotations[i], 0.0, 1.0, 0.0);

      for (int v = 0; v< NUM_PANELS_BOARDS; v++)
      {
         glBegin(GL_QUADS);
         glNormal3f(0.0,1.0,0.0);
         //glTexCoord2f(0.0, 0.0);
         glVertex3f(boards[v].x, boards[v].y, boards[v].z);
         v++;
         glNormal3f(0.0,1.0,0.0);
         //glTexCoord2f(1.0, 0.0);
         glVertex3f(boards[v].x, boards[v].y, boards[v].z);
         v++;
         glNormal3f(0.0,1.0,0.0);
         //glTexCoord2f(1.0, 1.0);
         glVertex3f(boards[v].x, boards[v].y, boards[v].z);
         v++;
         glNormal3f(0.0,1.0,0.0);
         //glTexCoord2f(0.0, 1.0);
         glVertex3f(boards[v].x, boards[v].y, boards[v].z);
         glEnd();
      }

      // undo rotation/translation
      glRotatef(-b_rotations[i], 0.0, 1.0, 0.0);
      glTranslatef(-b_positions[i].x, -b_positions[i].y, -b_positions[i].z);
   }

   glEndList();

   glNewList(list+2, GL_COMPILE);
   for (int i = 0; i< NUM_BOXES; i++)
   {
      glTranslatef(bx_positions[i].x, bx_positions[i].y, bx_positions[i].z);
      glRotatef(bx_rotations[i], 0.0, 1.0, 0.0);

      for (int v = 0; v< NUM_PANELS_BOXES; v++)
      {
         int k = 4*v;

         if (v == 0)
         {
            float mcolor[] = { 1.f, 1.f, 1.f, 1.f };
            glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, mcolor);
            glColor3f ( mcolor[0], mcolor[1], mcolor[2]) ;
         }
         else if (v == (NUM_PANELS_BOXES-1))
         {
            glEnable(GL_TEXTURE_2D);
            glBindTexture(GL_TEXTURE_2D, texName[4 + i]);
            float mcolor[] = { 0.f, 0., 0.f, 1.f };
            glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, mcolor);
            glColor3f (mcolor[0], mcolor[1], mcolor[2]);
         }

         glBegin(GL_QUADS);
         if (v == (NUM_PANELS_BOXES-1))
         {
            glNormal3f(0.0f,1.0f,0.0f);
            glTexCoord2f(0.0, 1.0);
         }
         glVertex3f(boxes[k].x, boxes[k].y, boxes[k].z);
         k++;
         if (v == (NUM_PANELS_BOXES-1))
         {
            glNormal3f(0.0f,1.0f,0.0f);
            glTexCoord2f(1.0, 1.0);
         }
         glVertex3f(boxes[k].x, boxes[k].y, boxes[k].z);
         k++;
         if (v == (NUM_PANELS_BOXES-1))
         {
            glNormal3f(0.0f,1.0f,0.0f);
            glTexCoord2f(1.0, 0.0);
         }
         glVertex3f(boxes[k].x, boxes[k].y, boxes[k].z);
         k++;
         if (v == (NUM_PANELS_BOXES-1))
         {
            glNormal3f(0.0f,1.0f,0.0f);
            glTexCoord2f(0.0, 0.0);
         }
         glVertex3f(boxes[k].x, boxes[k].y, boxes[k].z);
         glEnd();
         if (v == (NUM_PANELS_BOXES-1))
            glDisable(GL_TEXTURE_2D);
      }

      // undo rotation/translation
      glRotatef(-bx_rotations[i], 0.0, 1.0, 0.0);
      glTranslatef(-bx_positions[i].x, -bx_positions[i].y, -bx_positions[i].z);
   }
   glEndList();

   glNewList(list+3, GL_COMPILE);
   glEnable(GL_TEXTURE_2D);
   glBindTexture(GL_TEXTURE_2D, texName[1]);
   int v = 0;
   glBegin(GL_QUADS);

   glTexCoord2f(0.0, 0.0);
   glVertex3f(ceiling[v].x, ceiling[v].y, ceiling[v].z);
   v++;
   glTexCoord2f(4.0, 0.0);
   glVertex3f(ceiling[v].x, ceiling[v].y, ceiling[v].z);
   v++;
   glTexCoord2f(4.0, 4.0);
   glVertex3f(ceiling[v].x, ceiling[v].y, ceiling[v].z);
   v++;
   glTexCoord2f(0.0, 4.0);
   glVertex3f(ceiling[v].x, ceiling[v].y, ceiling[v].z);
   v++;
   glEnd();
   glDisable(GL_TEXTURE_2D);
   glEndList();

   /***********************************************************/

   g1 = gluNewQuadric();
   g2 = gluNewQuadric();
   g3 = gluNewQuadric();
   for (int i=0; i<WINDOW_CUTOUT_PARTS; i++)
      window_cutout[i] = gluNewQuadric();
   for (int i=0; i<GOALPOST_PARTS * 2; i++)
      goalpost[i] = gluNewQuadric();
   for (int i=0; i<NUM_BUOYS * 2; i++)
   {
      buoys[i] = gluNewQuadric();
      gluQuadricDrawStyle(buoys[i], GLU_FILL);
   }

   for (int i=0; i<2 * EXIT_SIDES; i++)
   {
      EXIT[i] = gluNewQuadric();
      gluQuadricDrawStyle(EXIT[i], GLU_FILL);
   }

   gluQuadricDrawStyle(g1,   GLU_FILL);
   gluQuadricDrawStyle(g2,   GLU_FILL);
   gluQuadricDrawStyle(g3,   GLU_FILL);
}
Exemplo n.º 10
0
void RenderWorld(void)
{
    glEnable(GL_TEXTURE_2D);
    glDisable(GL_DEPTH_TEST);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE );
    glEnable(GL_BLEND);

    glBindTexture(GL_TEXTURE_2D, pyramidTex);

    // 在纹理矩阵中移动纹理
    glMatrixMode(GL_TEXTURE);
    glLoadIdentity();
    // glTranslatef(0.0f, -tex_y, 0.0f);
    // glScalef(0.0f, tex_y, 0.0f);

    glMatrixMode(GL_MODELVIEW);
#if 0
    for (int i=0; i<1; i++)
    {
        glPushMatrix();
#if 0
        glColor3f(0.0f, 1.0f, 1.0f);
        glBegin(GL_TRIANGLE_FAN); {
            glTexCoord2f(0.0f, 1.0f); glVertex3f( 0.0f, 0.0f, 0.0f);
            glTexCoord2f(0.0f, 0.0f); glVertex3f(-0.1f, 1.1f, 0.1f);
            glTexCoord2f(1.0f, 0.0f); glVertex3f( 0.1f, 1.1f, 0.1f);
            glTexCoord2f(0.0f, 0.0f); glVertex3f( 0.1f, 1.1f,-0.1f);
            glTexCoord2f(1.0f, 0.0f); glVertex3f(-0.1f, 1.1f,-0.1f);
            glTexCoord2f(0.0f, 0.0f); glVertex3f(-0.1f, 1.1f, 0.1f);
        } glEnd();

        glScalef(-1.0, -1.0, -1.0);
        glColor3f(1.0f, 1.0f, 0.0f);
        glBegin(GL_TRIANGLE_FAN); {
            glTexCoord2f(0.0f, 1.0f); glVertex3f( 0.0f, 0.0f, 0.0f);
            glTexCoord2f(0.0f, 0.0f); glVertex3f(-0.1f, 1.1f, 0.1f);
            glTexCoord2f(1.0f, 0.0f); glVertex3f( 0.1f, 1.1f, 0.1f);
            glTexCoord2f(0.0f, 0.0f); glVertex3f( 0.1f, 1.1f,-0.1f);
            glTexCoord2f(1.0f, 0.0f); glVertex3f(-0.1f, 1.1f,-0.1f);
            glTexCoord2f(0.0f, 0.0f); glVertex3f(-0.1f, 1.1f, 0.1f);
        } glEnd();
#else
        glColor3f(0.0f, 1.0f, 1.0f);
        // DrawCone(1.1, 0.13, 4);

        glScalef(-1.0, -1.0, -1.0);
        glColor3f(1.0f, 1.0f, 0.0f);
        // DrawCone(1.1, 0.13, 4);
#endif
        glPopMatrix();
    }
#else
#if 0
    //glDisable(GL_TEXTURE_2D);
    // glColor3f(0.0f, 1.0f, 1.0f);
    // ConeDraw(&sCone);

    // glScalef(-1.0, -1.0, -1.0);
    // // glColor3f(1.0f, 1.0f, 0.0f);
    // glColor3f(1.0f, 1.0f, 1.0f);
    ConeDraw(&sCone);
#else
    // glDisable(GL_TEXTURE_2D);
    // glDisable(GL_BLEND);
    RenderRect();
#endif
#endif

    // 重置纹理矩阵
    glMatrixMode(GL_TEXTURE);
    glLoadIdentity();
    glMatrixMode(GL_MODELVIEW);

    glEnable(GL_DEPTH_TEST);
    glDisable(GL_TEXTURE_2D);
    glDisable(GL_BLEND);

    tex_y += 0.001f;
}
Exemplo n.º 11
0
/**
 * \brief Draw catoms and axes
 */
void Catoms3DWorld::glDraw() {
    glPushMatrix();
    glDisable(GL_TEXTURE_2D);
// draw catoms
    vector <GlBlock*>::iterator ic=tabGlBlocks.begin();
    lock();
    while (ic!=tabGlBlocks.end()) {
		((Catoms3DGlBlock*)(*ic))->glDraw(objBlock);
		ic++;
    }
    unlock();
    glPopMatrix();


// material for the grid walls
	static const GLfloat white[]={0.8f,0.8f,0.8f,1.0f},
		gray[]={0.2f,0.2f,0.2f,1.0f};
		glMaterialfv(GL_FRONT,GL_AMBIENT,gray);
		glMaterialfv(GL_FRONT,GL_DIFFUSE,white);
		glMaterialfv(GL_FRONT,GL_SPECULAR,white);
		glMaterialf(GL_FRONT,GL_SHININESS,40.0);

        lattice->glDraw();

		glMaterialfv(GL_FRONT,GL_AMBIENT,gray);
		glMaterialfv(GL_FRONT,GL_DIFFUSE,white);
		glMaterialfv(GL_FRONT,GL_SPECULAR,white);
		glMaterialf(GL_FRONT,GL_SHININESS,40.0);

		glPushMatrix();
		enableTexture(true);
		glBindTexture(GL_TEXTURE_2D,idTextureGrid);
		glTranslatef(0,0,lattice->gridScale[2]*(0.5-M_SQRT2_2));
		glScalef(lattice->gridSize[0]*lattice->gridScale[0],lattice->gridSize[1]*lattice->gridScale[1],lattice->gridSize[2]*lattice->gridScale[2]*M_SQRT2_2);
		glBegin(GL_QUADS);
		// bottom
		glNormal3f(0,0,1.0f);
		glTexCoord2f(0,0);
		glVertex3f(0.0f,0.0f,-0.0f);
		glTexCoord2f(0.5f*lattice->gridSize[0],0);
		glVertex3f(1.0f,0.0f,0.0f);
		glTexCoord2f(0.5f*lattice->gridSize[0],0.5f*lattice->gridSize[1]);
		glVertex3f(1.0,1.0,0.0f);
		glTexCoord2f(0,0.5f*lattice->gridSize[1]);
		glVertex3f(0.0,1.0,0.0f);
		// top
		glNormal3f(0,0,-1.0f);
		glTexCoord2f(0,0);
		glVertex3f(0.0f,0.0f,1.0f);
		glTexCoord2f(0.5f*lattice->gridSize[0],0);
		glVertex3f(0.0,1.0,1.0f);
		glTexCoord2f(0.5f*lattice->gridSize[0],0.5f*lattice->gridSize[1]);
		glVertex3f(1.0,1.0,1.0f);
		glTexCoord2f(0,0.5f*lattice->gridSize[1]);
		glVertex3f(1.0f,0.0f,1.0f);
		glEnd();
		// draw hexa
		glBindTexture(GL_TEXTURE_2D,idTextureHexa);
		glBegin(GL_QUADS);
		// left
		glNormal3f(1.0f,0,0);
		glTexCoord2f(0,0);
		glVertex3f(0.0f,0.0f,0.0f);
		glTexCoord2f(lattice->gridSize[1]/3.0f,0);
		glVertex3f(0.0f,1.0f,0.0f);
		glTexCoord2f(lattice->gridSize[1]/3.0f,lattice->gridSize[2]/1.5f);
		glVertex3f(0.0,1.0,1.0f);
		glTexCoord2f(0,lattice->gridSize[2]/1.5f);
		glVertex3f(0.0,0.0,1.0f);
		// right
		glNormal3f(-1.0f,0,0);
		glTexCoord2f(0,0);
		glVertex3f(1.0f,0.0f,0.0f);
		glTexCoord2f(0,lattice->gridSize[2]/1.5f);
		glVertex3f(1.0,0.0,1.0f);
		glTexCoord2f(lattice->gridSize[1]/3.0f,lattice->gridSize[2]/1.5f);
		glVertex3f(1.0,1.0,1.0f);
		glTexCoord2f(lattice->gridSize[1]/3.0f,0);
		glVertex3f(1.0f,1.0f,0.0f);
		// back
		glNormal3f(0,-1.0f,0);
		glTexCoord2f(0,0);
		glVertex3f(0.0f,1.0f,0.0f);
		glTexCoord2f(lattice->gridSize[0]/3.0f,0);
		glVertex3f(1.0f,1.0f,0.0f);
		glTexCoord2f(lattice->gridSize[0]/3.0f,lattice->gridSize[2]/1.5f);
		glVertex3f(1.0f,1.0,1.0f);
		glTexCoord2f(0,lattice->gridSize[2]/1.5f);
		glVertex3f(0.0,1.0,1.0f);
		// front
		glNormal3f(0,1.0,0);
		glTexCoord2f(0,0);
		glVertex3f(0.0f,0.0f,0.0f);
		glTexCoord2f(0,lattice->gridSize[2]/1.5f);
		glVertex3f(0.0,0.0,1.0f);
		glTexCoord2f(lattice->gridSize[0]/3.0f,lattice->gridSize[2]/1.5f);
		glVertex3f(1.0f,0.0,1.0f);
		glTexCoord2f(lattice->gridSize[0]/3.0f,0);
		glVertex3f(1.0f,0.0f,0.0f);
		glEnd();
		glPopMatrix();
		// draw the axes
		glPushMatrix();
		objRepere->glDraw();
		glPopMatrix();
}
Exemplo n.º 12
0
void SlideShow::draw(float t, float dt) {
    if(appFinished || image==0) return;

    display.mode2D();

    glPushMatrix();

    //glScalef(alpha, 1.0, 0.0);

    vec2f ratio = getAspectRatio();

    float max_percent = 1.0f;

    float scaled_w = display.width * ratio.x * max_percent;
    float scaled_h = display.height * ratio.y * max_percent;

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

    glTranslatef( (display.width - scaled_w) * 0.5f,
                  (display.height - scaled_h) * 0.5f,
                  0.0f);

    glDisable(GL_TEXTURE_2D);

    glColor4f(0.0, 0.0, 0.0, alpha * 0.25f);

    glPushMatrix();

        glTranslatef( 2.0f,
                      2.0f,
                      0.0f);

//        glTranslatef( (display.height * (1.0-max_percent)) * 0.25f,
//                      (display.height * (1.0-max_percent)) * 0.25f,
//                      0.0f);

        glBegin(GL_QUADS);
            glVertex2f(0.0f, 0.0);
            glVertex2f(scaled_w, 0.0);
            glVertex2f(scaled_w, scaled_h);
            glVertex2f(0.0f, scaled_h);
        glEnd();

    glPopMatrix();

    glEnable(GL_TEXTURE_2D);
    glBindTexture(GL_TEXTURE_2D, image->textureid);

    glColor4f(1.0, 1.0, 1.0, alpha);

    glBegin(GL_QUADS);
        glTexCoord2f(0.0f, 0.0f);
        glVertex2f(0.0f, 0.0);

        glTexCoord2f(1.0, 0.0f);
        glVertex2f(scaled_w, 0.0);

        glTexCoord2f(1.0, 1.0f);
        glVertex2f(scaled_w, scaled_h);

        glTexCoord2f(0.0f, 1.0f);
        glVertex2f(0.0f, scaled_h);
    glEnd();

    glPopMatrix();
}
Exemplo n.º 13
0
void Raytracer::displayCallback() 
{

	updateCamera();

	for (int i=0;i<numObjects;i++)
	{
		transforms[i].setIdentity();
		btVector3	pos(0.f,0.f,-(2.5* numObjects * 0.5)+i*2.5f);
		transforms[i].setOrigin( pos );
		btQuaternion orn;
		if (i < 2)
		{
			orn.setEuler(yaw,pitch,roll);
			transforms[i].setRotation(orn);
		}
	}

	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
	glDisable(GL_LIGHTING);
	if (!m_initialized)
	{
		m_initialized = true;
		glGenTextures(1, &glTextureId);
	}
	
	glBindTexture(GL_TEXTURE_2D,glTextureId );
	
	glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	
	glDisable(GL_TEXTURE_2D);
	glDisable(GL_BLEND);


	btVector4 rgba(1.f,0.f,0.f,0.5f);

	float top = 1.f;
	float bottom = -1.f;
	float nearPlane = 1.f;

	float tanFov = (top-bottom)*0.5f / nearPlane;

	float fov = 2.0 * atanf (tanFov);


	btVector3	rayFrom = getCameraPosition();
	btVector3 rayForward = getCameraTargetPosition()-getCameraPosition();
	rayForward.normalize();
	float farPlane = 600.f;
	rayForward*= farPlane;

	btVector3 rightOffset;
	btVector3 vertical(0.f,1.f,0.f);
	btVector3 hor;
	hor = rayForward.cross(vertical);
	hor.normalize();
	vertical = hor.cross(rayForward);
	vertical.normalize();

	float tanfov = tanf(0.5f*fov);

	hor *= 2.f * farPlane * tanfov;
	vertical *= 2.f * farPlane * tanfov;

	btVector3 rayToCenter = rayFrom + rayForward;

	btVector3 dHor = hor * 1.f/float(screenWidth);
	btVector3 dVert = vertical * 1.f/float(screenHeight);

	btTransform rayFromTrans;
	rayFromTrans.setIdentity();
	rayFromTrans.setOrigin(rayFrom);

	btTransform rayFromLocal;
	btTransform	rayToLocal;




	int x;

	///clear texture
	for (x=0;x<screenWidth;x++)
	{
		for (int y=0;y<screenHeight;y++)
		{
			btVector4 rgba(0.2f,0.2f,0.2f,1.f);
			raytracePicture->setPixel(x,y,rgba);
		}
	}

#if 1
	btVector3 rayTo;
	btTransform colObjWorldTransform;
	colObjWorldTransform.setIdentity();

	int	mode = 0;

	for (x=0;x<screenWidth;x++)
	{
		for (int y=0;y<screenHeight;y++)
		{

			rayTo = rayToCenter - 0.5f * hor + 0.5f * vertical;
			rayTo += x * dHor;
			rayTo -= y * dVert;
			btVector3	worldNormal(0,0,0);
			btVector3	worldPoint(0,0,0);



			bool hasHit = false;
			int mode = 0;
			switch (mode)
			{
			case 0:
				hasHit = lowlevelRaytest(rayFrom,rayTo,worldNormal,worldPoint);
				break;
			case 1:
				hasHit = singleObjectRaytest(rayFrom,rayTo,worldNormal,worldPoint);
				break;
			case 2:
				hasHit = worldRaytest(rayFrom,rayTo,worldNormal,worldPoint);
				break;
			default:
				{
				}
			}

			if (hasHit)
			{
				float lightVec0 = worldNormal.dot(btVector3(0,-1,-1));//0.4f,-1.f,-0.4f));
				float lightVec1= worldNormal.dot(btVector3(-1,0,-1));//-0.4f,-1.f,-0.4f));


				rgba = btVector4(lightVec0,lightVec1,0,1.f);
				rgba.setMin(btVector3(1,1,1));
				rgba.setMax(btVector3(0.2,0.2,0.2));
				rgba[3] = 1.f;
				raytracePicture->setPixel(x,y,rgba);
			} else
				btVector4 rgba = raytracePicture->getPixel(x,y);
			if (!rgba.length2())
			{
				raytracePicture->setPixel(x,y,btVector4(1,1,1,1));
			}
		}
	}
#endif

extern unsigned char sFontData[];
	if (0)
	{

		char* text="ABC abc 123 !@#";
			int x=0;
		for (int cc = 0;cc<strlen(text);cc++)
		{
		
			char testChar = text[cc];//'b';
			char ch = testChar-32;
			int startx=ch%16;
			int starty=ch/16;


			//for (int i=0;i<256;i++)
			for (int i=startx*16;i<(startx*16+16);i++)
			{
				int y=0;
				//for (int j=0;j<256;j++)
				//for (int j=0;j<256;j++)
				for (int j=starty*16;j<(starty*16+16);j++)
				{
					
					btVector4 rgba(0,0,0,1);
					rgba[0] = (sFontData[i*3+255*256*3-(256*j)*3])/255.f;
					//rgba[0] += (sFontData[(i+1)*3+255*256*3-(256*j)*3])/255.*0.25f;
					//rgba[0] += (sFontData[(i)*3+255*256*3-(256*j+1)*3])/255.*0.25f;
					//rgba[0] += (sFontData[(i+1)*3+255*256*3-(256*j+1)*3])/255.*0.25;

					//if (rgba[0]!=0.f)
					{
						rgba[1]=rgba[0];
						rgba[2]=rgba[0];
						rgba[3]=1.f;

						//raytracePicture->setPixel(x,y,rgba);
						raytracePicture->addPixel(x,y,rgba);
					}
					y++;
				}
				x++;
			}
		}
	}


	//raytracePicture->grapicalPrintf("CCD RAYTRACER",sFontData);
	char buffer[256];
	sprintf(buffer,"%d rays",screenWidth*screenHeight*numObjects);
	//sprintf(buffer,"Toggle",screenWidth*screenHeight*numObjects);
	//sprintf(buffer,"TEST",screenWidth*screenHeight*numObjects);
	//raytracePicture->grapicalPrintf(buffer,sFontData,0,10);//&BMF_font_helv10,0,10);
	raytracePicture->grapicalPrintf(buffer,sFontData,0,0);//&BMF_font_helv10,0,10);


	glMatrixMode(GL_PROJECTION);
	glPushMatrix();
	glLoadIdentity();
	glFrustum(-1.0,1.0,-1.0,1.0,3,2020.0);

	glMatrixMode(GL_MODELVIEW);
	glPushMatrix();
	glLoadIdentity();									// reset The Modelview Matrix
	glTranslatef(0.0f,0.0f,-3.1f);						// Move Into The Screen 5 Units



	glEnable(GL_TEXTURE_2D);
	glBindTexture(GL_TEXTURE_2D,glTextureId );

	const unsigned char *ptr = raytracePicture->getBuffer();
	glTexImage2D(GL_TEXTURE_2D, 
		0, 
		GL_RGBA, 
		raytracePicture->getWidth(),raytracePicture->getHeight(), 
		0, 
		GL_RGBA, 
		GL_UNSIGNED_BYTE, 
		ptr);


	glEnable (GL_BLEND);
	glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	glColor4f (1,1,1,1); // alpha=0.5=half visible

	glBegin(GL_QUADS);
	glTexCoord2f(0.0f, 0.0f);
	glVertex2f(-1,1);
	glTexCoord2f(1.0f, 0.0f);
	glVertex2f(1,1);
	glTexCoord2f(1.0f, 1.0f);
	glVertex2f(1,-1);
	glTexCoord2f(0.0f, 1.0f);
	glVertex2f(-1,-1);
	glEnd();



	glMatrixMode(GL_MODELVIEW);
	glPopMatrix();
	glMatrixMode(GL_PROJECTION);
	glPopMatrix();
	glMatrixMode(GL_MODELVIEW);


	glDisable(GL_TEXTURE_2D);
	glDisable(GL_DEPTH_TEST);

	GL_ShapeDrawer::drawCoordSystem();



	{
		for (int i=0;i<numObjects;i++)
		{
			btVector3 aabbMin,aabbMax;
			shapePtr[i]->getAabb(transforms[i],aabbMin,aabbMax);
		}
	}

	glPushMatrix();




	glPopMatrix();

	pitch += 0.005f;
	yaw += 0.01f;
	m_azi += 1.f;

	glFlush();
	glutSwapBuffers();
}
Exemplo n.º 14
0
void StochasticRenderer::create_image( const kvs::Camera* camera, const kvs::Light* light )
{
    glPushAttrib( GL_CURRENT_BIT | GL_ENABLE_BIT | GL_LIGHTING_BIT );

    RendererBase::initialize();

    bool retain_ensemble_buffer = true;

    // Following processes are executed once.
    if ( m_width == 0 && m_height == 0 )
    {
        m_ensemble_buffer.disableAccumulationBuffer();

        this->initialize_opengl();
        this->initialize_random_texture();

        for ( size_t i = 0; i < m_renderer_list.size(); i++ )
        {
            m_renderer_list[i]->setRandomTexture( m_random_texture );
            m_renderer_list[i]->initializeShader();
            m_renderer_list[i]->createVertexBuffer();
        }

        glGetFloatv( GL_MODELVIEW_MATRIX, m_modelview_matrix );
        retain_ensemble_buffer = false;
    }

    // Get the modelview matrix.
    float modelview_matrix[16];
    glGetFloatv( GL_MODELVIEW_MATRIX, modelview_matrix );
    static kvs::Vector3f light_position = light->position();

    // LOD control.
    size_t coarse_level = m_repeat_level;
    {
        if ( light_position != light->position() )
        {
            if ( m_enable_lod ) coarse_level = m_coarse_level;
            retain_ensemble_buffer = false;
        }
        else
        {
            for ( size_t i = 0; i < 16; i++ )
            {
                if ( m_modelview_matrix[i] != modelview_matrix[i] )
                {
                    if ( m_enable_lod ) coarse_level = m_coarse_level;
                    retain_ensemble_buffer = false;
                    break;
                }
            }
        }
        memcpy( m_modelview_matrix, modelview_matrix, sizeof( modelview_matrix ) );
    }

    // Following processes are executed when the window size is changed.
    if ( ( m_width  != camera->windowWidth() ) ||
         ( m_height != camera->windowHeight() ) )

    {
        m_width  = camera->windowWidth();
        m_height = camera->windowHeight();

        for ( size_t i = 0; i < m_renderer_list.size(); i++ )
        {
            m_renderer_list[i]->setRenderSize( m_width, m_height );
        }

        m_ensemble_buffer.create( m_width, m_height );

        this->initialize_framebuffer_texture();
        retain_ensemble_buffer = false;
    }

    for ( size_t i = 0; i < m_renderer_list.size(); i++ )
    {
        if ( m_renderer_list[i]->isUpdate() )
        {
            m_renderer_list[i]->createVertexBuffer();
            m_renderer_list[i]->disableUpdateFlag();
        }
    }

    const size_t repeat_count = coarse_level;
    if ( !retain_ensemble_buffer || m_clear_ensemble_buffer )
    {
        glClear( GL_ACCUM_BUFFER_BIT );
        m_ensemble_buffer.clear();
        for ( size_t i = 0; i < m_renderer_list.size(); i++ )
        {
            m_renderer_list[i]->clearEnsembleBuffer();
        }
    }

    // Draw objects.
    for ( size_t rp = 0; rp < repeat_count; rp++ )
    {
        m_framebuffer.bind();

        // Draw multiple buffers.
        const GLenum buffers[] = {
            GL_COLOR_ATTACHMENT0_EXT,
            GL_COLOR_ATTACHMENT1_EXT,
        };
        glDrawBuffers( 2, buffers );

        glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
        glEnable( GL_DEPTH_TEST );

        // draw vertex buffer.
        for ( size_t i = 0; i < m_renderer_list.size(); i++ )
        {
            if ( m_renderer_list[i]->rendererType() == kvs::glew::StochasticRendererBase::Volume )
            {
                kvs::glew::StochasticVolume2Renderer* r = static_cast<kvs::glew::StochasticVolume2Renderer*>( m_renderer_list[i] );
                r->setDepthTexture( m_depth_texture );
                r->setExtraTexture( m_extra_texture );
            }

            m_renderer_list[i]->drawVertexBuffer( modelview_matrix );
        }

        // render to the screen.
        m_framebuffer.disable();
        glDrawBuffer( GL_BACK );

        m_ensemble_buffer.bind();

        glMatrixMode( GL_MODELVIEW );  glPushMatrix(); glLoadIdentity();
        glMatrixMode( GL_PROJECTION ); glPushMatrix(); glLoadIdentity();
        glOrtho( 0, 1, 0, 1, -1, 1 );

        m_color_texture.bind();

        glDisable( GL_DEPTH_TEST );
        glDisable( GL_LIGHTING );
        glBegin( GL_QUADS );
        glColor4f( 1.0, 1.0, 1.0, m_ensemble_buffer.opacity() );
        glTexCoord2f( 1, 1 );  glVertex2f( 1, 1 );
        glTexCoord2f( 0, 1 );  glVertex2f( 0, 1 );
        glTexCoord2f( 0, 0 );  glVertex2f( 0, 0 );
        glTexCoord2f( 1, 0 );  glVertex2f( 1, 0 );
        glEnd();

        m_color_texture.unbind();
        glPopMatrix(); // Pop PROJECTION matrix
        glMatrixMode( GL_MODELVIEW );
        glPopMatrix(); // Pop MODELVIEW matrix

        m_ensemble_buffer.add();
    }
    m_ensemble_buffer.draw();

    m_clear_ensemble_buffer = false;

    light_position = light->position();

    glPopAttrib();
    glFinish();
}
Exemplo n.º 15
0
void Loaders::GenDisplayLists(t3DModel* pModel, uint32 modelId)
{
    if (pModel->displayListSize == 0)
    {
        glLoadIdentity();

        uint32 maxFrame = 0;
        for (uint32 an = 0; an < MAX_ANIM; an++)
            if (maxFrame < sStorage->ModelAnimation[modelId].Anim[an].frameLast)
                maxFrame = sStorage->ModelAnimation[modelId].Anim[an].frameLast;

        pModel->displayList = glGenLists(maxFrame+1);
        pModel->displayListSize = maxFrame + 1;

        uint32 maxkit = 0;
        std::vector<uint32> artkitIds;
        sStorage->GetAllModelArtkitIds(modelId, &artkitIds);
        if (!artkitIds.empty())
        {
            maxkit = artkitIds.size();

            pModel->displayListArtkit.resize(maxkit+1);
        }

        for (uint32 kit = 0; kit <= maxkit; kit++)
        {
            if (kit != 0 && (artkitIds.size() <= kit || !artkitIds[kit]))
                continue;

            if (kit != 0)
                pModel->displayListArtkit[kit] = glGenLists(maxFrame+1);

            for (uint32 a = 0; a <= maxFrame; a++)
            {
                if (kit == 0)
                    glNewList(pModel->displayList + a,GL_COMPILE);
                else
                    glNewList(pModel->displayListArtkit[kit] + a,GL_COMPILE);

                for (int i = 0; i < pModel->numOfObjects; i++)
                {
                    if (pModel->pObject.size() <= 0)
                        break;

                    t3DObject *pObject = &pModel->pObject[i];

                    glPushMatrix();
                    sDisplay->AnimateModelObjectByFrame(pModel, pObject, modelId, a);

                    if (pObject->bHasTexture)
                    {
                        glEnable(GL_TEXTURE_2D);
                        glColor3ub(255, 255, 255);
                        glBindTexture(GL_TEXTURE_2D, pModel->pMaterials[pObject->materialID].texureId);
                        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
                        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
                    }
                    else
                    {
                        glDisable(GL_TEXTURE_2D);
                        ObjectArtkitData* adata = sStorage->GetObjectArtkitData(modelId, pObject->strName, kit);
                        if (adata)
                        {
                            glColor3ub(adata->colors[0], adata->colors[1], adata->colors[2]);
                        }
                        else if (pModel->pMaterials.size() && pObject->materialID >= 0)
                        {
                            BYTE *pColor = pModel->pMaterials[pObject->materialID].color;
                            glColor3ub(pColor[0], pColor[1], pColor[2]);
                        }
                    }

                    /*
                    glShadeModel(GL_SMOOTH);
                    GLfloat mShininess[] = {2+4};
                    GLfloat mSpecular[] = {0.4f, 0.4f, 0.4f, 1.0f};
                    glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, mSpecular);
                    glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, mShininess);
                    */

                    glBegin(GL_TRIANGLES);

                    for (int j = 0; j < pObject->numOfFaces; j++)
                    {
                        for (int whichVertex = 0; whichVertex < 3; whichVertex++)
                        {
                            int index = pObject->pFaces[j].vertIndex[whichVertex];

                            if (pObject->pNormals)
                            {
                                CVector3* pNormal = &pObject->pNormals[index];
                                glNormal3f(pNormal->x, pNormal->y, pNormal->z);
                            }

                            if (pObject->bHasTexture && pObject->pTexVerts != NULL)
                            {
                                CVector2* pTexVert = &pObject->pTexVerts[index];

                                // Pokud existuji modifiery pro opakovatelnost textur, nacteme je
                                float mod_x = 1.0f, mod_y = 1.0f;
                                if (pObject->strName)
                                {
                                    if (ObjectModifierData* pMod = sStorage->GetObjectModifierData(modelId, &(pObject->strName[0])))
                                    {
                                        mod_x = pMod->texture_repeat_x;
                                        mod_y = pMod->texture_repeat_y;
                                    }
                                }

                                glTexCoord2f(pTexVert->x * mod_x, pTexVert->y * mod_y);
                            }

                            if (pObject->pVerts)
                            {
                                CVector3* pVert = &pObject->pVerts[index];
                                glVertex3f(pVert->x, pVert->y, pVert->z);
                            }
                        }
                    }

                    glEnd();

                    glPopMatrix();
                }
                glEndList();
            }
        }
    }
}
Exemplo n.º 16
0
/****f* Glelements/draw_block
 * NAME
 *   draw_block
 * FUNCTION
 *   Draw a block into OpenGL's memory
 * OPTIONS
 *   x -- x coordinate
 *   y -- y coordinate
 *   z -- z coordinate
 *   texture -- BitMap-struct pointer
 * SOURCE
 */
void draw_block(float x, float y, float z, BitMap* texture){

	glBindTexture(GL_TEXTURE_2D, BlockTextures[texture][0][0]);
	
	glBegin(GL_QUADS);

	// Back Face
	glTexCoord2f( 0.0f, 1.0f ); glVertex3f(x+0.0f, y+0.0f, z+1.0f);
	glTexCoord2f( 1.0f, 1.0f ); glVertex3f(x+1.0f, y+0.0f, z+1.0f);
	glTexCoord2f( 1.0f, 0.0f ); glVertex3f(x+1.0f, y+1.0f, z+1.0f);
	glTexCoord2f( 0.0f, 0.0f ); glVertex3f(x+0.0f, y+1.0f, z+1.0f);

	// Front Face
	glTexCoord2f( 1.0f, 1.0f ); glVertex3f(x+0.0f, y+0.0f, z+0.0f);
	glTexCoord2f( 1.0f, 0.0f ); glVertex3f(x+0.0f, y+1.0f, z+0.0f);
	glTexCoord2f( 0.0f, 0.0f ); glVertex3f(x+1.0f, y+1.0f, z+0.0f);
	glTexCoord2f( 0.0f, 1.0f ); glVertex3f(x+1.0f, y+0.0f, z+0.0f);

	// Top Face
	glTexCoord2f( 0.0f, 0.0f ); glVertex3f(x+0.0f, y+1.0f, z+0.0f);
	glTexCoord2f( 0.0f, 1.0f ); glVertex3f(x+0.0f, y+1.0f, z+1.0f);
	glTexCoord2f( 1.0f, 1.0f ); glVertex3f(x+1.0f, y+1.0f, z+1.0f);
	glTexCoord2f( 1.0f, 0.0f ); glVertex3f(x+1.0f, y+1.0f, z+0.0f);

	// Bottom Face
	glTexCoord2f( 0.0f, 0.0f ); glVertex3f(x+0.0f, y+0.0f, z+0.0f);
	glTexCoord2f( 1.0f, 0.0f ); glVertex3f(x+1.0f, y+0.0f, z+0.0f);
	glTexCoord2f( 1.0f, 1.0f ); glVertex3f(x+1.0f, y+0.0f, z+1.0f);
	glTexCoord2f( 0.0f, 1.0f ); glVertex3f(x+0.0f, y+0.0f, z+1.0f);

	// Right face
	glTexCoord2f( 1.0f, 1.0f ); glVertex3f(x+1.0f, y+0.0f, z+0.0f);
	glTexCoord2f( 1.0f, 0.0f ); glVertex3f(x+1.0f, y+1.0f, z+0.0f);
	glTexCoord2f( 0.0f, 0.0f ); glVertex3f(x+1.0f, y+1.0f, z+1.0f);
	glTexCoord2f( 0.0f, 1.0f ); glVertex3f(x+1.0f, y+0.0f, z+1.0f);

	// Left Face
	glTexCoord2f( 0.0f, 1.0f ); glVertex3f(x+0.0f, y+0.0f, z+0.0f);
	glTexCoord2f( 1.0f, 1.0f ); glVertex3f(x+0.0f, y+0.0f, z+1.0f);
	glTexCoord2f( 1.0f, 0.0f ); glVertex3f(x+0.0f, y+1.0f, z+1.0f);
	glTexCoord2f( 0.0f, 0.0f ); glVertex3f(x+0.0f, y+1.0f, z+0.0f);

	glEnd();

}
Exemplo n.º 17
0
//Peter: Used great billboard drawing trick from http://www.lighthouse3d.com/opengl/billboarding/index.php?billCheat.
void Sprite::drawScaledTintedRotated(Vec3d &location, Vec2d &scale, Color &color, float rotation)
{

	GLfloat left = convertScale(mTexPosition.X(), 0, mpTexture->getWidth(), 0.0f, 1.0f);
	GLfloat right = convertScale(mTexPosition.X() + mSize.X(), 0, mpTexture->getWidth(), 0.0f, 1.0f);

	GLfloat up = convertScale(mTexPosition.Y() + mSize.Y(), 0, mpTexture->getHeight(), 1.0f, 0.0f);
	GLfloat down = convertScale(mTexPosition.Y(), 0, mpTexture->getHeight(), 1.0f, 0.0f);

	glPushMatrix();

	glTranslatef(location.X, location.Y, location.Z);

	glPushMatrix();

	//glTranslatef(mpTexture->getRatio()*0.5,0,0);

	mpTexture->setAsActiveTexture();

	float modelview[16];
	int i,j;

	// save the current modelview matrix
	glPushMatrix();

	// get the current modelview matrix
	glGetFloatv(GL_MODELVIEW_MATRIX , modelview);

	// undo all rotations
	// beware all scaling is lost as well 
	for( i=0; i<3; i++ ) 
		for( j=0; j<3; j++ ) 
		{
			if ( i==j )
				modelview[i*4+j] = 1.0;
			else
				modelview[i*4+j] = 0.0;
		}

	// set the modelview with no rotations and scaling
	glLoadMatrixf(modelview);

	glRotatef(rotation, 0.0, 0.0, 1.0);

	//cwc::glShader *shader = (*game->getShaderManager())[0];

	//shader->begin();

	glBegin(GL_QUADS);
	// Front Face

	//Set tint.
	glColor3f(color.r, color.g, color.b);

	glTexCoord2f(left,up);
	glVertex3f(-((mSize.X()/mSize.Y()) * scale.X())/2, -scale.Y()/2, 0.0f);              // Top Left

	glTexCoord2f(right,up);
	glVertex3f(/*mpTexture->getRatio()*/((mSize.X()/mSize.Y()) * scale.X())/2, -scale.Y()/2, 0.0f);              // Top Right

	glTexCoord2f(right,down);
	glVertex3f( /*mpTexture->getRatio()*/((mSize.X()/mSize.Y()) * scale.X())/2, scale.Y()/2, 0.0f);              // Bottom Right

	glTexCoord2f(left,down);
	glVertex3f(-((mSize.X()/mSize.Y()) * scale.X())/2,scale.Y()/2, 0.0f);              // Bottom Left

	glEnd();

	//shader->end();

	if(game->getWireframeBoundingBoxMode())
	{
		glDisable(GL_TEXTURE_2D);

		glLineWidth(10);

		glBegin(GL_LINES);
		// Front Face

		//Set tint.
		glColor3f(color.r, color.g, color.b);

		glTexCoord2f(left,up);
		glVertex3f(-((mSize.X()/mSize.Y()) * scale.X())/2, -scale.Y()/2, 0.0f);              // Top Left
		glVertex3f(/*mpTexture->getRatio()*/((mSize.X()/mSize.Y()) * scale.X())/2, -scale.Y()/2, 0.0f);

		glTexCoord2f(right,up);
		glVertex3f(/*mpTexture->getRatio()*/((mSize.X()/mSize.Y()) * scale.X())/2, -scale.Y()/2, 0.0f);              // Top Right
		glVertex3f( /*mpTexture->getRatio()*/((mSize.X()/mSize.Y()) * scale.X())/2, scale.Y()/2, 0.0f);

		glTexCoord2f(right,down);
		glVertex3f( /*mpTexture->getRatio()*/((mSize.X()/mSize.Y()) * scale.X())/2, scale.Y()/2, 0.0f);              // Bottom Right
		glVertex3f(-((mSize.X()/mSize.Y()) * scale.X())/2,scale.Y()/2, 0.0f);

		glTexCoord2f(left,down);
		glVertex3f(-((mSize.X()/mSize.Y()) * scale.X())/2,scale.Y()/2, 0.0f);              // Bottom Left
		glVertex3f(-((mSize.X()/mSize.Y()) * scale.X())/2, -scale.Y()/2, 0.0f);

		glEnd();

		glEnable(GL_TEXTURE_2D);
	}

	glPopMatrix();

	// restores the modelview matrix
	glPopMatrix();

	glPopMatrix();
}
Exemplo n.º 18
0
/** \return GL_TRUE for pass, GL_FALSE for fail */
static GLboolean
test_format(const struct format_info *info)
{
   const int comps = num_components(info->BaseFormat);
   const int texels = TexWidth * TexHeight;
   const int w = piglit_width / 10;
   const int h = piglit_height / 10;
   GLfloat expected[4];
   void *image;
   float value[4];
   GLint f;
   GLenum userFormat;
   int p;
   const char *name = piglit_get_gl_enum_name(info->IntFormat);

   if ((info->BaseFormat == GL_RED ||
        info->BaseFormat == GL_RG) && !HaveRG) {
      /* skip it */
      return GL_TRUE;
   }

   /*printf("Testing %s\n", name);*/

   get_texture_color(value);

   /* alloc, fill texture image */
   image = malloc(comps * texels * sizeof(GLfloat));
   fill_array(comps, texels, image, value);

   /* GL_INTENSITY is not a legal src format */
   userFormat = info->BaseFormat == GL_INTENSITY ? GL_LUMINANCE : info->BaseFormat;

   glTexImage2D(GL_TEXTURE_2D, 0, info->IntFormat, TexWidth, TexHeight, 0,
                userFormat, GL_FLOAT, image);
   free(image);

   if (check_error(__FILE__, __LINE__))
      return GL_FALSE;

   /* check internal format */
   glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_INTERNAL_FORMAT, &f);
   if (f != info->IntFormat) {
      printf("%s: GL_TEXTURE_INTERNAL_FORMAT query failed for 0x%x\n",
             TestName,
             info->IntFormat);
      return GL_FALSE;
   }

   /* check texture datatype info */
   {
      static const GLenum queries[] = {
         GL_TEXTURE_RED_TYPE_ARB,
         GL_TEXTURE_GREEN_TYPE_ARB,
         GL_TEXTURE_BLUE_TYPE_ARB,
         GL_TEXTURE_ALPHA_TYPE_ARB,
         GL_TEXTURE_LUMINANCE_TYPE_ARB,
         GL_TEXTURE_INTENSITY_TYPE_ARB,
         GL_TEXTURE_DEPTH_TYPE_ARB
      };
      int i;
      for (i = 0; i < ARRAY_SIZE(queries); i++) {
         GLint type = 1;
         glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, queries[i], &type);
         if (check_error(__FILE__, __LINE__))
            return GL_FALSE;
         if (type != GL_NONE && type != GL_FLOAT) {
            printf("%s: %s query failed (returned 0x%x)\n",
                   TestName, piglit_get_gl_enum_name(queries[i]), type);
            return GL_FALSE;
         }
      }
   }

   /* compute expected color */
   switch (info->BaseFormat) {
   case GL_RGBA:
      expected[0] = scale_and_bias(value[0]);
      expected[1] = scale_and_bias(value[1]);
      expected[2] = scale_and_bias(value[2]);
      expected[3] = scale_and_bias(value[3]);
      break;
   case GL_RGB:
      expected[0] = scale_and_bias(value[0]);
      expected[1] = scale_and_bias(value[1]);
      expected[2] = scale_and_bias(value[2]);
      expected[3] = scale_and_bias(1.0);
      break;
   case GL_ALPHA:
      expected[0] =
      expected[1] =
      expected[2] = scale_and_bias(0.0);
      expected[3] = scale_and_bias(value[0]);
      break;
   case GL_LUMINANCE:
      expected[0] =
      expected[1] =
      expected[2] = scale_and_bias(value[0]);
      expected[3] = scale_and_bias(1.0);
      break;
   case GL_INTENSITY:
      expected[0] =
      expected[1] =
      expected[2] = 
      expected[3] = scale_and_bias(value[0]);
      break;
   case GL_LUMINANCE_ALPHA:
      expected[0] =
      expected[1] =
      expected[2] = scale_and_bias(value[0]);
      expected[3] = scale_and_bias(value[1]);
      break;
   case GL_RED:
      expected[0] = scale_and_bias(value[0]);
      expected[1] = scale_and_bias(0.0);
      expected[2] = scale_and_bias(0.0);
      expected[3] = scale_and_bias(1.0);
      break;
   case GL_RG:
      expected[0] = scale_and_bias(value[0]);
      expected[1] = scale_and_bias(value[1]);
      expected[2] = scale_and_bias(0.0);
      expected[3] = scale_and_bias(1.0);
      break;
   default:
      abort();
   }

   /* draw */
   glClearColor(0.5, 0.5, 0.5, 0.0);
   glClear(GL_COLOR_BUFFER_BIT);
   glBegin(GL_POLYGON);
   glTexCoord2f(0, 0);   glVertex2f(0, 0);
   glTexCoord2f(1, 0);   glVertex2f(w, 0);
   glTexCoord2f(1, 1);   glVertex2f(w, h);
   glTexCoord2f(0, 1);   glVertex2f(0, h);
   glEnd();

   /* test */
   p = piglit_probe_pixel_rgba(w/2, h/2, expected);
   if (!p) {
      int i;

      printf("  Failed with format %s:\n", name);
      printf("  Texture color = ");
      for (i = 0; i < comps; i++) {
         printf("%f", value[i]);
         if (i + 1 < comps)
            printf(", ");
      }
      printf("\n");
   }

   piglit_present_results();

   return p;
}
bool MainApp::onLoadWorld()
{
	//similar to texture handle creation, create a display list handle
    m_uTriDisplayList = glGenLists(1);

    //compile a basic cube within this new list
    glNewList( m_uTriDisplayList, GL_COMPILE );

    glBegin(GL_QUADS);
		// Front Face
		glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f,  1.0f);
		glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f,  1.0f);
		glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  1.0f,  1.0f);
		glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  1.0f,  1.0f);
		// Back Face
		glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f);
		glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f,  1.0f, -1.0f);
		glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f,  1.0f, -1.0f);
		glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f);
		// Top Face
		glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  1.0f, -1.0f);
		glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f,  1.0f,  1.0f);
		glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f,  1.0f,  1.0f);
		glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  1.0f, -1.0f);
		// Bottom Face
		glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, -1.0f, -1.0f);
		glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, -1.0f, -1.0f);
		glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f,  1.0f);
		glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f,  1.0f);
		// Right face
		glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f);
		glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  1.0f, -1.0f);
		glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f,  1.0f,  1.0f);
		glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f,  1.0f);
		// Left Face
		glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f);
		glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f,  1.0f);
		glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f,  1.0f,  1.0f);
		glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  1.0f, -1.0f);

    glEnd();

    //you are finished with the display list. Close it off
    glEndList();

	m_fZRotation = 0.0f;
	m_fYRotation = 0.0f;

	m_pTexture = peon::EngineCore::getSingleton().getRenderer()->loadTexture("data\\textures\\sdl_logo.bmp");

	glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
	glShadeModel( GL_SMOOTH );

	
	return true;
}
Exemplo n.º 20
0
void TexturedPolygons::CreateAngledPolygon(const int &listNo, 
										   const GLdouble &imageWidth, const GLdouble &imageHeight,
										   const GLdouble &x1, const GLdouble &x2, 
										   const GLdouble &x3, const GLdouble &x4,
										   const GLdouble &y1, const GLdouble &y2,
										   const GLdouble &y3, const GLdouble &y4,
										   const GLdouble &z1, const GLdouble &z2,
										   const GLdouble &z3, const GLdouble &z4,
										   const int &smallestX, const int &smallestZ)
{
	GLdouble xImage1 = x1;
	GLdouble xImage2 = x2;
	GLdouble xImage3 = x3;
	GLdouble xImage4 = x4;
	GLdouble zImage1 = z1;
	GLdouble zImage2 = z2;
	GLdouble zImage3 = z3;
	GLdouble zImage4 = z4;

	if (smallestX == 1)
	{
		CreateTextureScale(xImage1, xImage2, xImage3, xImage4, imageWidth);
	}
	else if (smallestX == 2)
	{
		CreateTextureScale(xImage2, xImage1, xImage3, xImage4, imageWidth);
	}
	else if (smallestX == 3)
	{
		CreateTextureScale(xImage3, xImage1, xImage2, xImage4, imageWidth);
	}
	else if (smallestX == 4)
	{
		CreateTextureScale(xImage4, xImage1, xImage2, xImage3, imageWidth);
	}
	else
	{
		xImage1 = y1;
		xImage2 = y2;
		xImage3 = y3;
		xImage4 = y4;
		if (smallestX == 5)
		{
			CreateTextureScale(xImage1, xImage2, xImage3, xImage4, imageWidth);
		}
		else if (smallestX == 6)
		{
			CreateTextureScale(xImage2, xImage1, xImage3, xImage4, imageWidth);
		}
		else if (smallestX == 7)
		{
			CreateTextureScale(xImage3, xImage1, xImage2, xImage4, imageWidth);
		}
		else if (smallestX == 8)
		{
			CreateTextureScale(xImage4, xImage1, xImage2, xImage3, imageWidth);
		}
	}	
	if (smallestZ == 1)
	{
		CreateTextureScale(zImage1, zImage2, zImage3, zImage4, imageHeight);
	}
	else if (smallestZ == 2)
	{
		CreateTextureScale(zImage2, zImage1, zImage3, zImage4, imageHeight);
	}
	else if (smallestZ == 3)
	{
		CreateTextureScale(zImage3, zImage1, zImage2, zImage4, imageHeight);
	}
	else if (smallestZ == 4)
	{
		CreateTextureScale(zImage4, zImage1, zImage2, zImage3, imageHeight);
	}
	else
	{
		zImage1 = y1;
		zImage2 = y2;
		zImage3 = y3;
		zImage4 = y4;
		if (smallestZ == 5)
		{
			CreateTextureScale(zImage1, zImage2, zImage3, zImage4, imageHeight);
		}
		else if (smallestZ == 6)
		{
			CreateTextureScale(zImage2, zImage1, zImage3, zImage4, imageHeight);
		}
		else if (smallestZ == 7)
		{
			CreateTextureScale(zImage3, zImage1, zImage2, zImage4, imageHeight);
		}
		else if (smallestZ == 8)
		{
			CreateTextureScale(zImage4, zImage1, zImage2, zImage3, imageHeight);
		}
	}
	// create display list
	glNewList(listNo, GL_COMPILE);
		glBegin(GL_QUADS);
			glTexCoord2f(xImage1, zImage1);
			glVertex3f(x1, y1, z1);
			glTexCoord2f(xImage2, zImage2);
			glVertex3f(x2, y2, z2);
			glTexCoord2f(xImage3, zImage3);
			glVertex3f(x3, y3, z3);
			glTexCoord2f(xImage4, zImage4);
			glVertex3f(x4, y4, z4);
		glEnd();
	glEndList();

}
Exemplo n.º 21
0
int CObjLoader::LoadObject(const char *directory, const char *filename) {
	stringstream ss;

	ss << directory << "/" << filename;

	ifstream in(ss.str().c_str());
	if(!in.is_open()) {
		cout << "Cannot open " << ss.str().c_str() << endl;
		return -1;
	}
	
	char buf[256];
	int curmat = 0;
	while(!in.eof()) {
		in.getline(buf, 256);
		coords.push_back(new string(buf));
	}
	
	for(unsigned int i = 0; i < coords.size(); i++) {
		if((*coords[i])[0] == '#')
			continue;
		else if(((*coords[i])[0] == 'v') && ((*coords[i])[1] == ' ')) {
			float tmpx, tmpy, tmpz;
			sscanf(coords[i]->c_str(), "v %f %f %f", &tmpx, &tmpy, &tmpz);
			verts.push_back(new coordinate(tmpx, tmpy, tmpz));
		}
		else if(((*coords[i])[0] == 'v') && ((*coords[i])[1] == 'n')) {
			float tmpx, tmpy, tmpz;
			sscanf(coords[i]->c_str(), "vn %f %f %f", &tmpx, &tmpy, &tmpz);
			normals.push_back(new coordinate(tmpx, tmpy, tmpz));
		}
		else if((*coords[i])[0] == 'f') {
			int a, b, c, d, e;
			if(count(coords[i]->begin(), coords[i]->end(), ' ') == 4) {
				if(coords[i]->find("//") != string::npos)
				{
					sscanf(coords[i]->c_str(), "f %d//%d %d//%d %d//%d %d//%d", &b, &a, &c, &a, &d, &a, &e, &a);
					faces.push_back(new face(a, b, c, d, e, 0, 0, 0, 0, curmat));
				}
				else if(coords[i]->find("/") != string::npos)
				{
					int t[4];
					sscanf(coords[i]->c_str(), "f %d/%d/%d %d/%d/%d %d/%d/%d %d/%d/%d", &b, &t[0], &a, &c, &t[1], &a, &d, &t[2], &a, &e, &t[3], &a);
					faces.push_back(new face(a, b, c, d, e, t[0], t[1], t[2], t[3], curmat));
				}
				else {
					sscanf(coords[i]->c_str(), "f %d %d %d %d", &a, &b, &c, &d);
					faces.push_back(new face(-1, a, b, c, d, 0, 0, 0, 0, curmat));
				}
			}
			else {
				if(coords[i]->find("//") != string::npos)
				{
					sscanf(coords[i]->c_str(), "f %d//%d %d//%d %d//%d", &b, &a, &c, &a, &d, &a);
					faces.push_back(new face(a, b, c, d, 0, 0, 0, curmat));
				}
				else if(coords[i]->find("/") != string::npos)
				{
					int t[3];
					sscanf(coords[i]->c_str(), "f %d/%d/%d %d/%d/%d %d/%d/%d", &b, &t[0], &a, &c, &t[1], &a, &d, &t[2], &a);
					faces.push_back(new face(a, b, c, d, t[0], t[1], t[2], curmat));
				}
				else {
					sscanf(coords[i]->c_str(), "f %d %d %d", &a, &b, &c);
					faces.push_back(new face(-1, a, b, c, 0, 0, 0, curmat));
				}
			}
		}
		else if(((*coords[i])[0] == 'u') && ((*coords[i])[1] == 's') && ((*coords[i])[2] == 'e')) {
			char matname[200];
			sscanf(coords[i]->c_str(), "usemtl %s", matname);
			for(unsigned int i = 0; i < materials.size(); i++) {
				if(strcmp(materials[i]->name.c_str(), matname) == 0) {
					curmat = i;
					break;
				}
			}
		}
		else if(((*coords[i])[0] == 'm') && ((*coords[i])[1] == 't') && ((*coords[i])[2] == 'l') && ((*coords[i])[3] == 'l')) {
			char filen[200];
			stringstream ss2;
			sscanf(coords[i]->c_str(), "mtllib %s", filen);
			ss2 << directory << "/" << filen;
			ifstream matlib_in(ss2.str().c_str());
			if(!matlib_in.is_open()) {
				cout << "Cannot open file: " << ss2.str().c_str() << endl;
				Cleanup();
				return -1;
			}
			ismaterial = true;
			vector<string> tmp;
			char buf[200];
			while(!matlib_in.eof()) {
				matlib_in.getline(buf, 200);
				tmp.push_back(buf);
			}
			char name[200];
			char filename[200];
			float amb[3], dif[3], spec[3], alpha, ns, ni;
			int illum;
			unsigned int texture = -1;
			bool ismat = false;
			strcpy(filename, "\0");
			for(unsigned int i = 0; i < tmp.size(); i++) {
				if(tmp[i][0] == '#')
					continue;
				else if((tmp[i][0] == 'n') && (tmp[i][1] == 'e') && (tmp[i][2] == 'w')) {
					if(ismat) {
						if(strcmp(filename, "\0") != 0) {
							materials.push_back(new material(name, alpha, ns, ni, amb, dif, spec, illum, texture));
							strcpy(filename, "\0");
						}
						else {
							materials.push_back(new material(name, alpha, ns, ni, amb, dif, spec, illum, -1));
						}
					}
					ismat = false;
					sscanf(tmp[i].c_str(), "newmtl %s", name);
				}
				else if((tmp[i][0] == 'N') && (tmp[i][1] == 's')) {
					sscanf(tmp[i].c_str(), "Ns %f", &ns);
					ismat = true;
				}
				else if((tmp[i][0] == 'K') && (tmp[i][1] == 'a')) {
					sscanf(tmp[i].c_str(), "Ka %f %f %f", &amb[0], &amb[1], &amb[2]);
					ismat = true;
				}
				else if((tmp[i][0] == 'K') && (tmp[i][1] == 'd')) {
					sscanf(tmp[i].c_str(), "Kd %f %f %f", &dif[0], &dif[1], &dif[2]);
					ismat = true;
				}
				else if((tmp[i][0] == 'K') && (tmp[i][1] == 's')) {
					sscanf(tmp[i].c_str(), "Ks %f %f %f", &spec[0], &spec[1], &spec[2]);
					ismat = true;
				}
				else if((tmp[i][0] == 'N') && (tmp[i][1] == 'i')) {
					sscanf(tmp[i].c_str(), "Ni %f", &ni);
					ismat = true;
				}
				else if((tmp[i][0] == 'd') && (tmp[i][1] == ' ')) {
					sscanf(tmp[i].c_str(), "d %f", &alpha);
					ismat = true;
				}
				else if((tmp[i][0] == 'i') && (tmp[i][1] == 'l')) {
					sscanf(tmp[i].c_str(), "illum %d", &illum);
					ismat = true;
				}
				else if((tmp[i][0] == 'm') && (tmp[i][1] == 'a') && (tmp[i][2] == 'p')) {
					sscanf(tmp[i].c_str(), "map_Kd %s", filename);
					texture = LoadTexture(directory, filename);
					ismat = true;
				}
			}
			if(ismat) {
				if(strcmp(filename, "\0") != 0) {
					materials.push_back(new material(name, alpha, ns, ni, amb, dif, spec, illum, texture));
				}
				else {
					materials.push_back(new material(name, alpha, ns, ni, amb, dif, spec, illum, -1));
				}
			}
		}
		else if(((*coords[i])[0] == 'v') && ((*coords[i])[1] == 't')) {
			float u, v;
			sscanf(coords[i]->c_str(), "vt %f %f", &u, &v);
			texcoords.push_back(new texcoord(u, 1-v));
			istexture = true;
		}
	}
	
	if(materials.size() == 0)
			ismaterial = false;
		else
			ismaterial = true;
	
	int num;
	num = glGenLists(1);
	glNewList(num, GL_COMPILE);
		int lastmat = -1;
		for(unsigned int i = 0; i < faces.size(); i++) {
			if(lastmat != faces[i]->mat && ismaterial) {
				float diffuse[] = {materials[faces[i]->mat]->dif[0], materials[faces[i]->mat]->dif[1], materials[faces[i]->mat]->dif[2], 1.0};
				float ambient[] = {materials[faces[i]->mat]->amb[0], materials[faces[i]->mat]->amb[1], materials[faces[i]->mat]->amb[2], 1.0};
				float specular[] = {materials[faces[i]->mat]->spec[0], materials[faces[i]->mat]->spec[1], materials[faces[i]->mat]->spec[2], 1.0};
				glMaterialfv(GL_FRONT, GL_DIFFUSE, diffuse);
				glMaterialfv(GL_FRONT, GL_AMBIENT, ambient);
				glMaterialfv(GL_FRONT, GL_SPECULAR, specular);
				glMaterialf(GL_FRONT, GL_SHININESS, materials[faces[i]->mat]->ns);
				lastmat = faces[i]->mat;
				if(materials[faces[i]->mat]->texture == -1) {
					glDisable(GL_TEXTURE_2D);
				}
				else {
					glEnable(GL_TEXTURE_2D);
					glBindTexture(GL_TEXTURE_2D, materials[faces[i]->mat]->texture);
				}
			}
			if(faces[i]->hasFour) {
				glBegin(GL_QUADS);
				if(isnormals)
					glNormal3f(normals[faces[i]->faceNum-1]->x, normals[faces[i]->faceNum-1]->y, normals[faces[i]->faceNum-1]->z);
				if(istexture && materials[faces[i]->mat]->texture != -1)
					glTexCoord2f(texcoords[faces[i]->texcoord[0]-1]->u, texcoords[faces[i]->texcoord[0]-1]->v);
				glVertex3f(verts[faces[i]->faces[0]-1]->x, verts[faces[i]->faces[0]-1]->y, verts[faces[i]->faces[0]-1]->z);
				if(istexture && materials[faces[i]->mat]->texture != -1)
					glTexCoord2f(texcoords[faces[i]->texcoord[1]-1]->u, texcoords[faces[i]->texcoord[1]-1]->v);
				glVertex3f(verts[faces[i]->faces[1]-1]->x, verts[faces[i]->faces[1]-1]->y, verts[faces[i]->faces[1]-1]->z);
				if(istexture && materials[faces[i]->mat]->texture != -1)
					glTexCoord2f(texcoords[faces[i]->texcoord[2]-1]->u, texcoords[faces[i]->texcoord[2]-1]->v);
				glVertex3f(verts[faces[i]->faces[2]-1]->x, verts[faces[i]->faces[2]-1]->y, verts[faces[i]->faces[2]-1]->z);
				if(istexture && materials[faces[i]->mat]->texture != -1)
					glTexCoord2f(texcoords[faces[i]->texcoord[3]-1]->u, texcoords[faces[i]->texcoord[3]-1]->v);
				glVertex3f(verts[faces[i]->faces[3]-1]->x, verts[faces[i]->faces[3]-1]->y, verts[faces[i]->faces[3]-1]->z);
				glEnd();
			}
			else {
				glBegin(GL_TRIANGLES);
				if(isnormals)
					glNormal3f(normals[faces[i]->faceNum-1]->x, normals[faces[i]->faceNum-1]->y, normals[faces[i]->faceNum-1]->z);
				if(istexture && materials[faces[i]->mat]->texture != -1)
					glTexCoord2f(texcoords[faces[i]->texcoord[0]-1]->u, texcoords[faces[i]->texcoord[0]-1]->v);
				glVertex3f(verts[faces[i]->faces[0]-1]->x, verts[faces[i]->faces[0]-1]->y, verts[faces[i]->faces[0]-1]->z);
				if(istexture && materials[faces[i]->mat]->texture != -1)
					glTexCoord2f(texcoords[faces[i]->texcoord[1]-1]->u, texcoords[faces[i]->texcoord[1]-1]->v);
				glVertex3f(verts[faces[i]->faces[1]-1]->x, verts[faces[i]->faces[1]-1]->y, verts[faces[i]->faces[1]-1]->z);
				if(istexture && materials[faces[i]->mat]->texture != -1)
					glTexCoord2f(texcoords[faces[i]->texcoord[2]-1]->u, texcoords[faces[i]->texcoord[2]-1]->v);
				glVertex3f(verts[faces[i]->faces[2]-1]->x, verts[faces[i]->faces[2]-1]->y, verts[faces[i]->faces[2]-1]->z);
				glEnd();
			}
		}
	glEndList();
	Cleanup();
	lists.push_back(num);
	return num;
}
Exemplo n.º 22
0
int main(int argc, char **argv)
{
    int flags = SDL_OPENGL;
    int bpp = 0;
    int carry_on = 1;
    Uint32 c_frame = 0;
    Uint32 interval;
    Uint32 start_t, last_t, curr_t;
    Uint32 rendered_frames = 0;
    SDL_Surface *screen;
    GLuint bg, bird;
    SDL_Event selection;
	const SDL_VideoInfo* info = NULL;

    initialise();

    info = SDL_GetVideoInfo();
	bpp = info->vfmt->BitsPerPixel;

    screen = SDL_SetVideoMode(MAP_W, MAP_H, bpp, flags); 
    if(!screen){
        fprintf(stderr, "Failed to open screen!\n");
        return 1;
    }
    create_tex("images/sky.png", &bg);
    create_tex("images/bird.png", &bird);


   /* paint section */

   glMatrixMode(GL_PROJECTION);
   glLoadIdentity();
   glOrtho(0, MAP_W,
           MAP_H, 0, -1, 1);
   //glViewport(0.0, 0.0,
    //       MAP_W, MAP_H);
   


   glMatrixMode(GL_MODELVIEW);
   glLoadIdentity();

   glEnable(GL_TEXTURE_2D);
   glBindTexture(GL_TEXTURE_2D, bg);

   glMatrixMode(GL_MODELVIEW);
   glLoadIdentity();
   glTranslatef(0, 0, 0);

   glBegin(GL_QUADS);

   glTexCoord2f(0.0, 0.0);
   glVertex3f(0, 0, 0);

   glTexCoord2f(0.0, 1.0);
   glVertex3f(0, MAP_H, 0);

   glTexCoord2f(1.0, 1.0);
   glVertex3f(MAP_W, MAP_H, 0);

   glTexCoord2f(1.0, 0.0);
   glVertex3f(MAP_W, 0 , 0);

   glEnd();
   
   /*
   glBindTexture(GL_TEXTURE_2D, bird);

   glBegin(GL_QUADS);

   glTexCoord2f(0.0, 0.0);
   glVertex3f(0, 0, 0);

   glTexCoord2f(0.0, 1.0);
   glVertex3f(0, BIRD_H, 0);

   glTexCoord2f(1.0, 1.0);
   glVertex3f(BIRD_W, BIRD_H, 0);

   glTexCoord2f(1.0, 0.0);
   glVertex3f(BIRD_W, 0 , 0);

   glEnd();
*/
   glDisable(GL_TEXTURE_2D);

   glFlush();
   SDL_GL_SwapBuffers();

   start_t = last_t = SDL_GetTicks();
   while(carry_on){

       while(SDL_PollEvent(&selection)){
           if(selection.type == SDL_QUIT){
               carry_on = 0;
           }
       }

       curr_t = SDL_GetTicks();
       if(floor((double)(curr_t - start_t) /1000. * FPS) > c_frame){
      //     c_frame = floor((double)(curr_t - start_t) / 1000. * FPS);
           c_frame++;
           paint(bg, 0, MAP_W, MAP_H, curr_t);
           paint(bird, 0.1, BIRD_W, BIRD_H, curr_t);
           rendered_frames++;
       }
       glFlush();
       SDL_GL_SwapBuffers();
           
   }

   fprintf(stdout, "frames: %d\n", rendered_frames);
   fprintf(stdout, "seconds: %d \n", (curr_t - start_t) / 1000);
   fprintf(stderr, "FPS: %f\n", (float)rendered_frames/((float)(curr_t - start_t) / 1000));

   return 0;

}
Exemplo n.º 23
0
void CSkyBox::render()
{
	/** 获得场景中光照状态 */
	GLboolean lp;
	glGetBooleanv(GL_LIGHTING,&lp);

	m_CameraPos = Camera::GetCamera()->getPosition();

	glDisable(GL_LIGHTING);            /**< 关闭光照 */
	glEnable(GL_TEXTURE_2D);

	/** 开始绘制 */
	glPushMatrix();
	glTranslatef(m_CameraPos.x,m_CameraPos.y,m_CameraPos.z);

	glRotatef(yRot,0.0f,1.0f,0.0f);
			
	/** 绘制背面 */
	glBindTexture(GL_TEXTURE_2D, m_texture[0].ID);
    glBegin(GL_QUADS);		
		
		/** 指定纹理坐标和顶点坐标 */
		glTexCoord2f(1.0f, 0.0f); glVertex3f(  width, -height, -length);
		glTexCoord2f(1.0f, 1.0f); glVertex3f(  width,  height, -length); 
		glTexCoord2f(0.0f, 1.0f); glVertex3f( -width,  height, -length);
		glTexCoord2f(0.0f, 0.0f); glVertex3f( -width, -height, -length);
		
	glEnd();



	/** 绘制前面 */
	glBindTexture(GL_TEXTURE_2D, m_texture[1].ID);
	glBegin(GL_QUADS);	
	
		/** 指定纹理坐标和顶点坐标 */
		glTexCoord2f(1.0f, 0.0f); glVertex3f( -width, -height, length);
		glTexCoord2f(1.0f, 1.0f); glVertex3f( -width,  height, length);
		glTexCoord2f(0.0f, 1.0f); glVertex3f(  width,  height, length); 
		glTexCoord2f(0.0f, 0.0f); glVertex3f(  width, -height, length);

	glEnd();

	

	/** 绘制顶面 */
	glBindTexture(GL_TEXTURE_2D,  m_texture[2].ID);
	glBegin(GL_QUADS);		
		
	    /** 指定纹理坐标和顶点坐标 */
		glTexCoord2f(0.0f, 1.0f); glVertex3f(  width, height, -length);
		glTexCoord2f(0.0f, 0.0f); glVertex3f(  width, height,  length); 
		glTexCoord2f(1.0f, 0.0f); glVertex3f( -width, height,  length);
	    glTexCoord2f(1.0f, 1.0f); glVertex3f( -width, height, -length);
		
	glEnd();


	
	/** 绘制左面 */
	glBindTexture(GL_TEXTURE_2D, m_texture[3].ID);
	glBegin(GL_QUADS);		
		
		/** 指定纹理坐标和顶点坐标 */
		glTexCoord2f(1.0f, 1.0f);  glVertex3f( -width,  height,	-length);		
		glTexCoord2f(0.0f, 1.0f);  glVertex3f( -width,  height,  length); 
		glTexCoord2f(0.0f, 0.0f);  glVertex3f( -width, -height,  length);
		glTexCoord2f(1.0f, 0.0f);  glVertex3f( -width, -height, -length);	
		
	glEnd();

	/** 绘制右面 */
	glBindTexture(GL_TEXTURE_2D, m_texture[4].ID);
	glBegin(GL_QUADS);		

		/** 指定纹理坐标和顶点坐标 */
		glTexCoord2f(0.0f, 0.0f); glVertex3f( width, -height, -length);
		glTexCoord2f(1.0f, 0.0f); glVertex3f( width, -height,  length);
		glTexCoord2f(1.0f, 1.0f); glVertex3f( width,  height,  length); 
		glTexCoord2f(0.0f, 1.0f); glVertex3f( width,  height, -length);
	glEnd();
	

    glPopMatrix();                 /** 绘制结束 */

	if(lp)                         /** 恢复光照状态 */  
		glEnable(GL_LIGHTING);

	glDisable(GL_TEXTURE_2D);

	 yRot += 0.01f;
	 if(yRot > 360.0f)
		 yRot = 0.0f;

	

}
Exemplo n.º 24
0
Arquivo: main.cpp Projeto: hgl888/glfw
///////////////////////////////////////////////////////////////////////////////
// draw a textured cube with GL_TRIANGLES
///////////////////////////////////////////////////////////////////////////////
void draw()
{
    glBindTexture(GL_TEXTURE_2D, textureId);

    glColor4f(1, 1, 1, 1);
    glBegin(GL_TRIANGLES);
        // front faces
        glNormal3f(0,0,1);
        // face v0-v1-v2
        glTexCoord2f(1,1);  glVertex3f(1,1,1);
        glTexCoord2f(0,1);  glVertex3f(-1,1,1);
        glTexCoord2f(0,0);  glVertex3f(-1,-1,1);
        // face v2-v3-v0
        glTexCoord2f(0,0);  glVertex3f(-1,-1,1);
        glTexCoord2f(1,0);  glVertex3f(1,-1,1);
        glTexCoord2f(1,1);  glVertex3f(1,1,1);

        // right faces
        glNormal3f(1,0,0);
        // face v0-v3-v4
        glTexCoord2f(0,1);  glVertex3f(1,1,1);
        glTexCoord2f(0,0);  glVertex3f(1,-1,1);
        glTexCoord2f(1,0);  glVertex3f(1,-1,-1);
        // face v4-v5-v0
        glTexCoord2f(1,0);  glVertex3f(1,-1,-1);
        glTexCoord2f(1,1);  glVertex3f(1,1,-1);
        glTexCoord2f(0,1);  glVertex3f(1,1,1);

        // top faces
        glNormal3f(0,1,0);
        // face v0-v5-v6
        glTexCoord2f(1,0);  glVertex3f(1,1,1);
        glTexCoord2f(1,1);  glVertex3f(1,1,-1);
        glTexCoord2f(0,1);  glVertex3f(-1,1,-1);
        // face v6-v1-v0
        glTexCoord2f(0,1);  glVertex3f(-1,1,-1);
        glTexCoord2f(0,0);  glVertex3f(-1,1,1);
        glTexCoord2f(1,0);  glVertex3f(1,1,1);

        // left faces
        glNormal3f(-1,0,0);
        // face  v1-v6-v7
        glTexCoord2f(1,1);  glVertex3f(-1,1,1);
        glTexCoord2f(0,1);  glVertex3f(-1,1,-1);
        glTexCoord2f(0,0);  glVertex3f(-1,-1,-1);
        // face v7-v2-v1
        glTexCoord2f(0,0);  glVertex3f(-1,-1,-1);
        glTexCoord2f(1,0);  glVertex3f(-1,-1,1);
        glTexCoord2f(1,1);  glVertex3f(-1,1,1);

        // bottom faces
        glNormal3f(0,-1,0);
        // face v7-v4-v3
        glTexCoord2f(0,0);  glVertex3f(-1,-1,-1);
        glTexCoord2f(1,0);  glVertex3f(1,-1,-1);
        glTexCoord2f(1,1);  glVertex3f(1,-1,1);
        // face v3-v2-v7
        glTexCoord2f(1,1);  glVertex3f(1,-1,1);
        glTexCoord2f(0,1);  glVertex3f(-1,-1,1);
        glTexCoord2f(0,0);  glVertex3f(-1,-1,-1);

        // back faces
        glNormal3f(0,0,-1);
        // face v4-v7-v6
        glTexCoord2f(0,0);  glVertex3f(1,-1,-1);
        glTexCoord2f(1,0);  glVertex3f(-1,-1,-1);
        glTexCoord2f(1,1);  glVertex3f(-1,1,-1);
        // face v6-v5-v4
        glTexCoord2f(1,1);  glVertex3f(-1,1,-1);
        glTexCoord2f(0,1);  glVertex3f(1,1,-1);
        glTexCoord2f(0,0);  glVertex3f(1,-1,-1);
    glEnd();

    glBindTexture(GL_TEXTURE_2D, 0);
}
/////////////
//DisplayLoop
/////////////
void display(void)
{
	
	int x, y;
	float float_x, float_y, float_xb, float_yb;
    //glPushMatrix();            //start matrix
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    //glColor3f(1.0, 1.0, 1.0);    //set color of rectangle
	glTranslatef(0.0, 0.0, -15.0);    //set origin of shape (5 units into the distance)
	//glRotatef(xrot,1.0f,0.0f,0.0f);
	//glRotatef(yrot,0.0f,1.0f,0.0f);  
	//glRotatef(zrot,0.0f,0.0f,1.0f);



	glEnable( GL_TEXTURE_2D );
	glBindTexture( GL_TEXTURE_2D, tex );

    //glRotatef(rot, 1.0, 0.0, 0.0); //rotate 20 degrees around the x axis

    /*glBegin(GL_QUADS);        //begin shape
	//glColor4f(1.0, 0.0, 0.0, 1.0);
	glTexCoord2f(0, 0);
    glVertex3f(-1.0, -1.0, 0.0);    //draw each vertex
    
	//glColor4f(0.0, 1.0, 0.0, 1.0);
	glTexCoord2f(1, 0);
	glVertex3f(1.0, -1.0, 0.0);
    
	//glColor4f(0.0, 0.0, 1.0, 1.0);
	glTexCoord2f(1, 1);
	glVertex3f(1.0, 1.0, 0.0);
    
	//glColor4f(1.0, 1.0, 0.0, 1.0);
	glTexCoord2f(0, 1);
	glVertex3f(-1.0, 1.0, 0.0);
    glEnd();  */              //end shape
    //glPopMatrix();            //end matrix

	glBegin(GL_QUADS);
	for( x = 0; x < 44; x++ )
	{
		for( y = 0; y < 44; y++ )
		{
			float_x = float(x)/44.0f;
			float_y = float(y)/44.0f;
			float_xb = float(x+1)/44.0f;
			float_yb = float(y+1)/44.0f;

			glTexCoord2f( float_x, float_y);
			glVertex3f( points[x][y][0], points[x][y][1], points[x][y][2] );

			glTexCoord2f( float_x, float_yb );
			glVertex3f( points[x][y+1][0], points[x][y+1][1], points[x][y+1][2] );

			glTexCoord2f( float_xb, float_yb );
			glVertex3f( points[x+1][y+1][0], points[x+1][y+1][1], points[x+1][y+1][2] );

			glTexCoord2f( float_xb, float_y );
			glVertex3f( points[x+1][y][0], points[x+1][y][1], points[x+1][y][2] );
		}
	}
	glEnd();

		if( wiggle_count == 2 )
	{
		for( y = 0; y < 45; y++ )
		{
			hold=points[0][y][2];
			for( x = 0; x < 44; x++)
			{
				points[x][y][2] = points[x+1][y][2];
			}
			points[44][y][2]=hold;
		}
		wiggle_count = 0;
	}

	wiggle_count++;

    glutSwapBuffers();
	xrot+=0.3f;
	yrot+=0.2f;
	zrot+=0.4f;
    //rot += .1;            //increase rotation amount
}
Exemplo n.º 26
0
void glaDrawPixelsTexScaled_clipping(float x, float y, int img_w, int img_h,
                                     int format, int type, int zoomfilter, void *rect,
                                     float scaleX, float scaleY,
                                     float clip_min_x, float clip_min_y,
                                     float clip_max_x, float clip_max_y)
{
	unsigned char *uc_rect = (unsigned char *) rect;
	const float *f_rect = (float *)rect;
	float xzoom = glaGetOneFloat(GL_ZOOM_X), yzoom = glaGetOneFloat(GL_ZOOM_Y);
	int subpart_x, subpart_y, tex_w, tex_h;
	int seamless, offset_x, offset_y, nsubparts_x, nsubparts_y;
	int texid = get_cached_work_texture(&tex_w, &tex_h);
	int components;
	const bool use_clipping = ((clip_min_x < clip_max_x) && (clip_min_y < clip_max_y));

	/* Specify the color outside this function, and tex will modulate it.
	 * This is useful for changing alpha without using glPixelTransferf()
	 */
	glPixelStorei(GL_UNPACK_ROW_LENGTH, img_w);
	glBindTexture(GL_TEXTURE_2D, texid);

	/* don't want nasty border artifacts */
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, zoomfilter);

#if defined(__APPLE__) && 0
	/* [merwin] disable this workaround and see if anyone is affected. If not scrap it! Also at end of this function */
	/* workaround for os x 10.5/10.6 driver bug: http://lists.apple.com/archives/Mac-opengl/2008/Jul/msg00117.html */
	glPixelZoom(1.0f, 1.0f);
#endif
	
	/* setup seamless 2=on, 0=off */
	seamless = ((tex_w < img_w || tex_h < img_h) && tex_w > 2 && tex_h > 2) ? 2 : 0;
	
	offset_x = tex_w - seamless;
	offset_y = tex_h - seamless;
	
	nsubparts_x = (img_w + (offset_x - 1)) / (offset_x);
	nsubparts_y = (img_h + (offset_y - 1)) / (offset_y);

	if (format == GL_RGBA)
		components = 4;
	else if (format == GL_RGB)
		components = 3;
	else if (ELEM(format, GL_LUMINANCE, GL_ALPHA))
		components = 1;
	else {
		BLI_assert(!"Incompatible format passed to glaDrawPixelsTexScaled");
		return;
	}

	if (type == GL_FLOAT) {
		/* need to set internal format to higher range float */

		/* NOTE: this could fail on some drivers, like mesa,
		 *       but currently this code is only used by color
		 *       management stuff which already checks on whether
		 *       it's possible to use GL_RGBA16F_ARB
		 */

		glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F_ARB, tex_w, tex_h, 0, format, GL_FLOAT, NULL);
	}
	else {
		/* switch to 8bit RGBA for byte buffer */
		glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, tex_w, tex_h, 0, format, GL_UNSIGNED_BYTE, NULL);
	}

	for (subpart_y = 0; subpart_y < nsubparts_y; subpart_y++) {
		for (subpart_x = 0; subpart_x < nsubparts_x; subpart_x++) {
			int remainder_x = img_w - subpart_x * offset_x;
			int remainder_y = img_h - subpart_y * offset_y;
			int subpart_w = (remainder_x < tex_w) ? remainder_x : tex_w;
			int subpart_h = (remainder_y < tex_h) ? remainder_y : tex_h;
			int offset_left = (seamless && subpart_x != 0) ? 1 : 0;
			int offset_bot = (seamless && subpart_y != 0) ? 1 : 0;
			int offset_right = (seamless && remainder_x > tex_w) ? 1 : 0;
			int offset_top = (seamless && remainder_y > tex_h) ? 1 : 0;
			float rast_x = x + subpart_x * offset_x * xzoom;
			float rast_y = y + subpart_y * offset_y * yzoom;
			/* check if we already got these because we always get 2 more when doing seamless */
			if (subpart_w <= seamless || subpart_h <= seamless)
				continue;

			if (use_clipping) {
				if (rast_x + (float)(subpart_w - offset_right) * xzoom * scaleX < clip_min_x ||
				    rast_y + (float)(subpart_h - offset_top) * yzoom * scaleY < clip_min_y)
				{
					continue;
				}
				if (rast_x + (float)offset_left * xzoom > clip_max_x ||
				    rast_y + (float)offset_bot * yzoom > clip_max_y)
				{
					continue;
				}
			}

			if (type == GL_FLOAT) {
				glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, subpart_w, subpart_h, format, GL_FLOAT, &f_rect[((size_t)subpart_y) * offset_y * img_w * components + subpart_x * offset_x * components]);
				
				/* add an extra border of pixels so linear looks ok at edges of full image */
				if (subpart_w < tex_w)
					glTexSubImage2D(GL_TEXTURE_2D, 0, subpart_w, 0, 1, subpart_h, format, GL_FLOAT, &f_rect[((size_t)subpart_y) * offset_y * img_w * components + (subpart_x * offset_x + subpart_w - 1) * components]);
				if (subpart_h < tex_h)
					glTexSubImage2D(GL_TEXTURE_2D, 0, 0, subpart_h, subpart_w, 1, format, GL_FLOAT, &f_rect[(((size_t)subpart_y) * offset_y + subpart_h - 1) * img_w * components + subpart_x * offset_x * components]);
				if (subpart_w < tex_w && subpart_h < tex_h)
					glTexSubImage2D(GL_TEXTURE_2D, 0, subpart_w, subpart_h, 1, 1, format, GL_FLOAT, &f_rect[(((size_t)subpart_y) * offset_y + subpart_h - 1) * img_w * components + (subpart_x * offset_x + subpart_w - 1) * components]);
			}
			else {
				glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, subpart_w, subpart_h, format, GL_UNSIGNED_BYTE, &uc_rect[((size_t)subpart_y) * offset_y * img_w * components + subpart_x * offset_x * components]);
				
				if (subpart_w < tex_w)
					glTexSubImage2D(GL_TEXTURE_2D, 0, subpart_w, 0, 1, subpart_h, format, GL_UNSIGNED_BYTE, &uc_rect[((size_t)subpart_y) * offset_y * img_w * components + (subpart_x * offset_x + subpart_w - 1) * components]);
				if (subpart_h < tex_h)
					glTexSubImage2D(GL_TEXTURE_2D, 0, 0, subpart_h, subpart_w, 1, format, GL_UNSIGNED_BYTE, &uc_rect[(((size_t)subpart_y) * offset_y + subpart_h - 1) * img_w * components + subpart_x * offset_x * components]);
				if (subpart_w < tex_w && subpart_h < tex_h)
					glTexSubImage2D(GL_TEXTURE_2D, 0, subpart_w, subpart_h, 1, 1, format, GL_UNSIGNED_BYTE, &uc_rect[(((size_t)subpart_y) * offset_y + subpart_h - 1) * img_w * components + (subpart_x * offset_x + subpart_w - 1) * components]);
			}

			GPU_basic_shader_bind(GPU_SHADER_TEXTURE_2D | GPU_SHADER_USE_COLOR);
			glBegin(GL_QUADS);
			glTexCoord2f((float)(0 + offset_left) / tex_w, (float)(0 + offset_bot) / tex_h);
			glVertex2f(rast_x + (float)offset_left * xzoom, rast_y + (float)offset_bot * yzoom);

			glTexCoord2f((float)(subpart_w - offset_right) / tex_w, (float)(0 + offset_bot) / tex_h);
			glVertex2f(rast_x + (float)(subpart_w - offset_right) * xzoom * scaleX, rast_y + (float)offset_bot * yzoom);

			glTexCoord2f((float)(subpart_w - offset_right) / tex_w, (float)(subpart_h - offset_top) / tex_h);
			glVertex2f(rast_x + (float)(subpart_w - offset_right) * xzoom * scaleX, rast_y + (float)(subpart_h - offset_top) * yzoom * scaleY);

			glTexCoord2f((float)(0 + offset_left) / tex_w, (float)(subpart_h - offset_top) / tex_h);
			glVertex2f(rast_x + (float)offset_left * xzoom, rast_y + (float)(subpart_h - offset_top) * yzoom * scaleY);
			glEnd();
			GPU_basic_shader_bind(GPU_SHADER_USE_COLOR);
		}
	}

	glBindTexture(GL_TEXTURE_2D, 0);
	glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
	
#if defined(__APPLE__) && 0
	/* workaround for os x 10.5/10.6 driver bug (above) */
	glPixelZoom(xzoom, yzoom);
#endif
}
Exemplo n.º 27
0
void ObjModel::draw() {
    //This affects the entire model
    //glColor
    glPushMatrix();

    glScalef(scale, scale, scale);

    glTranslatef(xpos, ypos, zpos);

    glRotatef(xrot, 1, 0, 0);
    glRotatef(yrot, 0, 1, 0);
    glRotatef(zrot, 0, 0, 1);


    for (auto &g : groups) {
        if (materials[g->materialIndex]->hasTexture) {
            glEnable(GL_TEXTURE_2D);
            materials[g->materialIndex]->texture->bind();
        }

        glBegin(GL_TRIANGLES);
        for (auto &f : g->faces) {
            for (auto &v : f.vertices) {
                glNormal3f(normals[v.normal]->x, normals[v.normal]->y, normals[v.normal]->z);
                glTexCoord2f(texcoords[v.texcoord]->x, texcoords[v.texcoord]->y);
                glVertex3f(vertices[v.position]->x, vertices[v.position]->y, vertices[v.position]->z);
            }
        }
        glEnd();
        glDisable(GL_TEXTURE_2D);
    }

    if (DRAW_BOUNDING_BOX) {
//        glLineWidth(5);
//
//        glBegin(GL_LINE_LOOP);
//        glVertex3f(vertices_max->x, vertices_max->y, vertices_min->z);
//        glVertex3f(vertices_min->x, vertices_max->y, vertices_min->z);
//        glVertex3f(vertices_min->x, vertices_min->y, vertices_min->z);
//        glVertex3f(vertices_max->x, vertices_min->y, vertices_min->z);
//        glEnd();
//
//        glBegin(GL_LINE_LOOP);
//        glVertex3f(vertices_max->x, vertices_min->y, vertices_max->z);
//        glVertex3f(vertices_max->x, vertices_max->y, vertices_max->z);
//        glVertex3f(vertices_min->x, vertices_max->y, vertices_max->z);
//        glVertex3f(vertices_min->x, vertices_min->y, vertices_max->z);
//        glEnd();
//
//        glBegin(GL_LINE_LOOP);
//        glVertex3f(vertices_max->x, vertices_max->y, vertices_min->z);
//        glVertex3f(vertices_max->x, vertices_max->y, vertices_max->z);
//        glVertex3f(vertices_min->x, vertices_max->y, vertices_max->z);
//        glVertex3f(vertices_min->x, vertices_max->y, vertices_min->z);
//        glEnd();
//
//        glBegin(GL_LINE_LOOP);
//        glVertex3f(vertices_max->x, vertices_min->y, vertices_max->z);
//        glVertex3f(vertices_min->x, vertices_min->y, vertices_max->z);
//        glVertex3f(vertices_min->x, vertices_min->y, vertices_min->z);
//        glVertex3f(vertices_max->x, vertices_min->y, vertices_min->z);
//        glEnd();

        for(auto &e : boundingSpheres) {
            if (e->collides) {
                glPushMatrix();
                glColor3ub(0, 255, 255);
                glTranslatef(e->x, e->y, e->z);
                glutWireSphere(e->radius, 20, 20); //Radius, polycount, polycount
                glPopMatrix();
            }
        }
        glColor3f(1,1,1);

    }
    glPopMatrix();
}
Exemplo n.º 28
0
/* draw a colored cube */
static void
draw_object(void)
{
   glPushMatrix();
   glScalef(0.75, 0.75, 0.75);

   glColor3f(1, 0, 0);

   if (Texture) {
      glBindTexture(GL_TEXTURE_2D, TexObj);
      glEnable(GL_TEXTURE_2D);
   }
   else {
      glDisable(GL_TEXTURE_2D);
   }

   glBegin(GL_QUADS);

   /* -X */
   glColor3f(0, 1, 1);
   glTexCoord2f(0, 0);  glVertex3f(-1, -1, -1);
   glTexCoord2f(1, 0);  glVertex3f(-1,  1, -1);
   glTexCoord2f(1, 1);  glVertex3f(-1,  1,  1);
   glTexCoord2f(0, 1);  glVertex3f(-1, -1,  1);

   /* +X */
   glColor3f(1, 0, 0);
   glTexCoord2f(0, 0);  glVertex3f(1, -1, -1);
   glTexCoord2f(1, 0);  glVertex3f(1,  1, -1);
   glTexCoord2f(1, 1);  glVertex3f(1,  1,  1);
   glTexCoord2f(0, 1);  glVertex3f(1, -1,  1);

   /* -Y */
   glColor3f(1, 0, 1);
   glTexCoord2f(0, 0);  glVertex3f(-1, -1, -1);
   glTexCoord2f(1, 0);  glVertex3f( 1, -1, -1);
   glTexCoord2f(1, 1);  glVertex3f( 1, -1,  1);
   glTexCoord2f(0, 1);  glVertex3f(-1, -1,  1);

   /* +Y */
   glColor3f(0, 1, 0);
   glTexCoord2f(0, 0);  glVertex3f(-1, 1, -1);
   glTexCoord2f(1, 0);  glVertex3f( 1, 1, -1);
   glTexCoord2f(1, 1);  glVertex3f( 1, 1,  1);
   glTexCoord2f(0, 1);  glVertex3f(-1, 1,  1);

   /* -Z */
   glColor3f(1, 1, 0);
   glTexCoord2f(0, 0);  glVertex3f(-1, -1, -1);
   glTexCoord2f(1, 0);  glVertex3f( 1, -1, -1);
   glTexCoord2f(1, 1);  glVertex3f( 1,  1, -1);
   glTexCoord2f(0, 1);  glVertex3f(-1,  1, -1);

   /* +Y */
   glColor3f(0, 0, 1);
   glTexCoord2f(0, 0);  glVertex3f(-1, -1, 1);
   glTexCoord2f(1, 0);  glVertex3f( 1, -1, 1);
   glTexCoord2f(1, 1);  glVertex3f( 1,  1, 1);
   glTexCoord2f(0, 1);  glVertex3f(-1,  1, 1);

   glEnd();

   glPopMatrix();
}
Exemplo n.º 29
0
int DrawGLScene(GLvoid)	            // Here's Where We Do All The Drawing
{								
	int i;
	static char frbuf[80] = "";
	
	glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

    
    //set camera in hookmode 
	if (hook_toball1)
	{
		TVector unit_followvector=sphere_speed[0];
		unit_followvector.unit();
 		gluLookAt(sphere_speed[0].X()+250,sphere_speed[0].Y()+250 ,sphere_speed[0].Z(), sphere_speed[0].X()+sphere_speed[0].X() ,sphere_speed[0].Y()+sphere_speed[0].Y() ,sphere_speed[0].Z()+sphere_speed[0].Z() ,0,1,0);  
    
    }
	else
	    gluLookAt(pos._x,pos._y,pos._z, pos._x + dir.X(),pos._y+dir.Y(),pos._z+dir.Z(), 0,1.0,0.0);

	glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

    glRotatef(camera_rotation,0,1,0);
	
	for (i=0;i<NR_BALLS;i++)
	{
		switch(i % 7){
        case 1: glColor3f(1.0f,1.0f,1.0f);
			       break;
		case 2: glColor3f(1.0f,1.0f,0.0f);
			       break;
		case 3: glColor3f(0.0f,1.0f,1.0f);
			       break;
		case 4: glColor3f(0.0f,1.0f,0.0f);
			       break;
		case 5: glColor3f(0.0f,0.0f,1.0f);
			       break;
		case 6: glColor3f(0.65f,0.2f,0.3f);
			       break;
		case 7: glColor3f(1.0f,0.0f,1.0f);
			       break;
		case 8: glColor3f(0.0f,0.7f,0.4f);
			       break;
		default: glColor3f(1.0f,0,0);
		}
		glPushMatrix();
		glTranslated(sphere_poz[i]._x,sphere_poz[i]._y,sphere_poz[i]._z);
		GLUquadricObj *obj = gluNewQuadric();
		gluQuadricDrawStyle(obj,GLU_FILL);
		gluQuadricNormals(obj,GLU_SMOOTH);
		gluQuadricOrientation(obj,GLU_OUTSIDE);
		gluSphere(obj, 5.0f, 20, 20);
		glPopMatrix();
		gluDeleteQuadric(obj);
	}

	
	for (i=0;i<NR_CIL;i++)
	{
		switch(i % 7){
        case 1: glColor3f(1.0f,1.0f,1.0f);
			       break;
		case 2: glColor3f(1.0f,1.0f,0.0f);
			       break;
		case 3: glColor3f(0.0f,1.0f,1.0f);
			       break;
		case 4: glColor3f(0.0f,1.0f,0.0f);
			       break;
		case 5: glColor3f(0.0f,0.0f,1.0f);
			       break;
		case 6: glColor3f(0.65f,0.2f,0.3f);
			       break;
		case 7: glColor3f(1.0f,0.0f,1.0f);
			       break;
		case 8: glColor3f(0.0f,0.7f,0.4f);
			       break;
		default: glColor3f(1.0f,0,0);
		}
		glPushMatrix();
		glTranslated(cone_poz[i]._x,cone_poz[i]._y,cone_poz[i]._z);
		GLUquadricObj *obj = gluNewQuadric();
		gluQuadricDrawStyle(obj,GLU_FILL);
		gluQuadricNormals(obj,GLU_SMOOTH);
		gluQuadricOrientation(obj,GLU_OUTSIDE);
		gluCylinder(obj,5.0, 5.0, 10.0, 20.0, 20.0);
		glPopMatrix();
		gluDeleteQuadric(obj);
	}

	
	float df = 100.0;

	for (int i = 0; i < NR_CUBES; i += 1)
	{
		glPushMatrix();
		glTranslated(cube_pos[i]._x,cube_pos[i]._y,cube_pos[i]._z);
		glBlendFunc(GL_SRC_ALPHA, GL_ONE);
		glDrawCube();
		glPopMatrix();
	}
	
	glEnable(GL_TEXTURE_2D);

	

	//glMaterialfv(GL_FRONT,GL_SPECULAR,spec);
	//glMaterialfv(GL_FRONT,GL_SHININESS,&df);
	
	//render walls(planes) with texture
	glBindTexture(GL_TEXTURE_2D, texture[1]); 
	glColor3f(1, 1, 1);
	glBegin(GL_QUADS);
	glTexCoord2f(1.0f, 0.0f); glVertex3f(520,520,520);
	glTexCoord2f(1.0f, 1.0f); glVertex3f(520,-520,520);
    glTexCoord2f(0.0f, 1.0f); glVertex3f(-520,-520,520);
	glTexCoord2f(0.0f, 0.0f); glVertex3f(-520,520,520);
        
	glTexCoord2f(1.0f, 0.0f); glVertex3f(-520,520,-520);
	glTexCoord2f(1.0f, 1.0f); glVertex3f(-520,-520,-520);
    glTexCoord2f(0.0f, 1.0f); glVertex3f(520,-520,-520);
	glTexCoord2f(0.0f, 0.0f); glVertex3f(520,520,-520);
    
	glTexCoord2f(1.0f, 0.0f); glVertex3f(520,520,-520);
	glTexCoord2f(1.0f, 1.0f); glVertex3f(520,-520,-520);
    glTexCoord2f(0.0f, 1.0f); glVertex3f(520,-520,520);
	glTexCoord2f(0.0f, 0.0f); glVertex3f(520,520,520);
	
	glTexCoord2f(1.0f, 0.0f); glVertex3f(-520,520,520);
	glTexCoord2f(1.0f, 1.0f); glVertex3f(-520,-520,520);
    glTexCoord2f(0.0f, 1.0f); glVertex3f(-520,-520,-520);
	glTexCoord2f(0.0f, 0.0f); glVertex3f(-520,520,-520);
	glEnd();

	//render floor (plane) with colours
	glBindTexture(GL_TEXTURE_2D, texture[0]); 
    glBegin(GL_QUADS);
	glTexCoord2f(1.0f, 0.0f); glVertex3f(-520,-520,520);
	glTexCoord2f(1.0f, 1.0f); glVertex3f(520,-520,520);
    glTexCoord2f(0.0f, 1.0f); glVertex3f(520,-520,-520);
	glTexCoord2f(0.0f, 0.0f); glVertex3f(-520,-520,-520);
	glEnd();
	
	glDisable(GL_TEXTURE_2D);
	
	glRasterPos2i(10, 10);
	printstring(GLUT_BITMAP_HELVETICA_18, frbuf);
	glRasterPos2i(10, 10);
	
	FRAMES++;
	{
		GLint t = glutGet(GLUT_ELAPSED_TIME);
		if (t - TO >= 2000)
		{
			GLfloat seconds = (t - TO) / 1000.0;
			GLfloat fps = FRAMES / seconds;
			sprintf(frbuf, "Frame rate: %f", fps);
			TO = t;
			FRAMES = 0;
		}
	}
	return TRUE;										// Keep Going
}
Exemplo n.º 30
0
void FlowShower::drawMouseOffScreen()
{
	 /*float invRatio = float(game->getResY()) / float(game->getResX());
	 float hs = 0.02f; //mouse horizontal size
	 float vs = hs * invRatio; //mouse vertical size
	 float x = float(game->getMouseX()) / float(game->getResX());
	 float y = 1.0f - float(game->getMouseY()) / float(game->getResY());
	 float left = (1.0f - invRatio) / 2.0f;
	 float right = 1.0f - left;
	 float osx = (x - left) / (right - left);

	 osx -= 1.0f;
	 oldMouseOSX -= 1.0f;
	 for (int j = 0; j < 3; j++)
	 {
	 glBegin(GL_QUADS);

	 glTexCoord2f(osx - hs, y - hs);
	 glVertex2f(osx - hs, y - hs);
	 glTexCoord2f(osx + hs, y - hs);
	 glVertex2f(osx + hs, y - hs);
	 glTexCoord2f(osx + hs, y + hs);
	 glVertex2f(osx + hs, y + hs);
	 glTexCoord2f(osx - hs, y + hs);
	 glVertex2f(osx - hs, y + hs);

	 glTexCoord2f(osx + hs, y - hs);
	 glVertex2f(osx + hs, y - hs);
	 glTexCoord2f(osx - hs, y - hs);
	 glVertex2f(osx - hs, y - hs);
	 glTexCoord2f(oldMouseOSX - hs, oldMouseY - hs);
	 glVertex2f(oldMouseOSX - hs, oldMouseY - hs);
	 glTexCoord2f(oldMouseOSX + hs, oldMouseY - hs);
	 glVertex2f(oldMouseOSX + hs, oldMouseY - hs);

	 glTexCoord2f(osx + vs, y + hs);
	 glVertex2f(osx + vs, y + hs);
	 glTexCoord2f(osx + vs, y - hs);
	 glVertex2f(osx + vs, y - hs);
	 glTexCoord2f(oldMouseOSX + hs, oldMouseY - hs);
	 glVertex2f(oldMouseOSX + hs, oldMouseY - hs);
	 glTexCoord2f(oldMouseOSX + hs, oldMouseY + hs);
	 glVertex2f(oldMouseOSX + hs, oldMouseY + hs);

	 glTexCoord2f(osx - vs, y + hs);
	 glVertex2f(osx - vs, y + hs);
	 glTexCoord2f(osx + vs, y + hs);
	 glVertex2f(osx + vs, y + hs);
	 glTexCoord2f(oldMouseOSX + hs, oldMouseY + hs);
	 glVertex2f(oldMouseOSX + hs, oldMouseY + hs);
	 glTexCoord2f(oldMouseOSX - hs, oldMouseY + hs);
	 glVertex2f(oldMouseOSX - hs, oldMouseY + hs);

	 glTexCoord2f(osx - vs, y - hs);
	 glVertex2f(osx - vs, y - hs);
	 glTexCoord2f(osx - vs, y + hs);
	 glVertex2f(osx - vs, y + hs);
	 glTexCoord2f(oldMouseOSX - hs, oldMouseY + hs);
	 glVertex2f(oldMouseOSX - hs, oldMouseY + hs);
	 glTexCoord2f(oldMouseOSX - hs, oldMouseY - hs);
	 glVertex2f(oldMouseOSX - hs, oldMouseY - hs);

	 glEnd();
	 osx += 1.0f;
	 oldMouseOSX += 1.0f;
	 }
	 osx -= 2.0f;
	 oldMouseOSX -= 2.0f;*/
	float sx = float(game->getMouseX()) / float(game->getResY());
	float sy = 1.0f - float(game->getMouseY()) / float(game->getResY());
	float x = (sx-0.5* float(game->getResX())/ float(game->getResY()))/scale+ viewX;
	float y = (sy-0.5)/scale+ viewY;
	if(x>0)
		x=x-static_cast<int>(x);
	else
		x=x-static_cast<int>(x)+1.0f;
	if(y>0)
		y=y-static_cast<int>(y);
	else
		y=y-static_cast<int>(y)+1.0f;
	float s = 0.02/scale;

	float x1=x - s;
	float x2=x + s;
	float y1=y - s;
	float y2=y + s;

	glBegin(GL_QUADS);

	glTexCoord2f(x1,y1);
	glVertex2f(x1,y1);
	glTexCoord2f(x2, y1);
	glVertex2f(x2, y1);
	glTexCoord2f(x2, y2);
	glVertex2f(x2, y2);
	glTexCoord2f(x1, y2);
	glVertex2f(x1, y2);

	glTexCoord2f(x1,y1);
	glVertex2f(x1,y1);
	glTexCoord2f(x2, y1);
	glVertex2f(x2, y1);

	glTexCoord2f(oldx2, oldy1);
	glVertex2f(oldx2, oldy1);

	glTexCoord2f(oldx1,oldy1);
	glVertex2f(oldx1,oldy1);


	glTexCoord2f(x2, y1);
	glVertex2f(x2, y1);
	glTexCoord2f(x2, y2);
	glVertex2f(x2, y2);
	glTexCoord2f(oldx2, oldy2);
	glVertex2f(oldx2, oldy2);
	glTexCoord2f(oldx2, oldy1);
	glVertex2f(oldx2, oldy1);



	glTexCoord2f(x2, y2);
	glVertex2f(x2, y2);
	glTexCoord2f(x1, y2);
	glVertex2f(x1, y2);
	glTexCoord2f(oldx1, oldy2);
	glVertex2f(oldx1,oldy2);
	glTexCoord2f(oldx2, oldy2);
	glVertex2f(oldx2, oldy2);



	glTexCoord2f(x1, y2);
	glVertex2f(x1, y2);
	glTexCoord2f(x1,y1);
	glVertex2f(x1,y1);
	glTexCoord2f(oldx1,oldy1);
	glVertex2f(oldx1,oldy1);
	glTexCoord2f(oldx1, oldy2);
	glVertex2f(oldx1, oldy2);

	glEnd();
}