示例#1
0
ENTRYPOINT void
draw_ball (ModeInfo *mi)
{
  ball_configuration *bp = &bps[MI_SCREEN(mi)];
  Display *dpy = MI_DISPLAY(mi);
  Window window = MI_WINDOW(mi);
  int c2;

  static const GLfloat bspec[4]  = {1.0, 1.0, 1.0, 1.0};
  static const GLfloat sspec[4]  = {0.0, 0.0, 0.0, 1.0};
  static const GLfloat bshiny    = 128.0;
  static const GLfloat sshiny    = 0.0;

  GLfloat bcolor[4] = {0.0, 0.0, 0.0, 1.0};
  GLfloat scolor[4] = {0.0, 0.0, 0.0, 1.0};

  if (!bp->glx_context)
    return;

  glXMakeCurrent(MI_DISPLAY(mi), MI_WINDOW(mi), *(bp->glx_context));

  glShadeModel(GL_SMOOTH);

  glEnable(GL_DEPTH_TEST);
  glEnable(GL_NORMALIZE);
  glEnable(GL_CULL_FACE);

  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

  glPushMatrix ();

  glScalef(1.1, 1.1, 1.1);

  {
    double x, y, z;
    get_position (bp->rot, &x, &y, &z, !bp->button_down_p);
    glTranslatef((x - 0.5) * 8,
                 (y - 0.5) * 8,
                 (z - 0.5) * 15);

    /* Do it twice because we don't track the device's orientation. */
    glRotatef( current_device_rotation(), 0, 0, 1);
    gltrackball_rotate (bp->trackball);
    glRotatef(-current_device_rotation(), 0, 0, 1);

    get_rotation (bp->rot, &x, &y, &z, !bp->button_down_p);
    glRotatef (x * 360, 1.0, 0.0, 0.0);
    glRotatef (y * 360, 0.0, 1.0, 0.0);
    glRotatef (z * 360, 0.0, 0.0, 1.0);
  }

  bcolor[0] = bp->colors[bp->ccolor].red   / 65536.0;
  bcolor[1] = bp->colors[bp->ccolor].green / 65536.0;
  bcolor[2] = bp->colors[bp->ccolor].blue  / 65536.0;

  c2 = (bp->ccolor + bp->color_shift) % bp->ncolors;
  scolor[0] = bp->colors[c2].red   / 65536.0;
  scolor[1] = bp->colors[c2].green / 65536.0;
  scolor[2] = bp->colors[c2].blue  / 65536.0;

  bp->ccolor++;
  if (bp->ccolor >= bp->ncolors) bp->ccolor = 0;

  mi->polygon_count = 0;

  glScalef (2.0, 2.0, 2.0);

  move_spikes (mi);

  glMaterialfv (GL_FRONT, GL_SPECULAR,            bspec);
  glMateriali  (GL_FRONT, GL_SHININESS,           bshiny);
  glMaterialfv (GL_FRONT, GL_AMBIENT_AND_DIFFUSE, bcolor);
  glCallList (bp->ball_list);
  mi->polygon_count += (SPHERE_SLICES * SPHERE_STACKS);

  glMaterialfv (GL_FRONT, GL_SPECULAR,            sspec);
  glMaterialf  (GL_FRONT, GL_SHININESS,           sshiny);
  glMaterialfv (GL_FRONT, GL_AMBIENT_AND_DIFFUSE, scolor);
  draw_spikes (mi);
  glPopMatrix ();

  if (mi->fps_p) do_fps (mi);
  glFinish();

  glXSwapBuffers(dpy, window);
}
示例#2
0
void
Model::Draw()
{
  glCallList(display_list);
}
示例#3
0
void Font::Print(int x, int y, const char *str, ...)
{
	if(str == NULL)
		return;

	char		strText[2048];
	va_list		p_Argument;

	va_start(p_Argument, str);
	vsprintf(strText, str, p_Argument);
	va_end(p_Argument);

	int len = (int)strlen(strText);

	int phraseWidth[100] = {0};
	int textHeight = 0;

	// Obter comprimento de cada frase
	if(hAlign != FONT_HORIZ_ALIGN_LEFT)
	{
		for(int i = 0, line = 0; i < len; i++)
		{
			char c = strText[i];

			if(c == ' ')
				phraseWidth[line] += int(maxWidth / 3);
			else if(c == '\t')
				phraseWidth[line] += maxWidth * 2;
			else if(c != '\n')
			{
				phraseWidth[line] += width[c];
				if(i < len - 1 && strText[i + 1] != '\n') phraseWidth[line] += hInterval;
			}
			else 
				line++;
		}
	}

	// Obter altura do texto
	if(vAlign != FONT_VERT_ALIGN_TOP)
	{
		textHeight = step;
		for(int i = 0; i < len; i++)
			if(strText[i] == '\n')
				textHeight += vInterval;
	}

	if(vAlign == FONT_VERT_ALIGN_CENTER)
		y -= int(textHeight / 2);
	else if(vAlign == FONT_VERT_ALIGN_BOTTOM)
		y -= textHeight;

    glLoadIdentity();
	glTranslatef((float)x, (float)y, 0);

	if(hAlign == FONT_HORIZ_ALIGN_CENTER)
		glTranslatef(float(-phraseWidth[0] / 2), 0, 0);
	else if(hAlign == FONT_HORIZ_ALIGN_RIGHT)
		glTranslatef(float(-phraseWidth[0]), 0, 0);

	for(int i = 0, line = 0; i < len; i++)
	{
		char c = strText[i];

		if(c == ' ')
		{
			glTranslatef(float(maxWidth / 3), 0, 0);
		}
		else if(c == '\n')
		{
			line++;
			glLoadIdentity();
			glTranslatef((float)x, float(y + vInterval * line), 0);
			
			if(hAlign == FONT_HORIZ_ALIGN_CENTER)
				glTranslatef(float(-phraseWidth[line]/2), 0, 0);
			else if(hAlign == FONT_HORIZ_ALIGN_RIGHT)
				glTranslatef(float(-phraseWidth[line]), 0, 0);
		}
		else if(c == '\t')
		{
			glTranslatef(float(maxWidth * 2), 0, 0);
		}
		else
		{
			glCallList(list_id + c);
			glTranslatef(float(width[c] + hInterval), 0, 0);
		}
	}
}
示例#4
0
void TGLFunWidget::displaySceleton(void)
{
    if (!xList2)
        createSceleton();
    glCallList(xList2);
}
// Draw the track in the panning aligned mode.
void cGrTrackMap::drawTrackPanningAligned(
	int Winx,
	int Winy,
	int Winw,
	int Winh,
	tCarElt *currentCar,
	tSituation *s
)
{
	float tracksize = MAX(track_width, track_height);
	float radius = MIN(500.0, tracksize/2.0);

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

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

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

	glPopMatrix();
	glMatrixMode(GL_MODELVIEW);

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

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

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

	glColor4fv(currentCarColor);
	if (cardot != 0) {
		glMatrixMode(GL_MODELVIEW);
		glPushMatrix();
		glTranslatef(x + map_size/2.0, y + map_size/2.0, 0.0);
		glScalef(1.0/factor, 1.0/factor, 1.0);
		glCallList(cardot);
		glPopMatrix();
	}
}
static void draw_block(ModeInfo *mi, entity *ent)
{
    blocktube_configuration *lp = &lps[MI_SCREEN(mi)];
    glCallList (lp->block_dlist);
    mi->polygon_count += lp->polys;
}
示例#7
0
/* Draw one bitmapped symbol by current font */
void glfDrawBSymbol(char s)
{
	if ((bmf_curfont < 0) || (bmf_in_use[bmf_curfont] == 0)) return;
	
	glCallList(list_base[bmf_curfont]+(unsigned char)s);
}
示例#8
0
//draw!
void PolarAnimated::draw(){
    glMatrixMode(GL_MODELVIEW);

    m_framecount++;

    double framecount = m_framecount * .3;

    glPushMatrix();
    glRotated(framecount / 3,0,-1,0);
    double scale = (60 - framecount) / 20;
    scale = MAX(scale, .2);
    glScaled(scale, scale, scale);


    glPushMatrix();
    glTranslatef(0,-1.0,0);
    glScalef(100,1,50);
    //shader stuff
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D,textures_->value(CRACK_COLOR));
shader_programs_->value(CRACK_SHADER)->setUniformValue("colormap",0);
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D,textures_->value(CRACK_NORM));
shader_programs_->value(CRACK_SHADER)->setUniformValue("normalmap",1);
shader_programs_->value(CRACK_SHADER)->bind();
shader_programs_->value(CRACK_SHADER)->setUniformValue("eyept",m_engine->camera_.eye.x, m_engine->camera_.eye.y, m_engine->camera_.eye.z);
    //glEnable(GL_TEXTURE_2D);
    //glBindTexture(GL_TEXTURE_2D,textures_->value(CRACK_COLOR));
    //end shader stuff
    ground->draw();
shader_programs_->value(CRACK_SHADER)->release();

    glPopMatrix();

    glPushMatrix();
    glScaled(.1,.1,.1);
    glRotated(90,1,0,0);



//    glPushMatrix();
//    glTranslated(0,0,2);
//    gluDisk(m_quadric,0,100,4,4);
//    gluDisk(m_quadric,0,400,30,30);
//    glPopMatrix();

    glActiveTexture(GL_TEXTURE0);
    glBindTexture(GL_TEXTURE_CUBE_MAP, textures_->value("cube_map_1"));
    shader_programs_->value(NAIL_SHADER)->bind();
    shader_programs_->value(NAIL_SHADER)->setUniformValue("CubeMap",GL_TEXTURE0);
    shader_programs_->value(NAIL_SHADER)->setUniformValue("eyept",m_engine->camera_.eye.x, m_engine->camera_.eye.y, m_engine->camera_.eye.z);

    for(int i = 0; i < m_shapes->length(); i++){
        Shapes s = m_shapes->at(i);

        glPushMatrix();
        glTranslated(s.t.x,s.t.y,0);
        glRotated(s.r.angle, s.r.x,s.r.y,s.r.z);
        //glTranslated(s.t.x,s.t.y,5 * sin(m_framecount / 20 + s.polt));
        //glTranslated(s.t.x,s.t.y,(40 - s.polr) * sin(m_framecount / 20 - s.polr / 15) / (m_framecount / 20 - s.polr / 15));
        //gluCylinder(m_quadric,.25,0,10,10,10);

        double temp = framecount / 15 - s.polr / 10 - 3;
        temp = MAX(temp, .1);
        glTranslated(0,0,10 * sin(temp) / (temp * temp * temp * temp));

        glRotated(-90,1,0,0);
        glScaled(5,5,5);
        if (s.shape){
            glCallList(models_->value(BRAD_MODEL).idx);
        } else {
            glScaled(1,2,1);
            glCallList(models_->value(NAIL_MODEL).idx);
        }
        glPopMatrix();
    }

    for (int i = 0; i < m_shapes_ring->length(); i++){
        Shapes s = m_shapes_ring->at(i);

        glPushMatrix();
        glTranslated(s.t.x,s.t.y,0);

        glRotated(-90,1,0,0);
        glScaled(5,5,5);

        glScaled(1,2,1);
        glCallList(models_->value(NAIL_MODEL).idx);

        glPopMatrix();
    }


    shader_programs_->value(NAIL_SHADER)->release();

     glActiveTexture(GL_TEXTURE0);
     glBindTexture(GL_TEXTURE_2D,textures_->value(ROPE_OCC));
     shader_programs_->value(ROPE_SHADER)->setUniformValue("colormap",0);

     glActiveTexture(GL_TEXTURE1);
     glBindTexture(GL_TEXTURE_2D,textures_->value(ROPE_NORM));

     shader_programs_->value(ROPE_SHADER)->setUniformValue("normalmap",1);


     //shader_programs_->value(ROPE_SHADER)->setUniformValue("sag",(GLfloat)(0.5 + 0.01*(m_framesElapsed%100)));
     shader_programs_->value(ROPE_SHADER)->setUniformValue("eyept",m_engine->camera_.eye.x, m_engine->camera_.eye.y, m_engine->camera_.eye.z);
     shader_programs_->value(ROPE_SHADER)->bind();


     float wtf=25;
    for (int i = 0; i < m_ropes->length(); i++){
        glPushMatrix();
        glScaled(wtf,wtf,wtf);

        rope r = m_ropes->at(i);

        //glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);
        drawRope(r,true);

        glPopMatrix();
    }

    shader_programs_->value(ROPE_SHADER)->release();

    glPopMatrix();
    glPopMatrix();
}
示例#9
0
文件: vpaint.c 项目: xtmacbook/SGI
/*
 * Called when window needs to be redrawn 
 */
void 
redraw(void)
{
    int i, x, y;

    if (viewImage) {
	glReadBuffer(GL_FRONT);
	glDrawBuffer(GL_FRONT);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	glDrawPixels(w, h, GL_RGBA, GL_UNSIGNED_BYTE, (GLubyte *) img);
    } else if (!drawEdges) {
	glDrawBuffer(useStrokes ? GL_BACK : GL_FRONT);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	/*
	 * Just draw the voronoi regions 
	 */
	for (i = 0; i < numPoints; i++) {
	    glPushMatrix();
	    glTranslatef(points[i].x, points[i].y, 0.f);
	    glColor3ub(points[i].r, points[i].g, points[i].b);
	    glCallList(1);
	    glColor3f(0.f, 0.f, 0.f);
	    glPopMatrix();
	}

	if (useStrokes)
	    glutSwapBuffers();
    } else {
	glClear(GL_COLOR_BUFFER_BIT | GL_ACCUM_BUFFER_BIT);
	glReadBuffer(GL_BACK);
	glDrawBuffer(GL_BACK);

	glutSetWindowTitle("Voronoi art (working...)");
	glutSetCursor(GLUT_CURSOR_WAIT);
	for (y = 0; y < 3; y++)
	    for (x = 0; x < 3; x++) {
		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
		glPushMatrix();
		glTranslatef(x - 1, y - 1, 0.0);

		for (i = 0; i < numPoints; i++) {
		    glPushMatrix();
		    glTranslatef(points[i].x, points[i].y, 0.f);
		    glColor3ub(points[i].r, points[i].g, points[i].b);
		    glCallList(1);
		    glPopMatrix();
		}
		glPopMatrix();

		glAccum(GL_ACCUM, edgeKernel[3 * y + x]);
	    }

	glAccum(GL_RETURN, 0.5);
	glutSetWindowTitle("Voronoi art");
	glutSetCursor(GLUT_CURSOR_INHERIT);

	/*
	 * Convert to grayscale 
	 */
	glMatrixMode(GL_COLOR);
	glLoadMatrixf(sumMatrix);
	glCopyPixels(0, 0, w, h, GL_COLOR);
	glLoadIdentity();
	glMatrixMode(GL_MODELVIEW);

	/*
	 * Threshold 
	 */
	glPixelTransferi(GL_MAP_COLOR, GL_TRUE);
	glCopyPixels(0, 0, w, h, GL_COLOR);
	glPixelTransferi(GL_MAP_COLOR, GL_FALSE);

	/*
	 * Draw the voronoi regions in the front buffer 
	 */
	glDrawBuffer(GL_FRONT);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	for (i = 0; i < numPoints; i++) {
	    glPushMatrix();
	    glTranslatef(points[i].x, points[i].y, 0.f);
	    glColor3ub(points[i].r, points[i].g, points[i].b);
	    glCallList(1);
	    glColor3f(0.f, 0.f, 0.f);
	    glPopMatrix();
	}

	/*
	 * Blend in the edge lines 
	 */
	glClear(GL_DEPTH_BUFFER_BIT);
	glBlendEquationEXT(GL_MIN_EXT);
	glEnable(GL_BLEND);
	glCopyPixels(0, 0, w, h, GL_COLOR);
	glDisable(GL_BLEND);
    }

    glFlush();
}
示例#10
0
void R3Model::
Draw(const R3DrawFlags draw_flags) const
{
  // Check triangles
  if (!triangles) return;
  if (triangles->NTriangles() == 0) return;
  assert(triangle_materials.NEntries() == NTriangles());
  assert(material_triangles.NEntries() == NMaterials());

  // Draw model
  if (draw_flags != 0) {
#   if (DRAW_METHOD == DRAW_WITH_VBO)
      // Initialize material
      R3null_material.Draw(TRUE);

      // Create VBO
      if (opengl_id == 0) {
        // Load materials
        for (int i = 0; i < NMaterials(); i++) {
          R3Material *material = Material(i);
          material->Load();
        }

        // Create VBO vertex array
        VBOVertex *vbo_vertices = new VBOVertex [ NVertices() ];
        for (int i = 0; i < NVertices(); i++) {
          R3TriangleVertex *vertex = Vertex(i);
          const R3Point& position = vertex->Position();
          const R2Point& texcoords = vertex->TextureCoords();
          vbo_vertices[i].x = position.X();
          vbo_vertices[i].y = position.Y();
          vbo_vertices[i].z = position.Z();
          vbo_vertices[i].s = texcoords.X();
          vbo_vertices[i].t = texcoords.Y();
          vertex->SetMark(i);
        }

        // Create VBO triangle array
        GLint *vbo_triangles = new GLint [ 3 * NTriangles() ];
        for (int i = 0; i < NTriangles(); i++) {
          R3Triangle *triangle = Triangle(i);
          R3TriangleVertex *v0 = triangle->Vertex(0);
          R3TriangleVertex *v1 = triangle->Vertex(0);
          R3TriangleVertex *v2 = triangle->Vertex(0);
          vbo_triangles[3*i+0] = v0->Mark();
          vbo_triangles[3*i+1] = v1->Mark();
          vbo_triangles[3*i+2] = v2->Mark();
        }

        // Create VBO for vertices
        glGenBuffers(1, &opengl_id);
        glBindBuffer(GL_ARRAY_BUFFER, opengl_id);
        glBufferData(GL_ARRAY_BUFFER, NVertices() * sizeof(VBOVertex), vbo_vertices, GL_STATIC_DRAW);
        
        // Create VBO for triangles
        glGenBuffers(1, &opengl_id2);
        glBindBuffer(GL_ARRAY_BUFFER, opengl_id2);
        glBufferData(GL_ELEMENT_BUFFER, 3 * NTriangles() * sizeof(GLuint), vbo_triangles, GL_STATIC_DRAW);

        // Delete VBO data
        delete [] vbo_vertices;
        delete [] vbo_triangles;
      }
        
      // Draw VBO
      glBindBuffer(GL_ARRAY_BUFFER, opengl_id);
      glEnableClientState(GL_VERTEX_ARRAY);
      glEnableClientState(GL_TEXTURE_COORD_ARRAY);
      glVertexPointer(3, GL_FLOAT, sizeof(VBOVertex), (void *) 0);
      glTexCoordPointer(2, GL_FLOAT, sizeof(VBOVertex), (void *) (3 * sizeof(GLfloat)));
      glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, opengl_id2);  
      glDrawElements(GL_TRIANGLES, NTriangles(), GL_UNSIGNED_INT, (void *) 0);
      glDisableClientState(GL_VERTEX_ARRAY);
      glDisableClientState(GL_TEXTURE_COORD_ARRAY);

      // Reset material
      R3null_material.Draw(TRUE);
#   elif (DRAW_METHOD == DRAW_WITH_DISPLAY_LIST)
      // Initialize material
      R3null_material.Draw(TRUE);

      // Create display list
      if (opengl_id == 0) {
        // Load materials
        for (int i = 0; i < NMaterials(); i++) {
          R3Material *material = Material(i);
          material->Load();
        }
        
        // Begin display list
        R3Model *model = (R3Model *) this;
        model->opengl_id = glGenLists(1);
        glNewList(opengl_id, GL_COMPILE);

        // Draw triangles
        for (int i = 0; i < NMaterials(); i++) {
          R3Material *material = Material(i);
          material->Draw();
          glBegin(GL_TRIANGLES);
          for (int j = 0; j < material_triangles[i]->NEntries(); j++) {
            R3Triangle *triangle = material_triangles[i]->Kth(j);
            R3LoadNormal(triangle->Normal());

            R3TriangleVertex *v0 = triangle->Vertex(0);
            R3LoadTextureCoords(v0->TextureCoords());
            R3LoadPoint(v0->Position());

            R3TriangleVertex *v1 = triangle->Vertex(1);
            R3LoadTextureCoords(v1->TextureCoords());
            R3LoadPoint(v1->Position());

            R3TriangleVertex *v2 = triangle->Vertex(2);
            R3LoadTextureCoords(v2->TextureCoords());
            R3LoadPoint(v2->Position());
          }
          glEnd();
        }
        
        // End display list
        glEndList();
      }

      // Call display list
      glCallList(opengl_id);

      // Reset material
      R3null_material.Draw(TRUE);
#   else
      // Draw individual triangles
      for (int i = 0; i < NMaterials(); i++) {
        R3Material *material = Material(i);
        material->Draw();
        glBegin(GL_TRIANGLES);
        for (int j = 0; j < material_triangles[i]->NEntries(); j++) {
          R3Triangle *triangle = material_triangles[i]->Kth(j);
          R3LoadNormal(triangle->Normal());
          
          R3TriangleVertex *v0 = triangle->Vertex(0);
          R3LoadTextureCoords(v0->TextureCoords());
          R3LoadPoint(v0->Position());
          
          R3TriangleVertex *v1 = triangle->Vertex(1);
          R3LoadTextureCoords(v1->TextureCoords());
          R3LoadPoint(v1->Position());
          
          R3TriangleVertex *v2 = triangle->Vertex(2);
          R3LoadTextureCoords(v2->TextureCoords());
          R3LoadPoint(v2->Position());
        }
        glEnd();
      }
#   endif
  }
  else {
    // Draw triangles
    glBegin(GL_TRIANGLES);
    for (int i = 0; i < NTriangles(); i++) {
      R3Triangle *triangle = Triangle(i);
      R3LoadNormal(triangle->Normal());
      R3TriangleVertex *v0 = triangle->Vertex(0);
      R3LoadPoint(v0->Position());
      R3TriangleVertex *v1 = triangle->Vertex(1);
      R3LoadPoint(v1->Position());
      R3TriangleVertex *v2 = triangle->Vertex(2);
      R3LoadPoint(v2->Position());
    }
    glEnd();
  }
}
示例#11
0
int DrawGLScene(GLvoid)									// Here's Where We Do All The Drawing
{
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);	// Clear Screen And Depth Buffer
	Move_Beings();
	for(int i = centersquare[0] - 25; i < centersquare[0] + 25; ++i) {
		for(int d = centersquare[1] - 25; d < centersquare[1] + 25; ++d) {
			if(i > 0 && i < 250 && d > 0 && d < 250) {
				glLoadIdentity();
				glTranslatef(0.0f, 0.0f, -25.0f);
				glRotatef(-30.0f, 1.0f, 0.0f, 0.0f);
				glRotatef( 45.0f, 0.0f, 0.0f, 1.0f);
				glTranslatef(-camerapos[0],-camerapos[1], 0.0f);
				glTranslatef(GLfloat(i), GLfloat(d), 0.0f);
				glColor3f(0.5f, 0.5f, 0.5f);
				glCallList(list[city[i][d]]);
			}
		}
	}
	for(i = 0; i < population; ++i) {
		if(being[i].xPos > centersquare[0] - 25 && being[i].xPos < centersquare[0] + 25 && 
			being[i].yPos > centersquare[1] - 25 && being[i].yPos < centersquare[1] + 25) {
			glLoadIdentity();
			glTranslatef(0.0f, 0.0f, -25.0f);
			glRotatef(-30.0f, 1.0f, 0.0f, 0.0f);
			glRotatef( 45.0f, 0.0f, 0.0f, 1.0f);
			glTranslatef(-camerapos[0],-camerapos[1], 0.0f);
			glTranslatef(GLfloat(being[i].xPos), being[i].yPos, 0.0f);
			switch(being[i].state) {
			case 0:
				glColor3f(0.6f, 0.0f, 0.0f);
				break;
			case 1:
				glColor3f(1.0f, 0.3f, 0.3f);
				break;
			case 2:
				glColor3f(being[i].flash, 1.0f, being[i].flash);
				being[i].flash -= 0.03 * framelength;
				break;
			}
			glRotatef(-90.0f * being[i].dir, 0.0f, 0.0f, 1.0f);
			if(being[i].moving == true) {
				glTranslatef(0.0f, being[i].move, 0.0f);
			}
			glCallList(list[2]);
		}
	}
	if(hud) {
		GLfloat a,b;
		a = GLfloat(population - zombies) / GLfloat(population);	//Red Bar Length
		b = GLfloat(zombies) / GLfloat(population);					//Green Bar Length
		glLoadIdentity();
		glTranslatef(-2.7f, 2.0f,-5.0f);
		glBegin(GL_QUADS);
			glNormal3f(0.0f, 0.0f, 1.0f);
			glColor3f(1.0f, 0.0f, 0.0f);
			glVertex3f(0.0f, 0.03f, 0.0f);
			glVertex3f(0.0f, 0.0f, 0.0f);
			glVertex3f(   a, 0.0f, 0.0f);
			glVertex3f(   a, 0.03f, 0.0f);

			glColor3f(0.0f, 1.0f, 0.0f);
			glVertex3f(0.0f,-0.03f, 0.0f);
			glVertex3f(0.0f, 0.0f, 0.0f);
			glVertex3f(   b, 0.0f, 0.0f);
			glVertex3f(   b,-0.03f, 0.0f);
		glEnd();
	}
	return true;
}
示例#12
0
void _stdcall COBJModel::DrawModel()
{
	
		glCallList(m_iDisplayList);
	
}
示例#13
0
void GUItable::PrivateDraw()
{
	glDisable(GL_TEXTURE_2D);
		glColor4f(0.0, 0.0, 0.0, 0.4f);	
	glBegin(GL_QUADS);		
		glTexCoord2d(0.0f, 0.0f);
		glVertex3f(10, 10, 0);
		glTexCoord2d(0.0f, 1.0);		
		glVertex3f(10, h-10, 0);		
		glTexCoord2d(1.0, 1.0);		
		glVertex3d(w-10, h-10, 0);
		glTexCoord2d(1.0f, 0.0f);		
		glVertex3f(w-10, 10, 0);		
	glEnd();
	glColor3f(1.0, 1.0, 1.0);
	glEnable(GL_TEXTURE_2D);
	glCallList(displayList);
	
	int inSet=16;
	
	if(w<200)
		inSet=0;

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

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

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

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

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

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

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

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

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

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

			guifont->Print(inSet, (i+1)*rowHeight, data[i+position]);			
			glColor4f(1.0,1.0,1.0,1.0f);
		}
	}
}
示例#14
0
ENTRYPOINT void
draw_gears (ModeInfo *mi)
{
  gears_configuration *bp = &bps[MI_SCREEN(mi)];
  Display *dpy = MI_DISPLAY(mi);
  Window window = MI_WINDOW(mi);
  int i;

  if (!bp->glx_context)
    return;

  glXMakeCurrent(MI_DISPLAY(mi), MI_WINDOW(mi), *(bp->glx_context));

  glShadeModel(GL_SMOOTH);

  glEnable(GL_DEPTH_TEST);
  glEnable(GL_NORMALIZE);
  glEnable(GL_CULL_FACE);

  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

  glPushMatrix ();

  {
    double x, y, z;
    get_position (bp->rot, &x, &y, &z, !bp->button_down_p);
    glTranslatef ((x - 0.5) * 4,
                  (y - 0.5) * 4,
                  (z - 0.5) * 7);

    /* Do it twice because we don't track the device's orientation. */
    glRotatef( current_device_rotation(), 0, 0, 1);
    gltrackball_rotate (bp->trackball);
    glRotatef(-current_device_rotation(), 0, 0, 1);

    get_rotation (bp->rot, &x, &y, &z, !bp->button_down_p);

    /* add a little rotation for -no-spin mode */
    x -= 0.14;
    y -= 0.06;

    glRotatef (x * 360, 1.0, 0.0, 0.0);
    glRotatef (y * 360, 0.0, 1.0, 0.0);
    glRotatef (z * 360, 0.0, 0.0, 1.0);
  }

  /* Center the scene's bounding box in the window,
     and scale it to fit. 
   */
  {
    GLfloat w = bp->bbox.x2 - bp->bbox.x1;
    GLfloat h = bp->bbox.y2 - bp->bbox.y1;
    GLfloat s = 10.0 / (w > h ? w : h);
    glScalef (s, s, s);
    glTranslatef (-(bp->bbox.x1 + w/2),
                  -(bp->bbox.y1 + h/2),
                  0);
  }

  mi->polygon_count = 0;

  for (i = 0; i < bp->ngears; i++)
    {
      gear *g = bp->gears[i];

      glPushMatrix();

      glTranslatef (g->x, g->y, g->z);
      glRotatef (g->th, 0, 0, 1);

      glCallList (g->dlist);
      mi->polygon_count += g->polygons;

      glPopMatrix ();
    }

  if (bp->planetary_p)
    {
      glCallList (bp->armature_dlist);
      mi->polygon_count += bp->armature_polygons;
    }

  glPopMatrix ();

  /* spin gears */
  if (!bp->button_down_p)
    for (i = 0; i < bp->ngears; i++)
      {
        gear *g = bp->gears[i];
        double off = g->ratio * 5 * speed;
        if (g->th > 0)
          g->th += off;
        else
          g->th -= off;
      }

  if (mi->fps_p) do_fps (mi);
  glFinish();

  glXSwapBuffers(dpy, window);
}
示例#15
0
/*!
    \fn Processor::Render(int persistence,bool al,bool pc,bool vo,bool sk,bool mo,bool allindflag,int pnum,int rank,bool wf,bool fs)
 */
void Processor::Render(int persistence,bool alphaShape,bool allPockets,bool onlyPockets,bool onlyVoids,bool skinSurface,bool mouths,bool allindflag,int pnum,int rank,bool wireFrame,
                       bool alphaSkinSurface,bool alphaSkinWireFrame,bool smoothShading,bool skinWireFrame,bool pocketWireFrame, bool powerDiag,
                       bool cHull, bool cHullWF, bool cHullNorm, bool showPath, bool showSpaceFill)
{
        glEnable(GL_NORMALIZE);
        if(alcx)
        {
                alcx->Render(rank,alphaShape,wireFrame,alphaSkinSurface,smoothShading,alphaSkinWireFrame);

                if (onlyVoids || onlyPockets || allPockets)
                {
                        if(allindflag)
                        {
                                pocket->Render(alcx->delcx,vertexList,PocketNMouths,allPockets,onlyPockets,onlyVoids,skinSurface,persistence,rank,smoothShading,skinWireFrame,mouths,pocketWireFrame);
                        }
                        else
                        {
                                pocket->RenderSingle(alcx->delcx,vertexList,PocketNMouths,allPockets,onlyPockets,onlyVoids,skinSurface,persistence,rank,pnum,smoothShading,skinWireFrame,mouths,pocketWireFrame);
                        }
                }
                if (mouths)
                {
                        if (!onlyVoids)
                        {
                                if(allindflag)
                                {
                                        mouth->Render(alcx->delcx,vertexList,persistence);
                                }
                                else
                                {
                                        mouth->RenderMouthOfPocket(alcx->delcx,vertexList,persistence,pnum);
                                }
                        }
                }

            glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, LightMaterial::MatAmb[3]);
            glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, LightMaterial::MatDiff[3]);
            glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, LightMaterial::MatSpec[3]);
            glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, LightMaterial::MatShin[3]);
            glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, LightMaterial::MatEmission);

            if(proteinRenderer->init() && showSpaceFill){
                proteinRenderer->render();
            }
            powerDiagram->render(powerDiag, showPath);

            glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, LightMaterial::MatAmb[3]);
            glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, LightMaterial::MatDiff[3]);
            glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, LightMaterial::MatSpec[3]);
            glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, LightMaterial::MatShin[3]);
            glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, LightMaterial::MatEmission);

            glEnable(GL_COLOR_MATERIAL);
            if(cHull){
                glLineWidth(1);
                glColor3d(0.2, 0.6, 0.2);
                if(cHullWF){
                    glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
                }else{
                    glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
                }

                if (glIsList(cHullId) == GL_FALSE){
                    cHullId = glGenLists(1);
                    glNewList(cHullId, GL_COMPILE_AND_EXECUTE);

                    glBegin(GL_TRIANGLES);
                    for(int i=1; i< alcx->delcx->DeluanayTrigs.size(); i++){
                        Triangle tri = alcx->delcx->DeluanayTrigs[i];
                        if(tri.Hull){
                            glNormal3d(tri.Normal->X, tri.Normal->Y, tri.Normal->Z);
                            for(int j=1;j<4;j++){
                                Vector3 v = alcx->vertexList[tri.Corners[j]].getCoordVector();
                                glVertex3d(v.X, v.Y, v.Z);
                            }
                        }
                    }
                    glEnd();

                    glEndList();
                } else {
                    glCallList(cHullId);
                }
                if(cHullNorm){
                    if(glIsList(cHullNormId) == GL_FALSE){
                        cHullNormId = glGenLists(1);
                        glNewList(cHullNormId, GL_COMPILE_AND_EXECUTE);

                        //======= Drawing Normals of Convex Hull Tris =================

                        glColor3d(1,0,0);
                        glLineWidth(2);
                        glBegin(GL_LINES);
                        for(int i=1; i< alcx->delcx->DeluanayTrigs.size(); i++){
                            Triangle tri = alcx->delcx->DeluanayTrigs[i];
                            if(tri.Hull){
                                glNormal3d(tri.Normal->X, tri.Normal->Y, tri.Normal->Z);
                                Vector3 center;
                                for(int j=1; j<4; j++){
                                    Vertex v = alcx->vertexList[tri.Corners[j]];
                                    Vector3 coord = v.getCoordVector();
                                    Vector3::Sum(&center, &coord, &center);
                                }
                                Vector3::Scale(&center, &center, 1/3.0);
                                glVertex3d(center.X, center.Y, center.Z);
                                Vector3::Sum(&center, tri.Normal, &center);
                                Vector3::Sum(&center, tri.Normal, &center);
                                glVertex3d(center.X, center.Y, center.Z);
                            }
                        }
                        glEnd();

                        glEndList();
                    } else {
                        glCallList(cHullNormId);
                    }
                }
            }
            glDisable(GL_COLOR_MATERIAL);
            glDisable(GL_NORMALIZE);
        }
}
// render
void PlayerOverlayLevel::Render(unsigned int aId, float aTime, const Transform2 &aTransform)
{
	// get the player
	Player *player = Database::player.Get(aId);

	// get the attached entity identifier
	unsigned int id = player->mAttach;

	// get level resource
	Resource *levelresource = Database::resource.Get(id).Get(0x9b99e7dd /* "level" */);
	if (!levelresource)
		return;
	int new_level = xs_FloorToInt(levelresource->GetValue());
	float new_part = levelresource->GetValue() - new_level;

	// if the level has not changed...
	if (new_part == cur_part && new_level == cur_level && !wasreset)
	{
		// call the existing draw list
		glCallList(level_handle);
		return;
	}

	// update level
	cur_level = new_level;
	cur_part = new_part;

	// start a new draw list list
	glNewList(level_handle, GL_COMPILE_AND_EXECUTE);

	// draw level gauge
	glBegin(GL_QUADS);

	// background
	glColor4fv(levelcolor[cur_level]);
	glVertex2f(levelrect.x, levelrect.y);
	glVertex2f(levelrect.x + levelrect.w, levelrect.y);
	glVertex2f(levelrect.x + levelrect.w, levelrect.y + levelrect.h);
	glVertex2f(levelrect.x, levelrect.y + levelrect.h);

	// fill gauge
	glColor4fv(levelcolor[cur_level+1]);
	glVertex2f(levelrect.x, levelrect.y);
	glVertex2f(levelrect.x + levelrect.w * cur_part, levelrect.y);
	glVertex2f(levelrect.x + levelrect.w * cur_part, levelrect.y + levelrect.h);
	glVertex2f(levelrect.x, levelrect.y + levelrect.h);

	glEnd();

	// draw the level icon
	glColor4f(0.4f, 0.5f, 1.0f, 1.0f);
	glPushMatrix();
	glTranslatef(levelpos.x, levelpos.y, 0.0f);
	glScalef(4, 4, 1);
	glCallList(Database::drawlist.Get(0x8cdedbba /* "circle16" */));
	glPopMatrix();

	// draw level number
	char level[16];
	sprintf(level, "x%d", cur_level);

	glEnable(GL_TEXTURE_2D);
	glBindTexture(GL_TEXTURE_2D, OGLCONSOLE_glFontHandle);

	glColor4f(0.4f, 0.5f, 1.0f, 1.0f);

	glBegin(GL_QUADS);
	float w = 8;
	float h = -8;
	float x = levelpos.x + 8;
	float y = levelpos.y - 0.5f * h;
	float z = 0;
	OGLCONSOLE_DrawString(level, x, y, w, h, z);

	glEnd();

	glDisable(GL_TEXTURE_2D);

	glEndList();
}
void BL_Texture::setTexEnv(BL_Material *mat, bool modulate)
{
    if (modulate || !GLEW_ARB_texture_env_combine) {
        glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
        return;
    }

    if (glIsList(mEnvState))
    {
        glCallList(mEnvState);
        return;
    }
    if (!mEnvState)
        mEnvState = glGenLists(1);

    glNewList(mEnvState, GL_COMPILE_AND_EXECUTE);

    glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB );

    GLfloat blend_operand		= GL_SRC_COLOR;
    GLfloat blend_operand_prev  = GL_SRC_COLOR;
    GLfloat alphaOp				= GL_SRC_ALPHA;

    GLenum combiner	= GL_COMBINE_RGB_ARB;
    GLenum source0	= GL_SOURCE0_RGB_ARB;
    GLenum source1	= GL_SOURCE1_RGB_ARB;
    GLenum source2	= GL_SOURCE2_RGB_ARB;
    GLenum op0		= GL_OPERAND0_RGB_ARB;
    GLenum op1		= GL_OPERAND1_RGB_ARB;
    GLenum op2		= GL_OPERAND2_RGB_ARB;

    // switch to alpha combiners
    if ( mat->flag[mUnit]  &TEXALPHA ) {
        combiner = GL_COMBINE_ALPHA_ARB;
        source0	= GL_SOURCE0_ALPHA_ARB;
        source1 = GL_SOURCE1_ALPHA_ARB;
        source2 = GL_SOURCE2_ALPHA_ARB;
        op0 = GL_OPERAND0_ALPHA_ARB;
        op1 = GL_OPERAND1_ALPHA_ARB;
        op2 = GL_OPERAND2_ALPHA_ARB;
        blend_operand = GL_SRC_ALPHA;
        blend_operand_prev = GL_SRC_ALPHA;
        // invert
        if (mat->flag[mUnit] &TEXNEG) {
            blend_operand_prev = GL_ONE_MINUS_SRC_ALPHA;
            blend_operand = GL_ONE_MINUS_SRC_ALPHA;
        }
    }
    else {
        if (mat->flag[mUnit] &TEXNEG) {
            blend_operand_prev=GL_ONE_MINUS_SRC_COLOR;
            blend_operand = GL_ONE_MINUS_SRC_COLOR;
        }
    }
    bool using_alpha = false;

    if (mat->flag[mUnit]  &USEALPHA) {
        alphaOp = GL_ONE_MINUS_SRC_ALPHA;
        using_alpha=true;
    }
    else if (mat->flag[mUnit]  &USENEGALPHA) {
        alphaOp = GL_SRC_ALPHA;
        using_alpha = true;
    }

    switch (mat->blend_mode[mUnit]) {
    case BLEND_MIX:
    {
        // ------------------------------
        if (!using_alpha) {
            GLfloat base_col[4];
            base_col[0]	 = base_col[1]  = base_col[2]  = 0.f;
            base_col[3]	 = 1.f-mat->color_blend[mUnit];
            glTexEnvfv( GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR,base_col );
        }
        glTexEnvf(	GL_TEXTURE_ENV, combiner,	GL_INTERPOLATE_ARB);
        glTexEnvf(	GL_TEXTURE_ENV, source0,	GL_PREVIOUS_ARB);
        glTexEnvf(	GL_TEXTURE_ENV, op0,		blend_operand_prev );
        glTexEnvf(	GL_TEXTURE_ENV, source1,	GL_TEXTURE );
        glTexEnvf(	GL_TEXTURE_ENV, op1,		blend_operand);
        if (!using_alpha)
            glTexEnvf(	GL_TEXTURE_ENV, source2,	GL_CONSTANT_ARB );
        else
            glTexEnvf(	GL_TEXTURE_ENV, source2,	GL_TEXTURE );

        glTexEnvf(	GL_TEXTURE_ENV, op2,		alphaOp);
    }
    break;
    case BLEND_MUL:
    {
        // ------------------------------
        glTexEnvf(	GL_TEXTURE_ENV, combiner,	GL_MODULATE);
        glTexEnvf(	GL_TEXTURE_ENV, source0,	GL_PREVIOUS_ARB);
        glTexEnvf(	GL_TEXTURE_ENV, op0,		blend_operand_prev);
        glTexEnvf(	GL_TEXTURE_ENV, source1,	GL_TEXTURE );
        if (using_alpha)
            glTexEnvf(	GL_TEXTURE_ENV, op1,		alphaOp);
        else
            glTexEnvf(	GL_TEXTURE_ENV, op1,		blend_operand);
    }
    break;
    case BLEND_ADD:
    {
        // ------------------------------
        glTexEnvf(	GL_TEXTURE_ENV, combiner,	GL_ADD_SIGNED_ARB);
        glTexEnvf(	GL_TEXTURE_ENV, source0,	GL_PREVIOUS_ARB );
        glTexEnvf(	GL_TEXTURE_ENV, op0,		blend_operand_prev );
        glTexEnvf(	GL_TEXTURE_ENV, source1,	GL_TEXTURE );
        if (using_alpha)
            glTexEnvf(	GL_TEXTURE_ENV, op1,		alphaOp);
        else
            glTexEnvf(	GL_TEXTURE_ENV, op1,		blend_operand);
    }
    break;
    case BLEND_SUB:
    {
        // ------------------------------
        glTexEnvf(	GL_TEXTURE_ENV, combiner,	GL_SUBTRACT_ARB);
        glTexEnvf(	GL_TEXTURE_ENV, source0,	GL_PREVIOUS_ARB );
        glTexEnvf(	GL_TEXTURE_ENV, op0,		blend_operand_prev );
        glTexEnvf(	GL_TEXTURE_ENV, source1,	GL_TEXTURE );
        glTexEnvf(	GL_TEXTURE_ENV, op1,		blend_operand);
    }
    break;
    case BLEND_SCR:
    {
        // ------------------------------
        glTexEnvf(	GL_TEXTURE_ENV, combiner,	GL_ADD);
        glTexEnvf(	GL_TEXTURE_ENV, source0,	GL_PREVIOUS_ARB );
        glTexEnvf(	GL_TEXTURE_ENV, op0,		blend_operand_prev );
        glTexEnvf(	GL_TEXTURE_ENV, source1,	GL_TEXTURE );
        if (using_alpha)
            glTexEnvf(	GL_TEXTURE_ENV, op1,		alphaOp);
        else
            glTexEnvf(	GL_TEXTURE_ENV, op1,		blend_operand);
    }
    break;
    }
    glTexEnvf(	GL_TEXTURE_ENV, GL_RGB_SCALE_ARB,	1.0);

    glEndList();
}
示例#18
0
void Floor::render() {
   GLfloat floor_amb[4] = {0.1f, 0.1f, 0.1f, 1.0f};
   GLfloat floor_dif[4] = {0.5f, 0.5f, 0.5f, 1.0f};
   GLfloat floor_spe[4] = {0.2f, 0.2f, 0.2f, 1.0f};
   GLfloat floor_shi = 0.5f;
   GLfloat floor_emi[4] = {0.0f, 0.0f, 0.0f, 1.0f};

   glMaterialfv(GL_FRONT, GL_AMBIENT, floor_amb);
   glMaterialfv(GL_FRONT, GL_DIFFUSE, floor_dif);
   glMaterialfv(GL_FRONT, GL_SPECULAR, floor_spe);
   glMaterialf(GL_FRONT, GL_SHININESS, floor_shi);
   glMaterialfv(GL_FRONT, GL_EMISSION, floor_emi);

   glPushMatrix();
   glScalef(gfxScaleWidth + cRenderObjs::GFX_FLOOR_QUEUE_SCALE_WIDTH,
            0.1f, 2.0f);
   glCallList(cRenderObjs::OBJ_CUBE);
   glPopMatrix();

   /* Render Arrow */
   {
      glPushMatrix();
      glTranslatef(-gfxScaleWidth + 0.8f, 1.1f, 0.2f);
      glScalef(0.25f, 0.25f, 0.25f);

      if(signalingUp)   {
         GLfloat arrow_dif[4] = {0.9f, 0.0f, 0.0f, 1.0f};
         glMaterialfv(GL_FRONT, GL_DIFFUSE, arrow_dif);
      }

      else  {
         GLfloat arrow_dif[4] = {0.1f, 0.1f, 0.1f, 1.0f};
         glMaterialfv(GL_FRONT, GL_DIFFUSE, arrow_dif);
      }

      glBegin(GL_TRIANGLES);
      glNormal3f(0.0, 1.0f, 1.0f);
      glVertex3f(1.0,  0.0,  0.0);
      glVertex3f( -1.0,  0.0,  0.0);
      glVertex3f( 0.0, 1.73f,  0.0);
      glEnd();
      glPopMatrix();

      glPushMatrix();
      glTranslatef(-gfxScaleWidth+0.8, 0.9f, 0.2f);
      glScalef(0.25f, 0.25f, 0.25f);

      if(signalingDown) {
         GLfloat arrow_dif[4] = {0.0f, 0.9f, 0.0f, 1.0f};
         glMaterialfv(GL_FRONT, GL_DIFFUSE, arrow_dif);
      }

      else  {
         GLfloat arrow_dif[4] = {0.1f, 0.1f, 0.1f, 1.0f};
         glMaterialfv(GL_FRONT, GL_DIFFUSE, arrow_dif);
      }

      glBegin(GL_TRIANGLES);
      glNormal3f(0.0, 1.0f, 1.0f);
      glVertex3f( -1.0,  0.0,  0.0);
      glVertex3f(1.0,  0.0,  0.0);
      glVertex3f( 0.0, -1.73f,  0.0);
      glEnd();
      glPopMatrix();
   }

   glPushMatrix();
   glTranslatef(-gfxScaleWidth-0.5f, 1.0f, 0.f);
   cRenderObjs::renderOccupants(numPeopleContained(), 50);
   glPopMatrix();
}
static void
snowglobePaintInside (CompScreen *s,
                      const ScreenPaintAttrib *sAttrib,
                      const CompTransform     *transform,
                      CompOutput              *output,
                      int                     size)
{
    SNOWGLOBE_SCREEN (s);
    CUBE_SCREEN (s);

    int i;

    as->waterHeight = 50000;

    if (as->hsize!=s->hsize) updateSnowglobe (s);


    static const float mat_shininess[] = { 60.0 };
    static const float mat_specular[] = { 0.8, 0.8, 0.8, 1.0 };
    static const float mat_diffuse[] = { 0.46, 0.66, 0.795, 1.0 };
    static const float mat_ambient[] = { 0.1, 0.1, 0.3, 1.0 };
    static const float lmodel_ambient[] = { 1.0, 1.0, 1.0, 1.0 };
    static const float lmodel_localviewer[] = { 0.0 };

    ScreenPaintAttrib sA = *sAttrib;
    CompTransform mT = *transform;

    if (snowglobeGetShowWater(s))
        updateHeight(as->water);

    sA.yRotate += cs->invert * (360.0f / size) *
                  (cs->xRotations - (s->x* cs->nOutput));

    (*s->applyScreenTransform)(s, &sA, output, &mT);

    glPushMatrix();

    glLoadMatrixf(mT.m);

    glTranslatef(cs->outputXOffset, -cs->outputYOffset, 0.0f);

    glScalef(cs->outputXScale, cs->outputYScale, 1.0f);

    Bool enabledCull = FALSE;

    glPushAttrib(GL_COLOR_BUFFER_BIT | GL_TEXTURE_BIT | GL_LIGHTING_BIT);

    glEnable(GL_BLEND);

    if (glIsEnabled(GL_CULL_FACE))
    {
        enabledCull = TRUE;
    }

    int cull;

    glGetIntegerv(GL_CULL_FACE_MODE, &cull);
    glEnable(GL_CULL_FACE);

    glCullFace(~cull & (GL_FRONT | GL_BACK));

    if (snowglobeGetShowWater(s))
    {
        glColor4usv(snowglobeGetWaterColor(s));
        drawWater(as->water, TRUE, FALSE);
    }
    glCullFace(cull);

    if (snowglobeGetShowGround(s))
    {
        glColor4f(0.8, 0.8, 0.8, 1.0);
        drawGround(NULL, as->ground);

    }

    glPushMatrix();

    glColor4usv(defaultColor);

    glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, mat_shininess);
    glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, mat_specular);
    glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, mat_diffuse);
    glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, mat_ambient);
    glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient);
    glLightModelfv(GL_LIGHT_MODEL_LOCAL_VIEWER, lmodel_localviewer);

    glEnable(GL_NORMALIZE);
    glEnable(GL_LIGHTING);
    glEnable(GL_LIGHT1);
    glEnable(GL_LIGHT0);

    glEnable(GL_COLOR_MATERIAL);

    glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

    for (i = 0; i < as->numSnowflakes; i++)
    {
        glPushMatrix();
        SnowflakeTransform(&(as->snow[i]));

        float scale = 0.01*as->snow[i].size;
        glScalef(scale, scale, scale);

        initDrawSnowflake();
        glCallList(as->snowflakeDisplayList);
        finDrawSnowflake();
        glPopMatrix();
    }

    if (snowglobeGetShowSnowman(s))
    {
        glPushMatrix();

        float bottom = -0.5;
        if (snowglobeGetShowGround(s))
            bottom = getHeight(as->ground, 0, 0);
        glTranslatef(0, bottom, 0);

        float scale = 0.4*snowglobeGetSnowmanSize(s)*(0.5-bottom);
        glScalef(scale, scale, scale);

        glColor4f(1.0, 1.0, 1.0, 1.0);

        DrawSnowman(0);
        glPopMatrix();
    }

    glPopMatrix();

    if (snowglobeGetShowWater(s))
    {
        glEnable(GL_CULL_FACE);
        glColor4usv(snowglobeGetWaterColor(s));
        drawWater(as->water, snowglobeGetShowWater(s), 0);
    }

    if (snowglobeGetShowGround(s))
    {
        glColor4f(0.8, 0.8, 0.8, 1.0);
        drawBottomGround(s->hsize * cs->nOutput, cs->distance, -0.4999);
    }

    glDisable(GL_LIGHT1);
    glDisable(GL_NORMALIZE);

    if (!s->lighting)
        glDisable(GL_LIGHTING);

    glDisable(GL_DEPTH_TEST);

    if (enabledCull)
        glDisable(GL_CULL_FACE);

    glPopMatrix();

    glPopAttrib();

    as->damage = TRUE;

    UNWRAP (as, cs, paintInside);
    (*cs->paintInside)(s, sAttrib, transform, output, size);
    WRAP (as, cs, paintInside, snowglobePaintInside);
}
void GLWidget::draw()
{
    QPainter p(this); // used for text overlay

    // save the GL state set for QPainter
    p.beginNativePainting();
    saveGLState();

    // render the 'bubbles.svg' file into our pbuffer
    QPainter pbuffer_painter(pbuffer);
    svg_renderer->render(&pbuffer_painter);
    pbuffer_painter.end();
    glFlush();

    // rendering directly to a texture is not supported on X11 and
    // some Windows implementations, unfortunately
    if (!hasDynamicTextureUpdate)
        pbuffer->updateDynamicTexture(dynamicTexture);

    makeCurrent();
    // draw into the GL widget
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glFrustum(-1, 1, -1, 1, 10, 100);
    glTranslatef(0.0f, 0.0f, -15.0f);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    glViewport(0, 0, width(), height());

    glBindTexture(GL_TEXTURE_2D, dynamicTexture);
    glEnable(GL_TEXTURE_2D);
    glEnable(GL_MULTISAMPLE);
    glEnable(GL_CULL_FACE);
    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

    // draw background
    glPushMatrix();
    glScalef(1.7f, 1.7f, 1.7f);
    glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
    glCallList(tile_list);
    glPopMatrix();

    const int w = logo.width();
    const int h = logo.height();

    glRotatef(rot_x, 1.0f, 0.0f, 0.0f);
    glRotatef(rot_y, 0.0f, 1.0f, 0.0f);
    glRotatef(rot_z, 0.0f, 0.0f, 1.0f);
    glScalef(scale/w, scale/w, scale/w);

    glDepthFunc(GL_LESS);
    glEnable(GL_DEPTH_TEST);

    // draw the Qt icon
    glTranslatef(-w+1, -h+1, 0.0f);
    for (int y=h-1; y>=0; --y) {
        uint *p = (uint*) logo.scanLine(y);
        uint *end = p + w;
        int  x = 0;
        while (p < end) {
            glColor4ub(qRed(*p), qGreen(*p), qBlue(*p), uchar(qAlpha(*p)*.9));
            glTranslatef(0.0f, 0.0f, wave[y*w+x]);
            if (qAlpha(*p) > 128)
                glCallList(tile_list);
            glTranslatef(0.0f, 0.0f, -wave[y*w+x]);
            glTranslatef(2.0f, 0.0f, 0.0f);
            ++x;
            ++p;
        }
        glTranslatef(-w*2.0f, 2.0f, 0.0f);
    }

    // restore the GL state that QPainter expects
    restoreGLState();
    p.endNativePainting();

    // draw the overlayed text using QPainter
    p.setPen(QColor(197, 197, 197, 157));
    p.setBrush(QColor(197, 197, 197, 127));
    p.drawRect(QRect(0, 0, width(), 50));
    p.setPen(Qt::black);
    p.setBrush(Qt::NoBrush);
    const QString str1(tr("A simple OpenGL pbuffer example."));
    const QString str2(tr("Use the mouse wheel to zoom, press buttons and move mouse to rotate, double-click to flip."));
    QFontMetrics fm(p.font());
    p.drawText(width()/2 - fm.width(str1)/2, 20, str1);
    p.drawText(width()/2 - fm.width(str2)/2, 20 + fm.lineSpacing(), str2);
}
static void Init(void)
{
   fprintf(stderr, "GL_RENDERER   = %s\n", (char *) glGetString(GL_RENDERER));
   fprintf(stderr, "GL_VERSION    = %s\n", (char *) glGetString(GL_VERSION));
   fprintf(stderr, "GL_VENDOR     = %s\n", (char *) glGetString(GL_VENDOR));
   fflush(stderr);

   glClearColor(0.0, 0.0, 1.0, 0.0);

   /* First list will disrupt state which might potentially be
    * short-circuited in calling list:
    */
   first_list = glGenLists(1);
   glNewList(first_list, GL_COMPILE); 
   glShadeModel( GL_SMOOTH );
   glEndList();


   /* List that looks like it might have redundant state:
    */
   list = glGenLists(1);
   glNewList(list, GL_COMPILE); 

   glBegin(GL_TRIANGLES);
   glColor3f(0,0,.7);
   glVertex3f( 0.9, -0.9, -30.0);
   glColor3f(.8,0,0);
   glVertex3f( 0.9,  0.9, -30.0);
   glColor3f(0,.9,0);
   glVertex3f(-0.9,  0.0, -30.0);
   glEnd();

   glShadeModel( GL_FLAT );
   glBegin(GL_TRIANGLES);
   glColor3f(0,0,.7);
   glVertex3f( -0.9,  0.9, -30.0);
   glColor3f(0,.9,0);
   glVertex3f( -0.9, -0.9, -30.0);
   glColor3f(.8,0,0);
   glVertex3f(  0.9,  0.0, -30.0);
   glEnd();

   glCallList( first_list );

   /* Do a quick begin/end to ensure we are not inside a dangling
    * primitive from the called list:
    */
   glBegin( GL_POINTS );
   glEnd();

   /* This statechange is NOT redundant:
    */
   glShadeModel( GL_FLAT );
   glBegin(GL_TRIANGLES);
   glColor3f(1,0,0);
   glVertex3f( -0.5,  0.5, -30.0);
   glColor3f(0,1,0);
   glVertex3f( -0.5, -0.5, -30.0);
   glColor3f(0,0,1);
   glVertex3f(  0.5,  0.0, -30.0);
   glEnd();

   glEndList();
}
示例#22
0
void
extrudeSolidFromPolygon(GLfloat data[][2], unsigned int dataSize,
  GLdouble thickness, GLuint side, GLuint edge, GLuint whole)
{
  static GLUtriangulatorObj *tobj = NULL;
  GLdouble vertex[3], dx, dy, len;
  int i;
  int count = dataSize / (int) (2 * sizeof(GLfloat));

  if (tobj == NULL) {
    tobj = gluNewTess();  /* create and initialize a GLU
                             polygontesselation object */
    gluTessCallback(tobj, GLU_BEGIN, glBegin);
    gluTessCallback(tobj, GLU_VERTEX, glVertex2fv);  /* semi-tricky 

                                                      */
    gluTessCallback(tobj, GLU_END, glEnd);
  }
  glNewList(side, GL_COMPILE);
  glShadeModel(GL_SMOOTH);  /* smooth minimizes seeing
                               tessellation */
  gluBeginPolygon(tobj);
  for (i = 0; i < count; i++) {
    vertex[0] = data[i][0];
    vertex[1] = data[i][1];
    vertex[2] = 0;
    gluTessVertex(tobj, vertex, data[i]);
  }
  gluEndPolygon(tobj);
  glEndList();
  glNewList(edge, GL_COMPILE);
  glShadeModel(GL_FLAT);  /* flat shade keeps angular hands
                             from being "smoothed" */
  glBegin(GL_QUAD_STRIP);
  for (i = 0; i <= count; i++) {
    /* mod function handles closing the edge */
    glVertex3f(data[i % count][0], data[i % count][1], 0.0);
    glVertex3f(data[i % count][0], data[i % count][1], thickness);

    /* Calculate a unit normal by dividing by Euclidean
       distance. We could be lazy and use
       glEnable(GL_NORMALIZE) so we could pass in arbitrary
       normals for a very slight performance hit. */

    dx = data[(i + 1) % count][1] - data[i % count][1];
    dy = data[i % count][0] - data[(i + 1) % count][0];
    len = sqrt(dx * dx + dy * dy);
    glNormal3f(dx / len, dy / len, 0.0);
  }
  glEnd();
  glEndList();
  glNewList(whole, GL_COMPILE);
  glFrontFace(GL_CW);
  glCallList(edge);
  glNormal3f(0.0, 0.0, -1.0);  /* constant normal for side */
  glCallList(side);
  glPushMatrix();
  glTranslatef(0.0, 0.0, thickness);
  glFrontFace(GL_CCW);
  glNormal3f(0.0, 0.0, 1.0);  /* opposite normal for other side */
  glCallList(side);
  glPopMatrix();
  glEndList();
}
// Draw the track in the panning mode.
void cGrTrackMap::drawTrackPanning(
	int Winx,
	int Winy,
	int Winw,
	int Winh,
	tCarElt *currentCar,
	tSituation *s
)
{
	float x1, y1, x2, y2;
	float tracksize = MAX(track_width, track_height);
	float radius = MIN(500.0, tracksize/2.0);
	x1 = (currentCar->_pos_X - radius - track_min_x)/tracksize;
	y1 = (currentCar->_pos_Y - radius - track_min_y)/tracksize;
	x2 = (currentCar->_pos_X + radius - track_min_x)/tracksize;
	y2 = (currentCar->_pos_Y + radius - track_min_y)/tracksize;

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

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

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

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

	glColor4fv(currentCarColor);
	if (cardot != 0) {
		glMatrixMode(GL_MODELVIEW);
		glPushMatrix();
		glTranslatef(x + map_size/2.0, y + map_size/2.0, 0.0);
		float factor = tracksize/(2.0*radius);
		glScalef(factor, factor, 1.0);
		glCallList(cardot);
		glPopMatrix();
	}
}
示例#24
0
文件: DrawWater.cpp 项目: arlukin/dev
void CDrawWater::Draw()
{
	if(displist==0){
		displist=glGenLists(1);
		glNewList(displist, GL_COMPILE);

		glDisable(GL_ALPHA_TEST);
		glDepthMask(0);
		glDisable(GL_TEXTURE_2D);
		glColor3f(0.05f,0.05f,0.3f);
		glBegin(GL_QUADS);
			float xsize=(g.mapx-1)*SQUARE_SIZE;
			float ysize=(g.mapy-1)*SQUARE_SIZE;
			glVertex3f(0,g.seaLevel,0);
			glVertex3f(0,-5,0);
			glVertex3f(xsize,-5,0);
			glVertex3f(xsize,g.seaLevel,0);
			glVertex3f(0,g.seaLevel,0);
			glVertex3f(0,-5,0);
			glVertex3f(0,-5,ysize);
			glVertex3f(0,g.seaLevel,ysize);
			glVertex3f(xsize,g.seaLevel,ysize);
			glVertex3f(xsize,-5,ysize);
			glVertex3f(xsize,-5,0);
			glVertex3f(xsize,g.seaLevel,0);
			glVertex3f(xsize,g.seaLevel,ysize);
			glVertex3f(xsize,-5,ysize);
			glVertex3f(0,-5,ysize);
			glVertex3f(0,g.seaLevel,ysize);

			glColor3f(0.0f,0.0f,0.0f);
			for(int y=0;y<3;++y)
				for(int x=0;x<3;++x)
					if(x!=1 || y!=1){
						glVertex3f(-xsize*1.04+x*xsize*1.02,0,-ysize*1.04+y*ysize*1.02);
						glVertex3f(-xsize*1.04+x*xsize*1.02,0,y*ysize*1.02);
						glVertex3f(x*xsize*1.02,0,y*ysize*1.02);
						glVertex3f(x*xsize*1.02,0,-ysize*1.04+y*ysize*1.02);
					}
	
					glEnd();

		glColor4f(0.6f,0.6f,0.6f,0.4f);
		glEnable(GL_TEXTURE_2D);
		glBindTexture(GL_TEXTURE_2D, texture);
		glBegin(GL_QUADS);
/*		for(int y=0;y<(g.mapy-1)/32;y++){
			for(int x=0;x<(g.mapx-1)/32;x++){
				bool draw=false;
				for(int y2=y*32;y2<=(y+1)*32;y2++)
					for(int x2=x*32;x2<=(x+1)*32;x2++)
						if(readmap->map[y2*(g.mapx)+x2]<=g.seaLevel)
							draw=true;
				if(draw){
					glTexCoord2f(x*0.5f,y*0.5f);
					glVertex3f(x*256,g.seaLevel,y*256);
					glTexCoord2f(x*0.5f,(y+1)*0.5f);
					glVertex3f(x*256,g.seaLevel,(y+1)*256);
					glTexCoord2f((x+1)*0.5f,(y+1)*0.5f);
					glVertex3f((x+1)*256,g.seaLevel,(y+1)*256);
					glTexCoord2f((x+1)*0.5f,y*0.5f);
					glVertex3f((x+1)*256,g.seaLevel,y*256);
				}
			}
		}
*/
		if(g.seaLevel>1){
			glTexCoord2f(0,0);
			glVertex3f(0,g.seaLevel,0);
			glTexCoord2f(0,(g.mapy-1)/64);
			glVertex3f(0,g.seaLevel,(g.mapy-1)*SQUARE_SIZE);
			glTexCoord2f((g.mapx-1)/64,(g.mapy-1)/64);
			glVertex3f((g.mapx-1)*SQUARE_SIZE,g.seaLevel,(g.mapy-1)*SQUARE_SIZE);
			glTexCoord2f((g.mapx-1)/64,0);
			glVertex3f((g.mapx-1)*SQUARE_SIZE,g.seaLevel,0);
		}
		glEnd();

		glDisable(GL_TEXTURE_2D);
		glDepthMask(1);
		glEndList();
	}
	glCallList(displist);
}
示例#25
0
    void GridRenderEngine::paintGL()
    {
	glPushMatrix();
        glCallList(mListName);
	glPopMatrix();
    }
// recursive subdivision is extra credit....
// subdivide(u0, d1, maxLineLength)
// umid = (u0 + u1) / 2
// x0 = f(u0)  x1 = f(u1)
// if  | x1 - x0 | > maxLineLength
//		subdivide (u0, umid, maxLineLength)
//		subdivide (umid, u1, maxLineLength)
// else drawLine(x0, x1)
//
// can subdivide based on curvature instead (2nd derivative of f)
void renderSpline() {

	glColor3f(1.0, 1.0, 1.0);
	glCallList(theSpline);
	glFlush();
}
示例#27
0
void RedrawFunc( void )
{
	// all time in milliseconds
	int elapsedTime = glutGet( GLUT_ELAPSED_TIME );
	static int prevElapsedTime = 0;
	static float timeAccum = 0.0;
	int deltaTime = elapsedTime - prevElapsedTime;

	vec3_t lightPosition = { 0.0f, 0.0f, 60.0f };
	
	prevElapsedTime = elapsedTime;
	
	glClearColor( 0.0f, 0.0f, 0.0f, 1.0f );
	glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

	glDepthFunc( GL_LEQUAL );
	glEnable( GL_DEPTH_TEST );

	if( drawLighting )
	{
		SetLight( lightPosition );
	}
	
	if( drawBaseTexture )
	{
		glEnable( GL_TEXTURE_2D );
		glBindTexture( GL_TEXTURE_2D, BASE_TEXTURE );
//		glBindTexture( GL_TEXTURE_2D, NORMAL_TEXTURE );
	}
	else
	{
		glDisable( GL_TEXTURE_2D );
	}
	
	if( drawWireFrame )
	{
		glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
		glCallList( WIRE_LIST );
	}
	else
	{
		glCallList( QUAD_LIST );
	}

	glDisable( GL_TEXTURE_2D );
	glDisable( GL_LIGHTING );

	glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);

	if( drawNormals )
	{
		glColor3f( 0.0f, 1.0f, 0.0f );
		glCallList( NORMAL_LIST );
		glColor3f( 1.0f, 1.0f, 1.0f );
	}

	DrawLightSource( lightPosition, 1.0f, 1.0f, 1.0f );
	
	DrawStatus();
	
	glutSwapBuffers();
	glFinish();
}
示例#28
0
ENTRYPOINT void
draw_ball (ModeInfo *mi)
{
   blinkboxstruct *bp = &blinkbox[MI_SCREEN(mi)];

   Display *dpy = MI_DISPLAY(mi);
   Window window = MI_WINDOW(mi);
   int i = 0;

   if (! bp->glx_context)
     return;
   mi->polygon_count = 0;
   glXMakeCurrent(MI_DISPLAY(mi), MI_WINDOW(mi), *(bp->glx_context));

   glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

   hit_top_bottom(bp);
   hit_front_back(bp);
   hit_side(bp);

   glRotated(0.25,0,0,1);
   glRotated(0.25,0,1,0);
   glRotated(0.25,1,0,0);


   glPushMatrix();
   glScalef(0.5,0.5,0.5);

   glColor3f(1,1,1);
   glPushMatrix();

   if (!do_blur || MI_IS_WIREFRAME(mi)) {
     glTranslatef(bp->ball.x += bp->mo.x,
                  bp->ball.y += bp->mo.y,
                  bp->ball.z += bp->mo.z);

     glScalef(2,2,2);
     glCallList(bp->ballList);
     mi->polygon_count += SPHERE_SLICES*SPHERE_STACKS;

   } else {

#    define blur_detail 24.0
     float ball_alpha = 1 / blur_detail;

     glBlendFunc(GL_SRC_ALPHA,GL_ONE);
     glTranslatef(bp->ball.x, bp->ball.y, bp->ball.z);
   
     for (i = 0; i < blur_detail; ++i) {
       glTranslatef(bp->mo.x / blur_detail,
                    bp->mo.y / blur_detail,
                    bp->mo.z / blur_detail);

       /* comment the following line for quick but boring linear blur */
       ball_alpha = sin((M_PI / blur_detail) * i) / blur_detail;
     
       glColor4f(1, 1, 1, ball_alpha);

       glScalef(2, 2, 2);
       glCallList(bp->ballList);
       mi->polygon_count += SPHERE_SLICES*SPHERE_STACKS;
       glScalef(.5, .5, .5);
     }
     i = 0;
   
     bp->ball.x += bp->mo.x;
     bp->ball.y += bp->mo.y;
     bp->ball.z += bp->mo.z;
   }
   
   glPopMatrix();

   while(i < 6){
    switch(i){
      case 0:{
               bp->sp = &bp->lside;
               bp->bpos.x = bp->lside.pos.z*-1;
               bp->bpos.y = bp->lside.pos.y;
               bp->bpos.z = bbox.bottom.x - bp->bscale.d;
               if (bp->sp->hit)
                CheckBoxPos(bp, bbox.bottom.z,bbox.top.z,bbox.bottom.y,bbox.top.y);
               break;
             }
      case 1:{
               bp->sp = &bp->rside;
               bp->bpos.x = bp->rside.pos.z*-1;
               bp->bpos.y = bp->rside.pos.y;
               bp->bpos.z = bbox.top.x + bp->bscale.d;
               if (bp->sp->hit)
                CheckBoxPos(bp, bbox.bottom.z,bbox.top.z,bbox.bottom.y,bbox.top.y);
               break;
             }
      case 2:{
               bp->sp = &bp->tside;
               bp->bpos.x = bp->tside.pos.x;
               bp->bpos.y = bp->tside.pos.z;
               bp->bpos.z = bbox.bottom.y - bp->bscale.d;
               if (bp->sp->hit)
                CheckBoxPos(bp, bbox.bottom.x,bbox.top.x,bbox.bottom.z,bbox.top.z);
               break;
             }
      case 3:{
               bp->sp = &bp->bside;
               bp->bpos.x = bp->bside.pos.x;
               bp->bpos.y = bp->bside.pos.z;
               bp->bpos.z = bbox.top.y + bp->bscale.d;
               if (bp->sp->hit)
                CheckBoxPos(bp, bbox.bottom.x,bbox.top.x,bbox.bottom.z,bbox.top.z);
               break;
             }
      case 4:{
               bp->sp = &bp->fside;
               bp->bpos.x = bp->fside.pos.y;
               bp->bpos.y = bp->fside.pos.x*-1;
               bp->bpos.z = bbox.top.z + bp->bscale.d;
               if (bp->sp->hit)
                CheckBoxPos(bp, bbox.bottom.y,bbox.top.y,bbox.bottom.x,bbox.top.x);
               break;
             }
      case 5:{
               bp->sp = &bp->aside;
               bp->bpos.x = bp->aside.pos.y;
               bp->bpos.y = bp->aside.pos.x*-1;
               bp->bpos.z = bbox.bottom.z + bp->bscale.d;
               if (bp->sp->hit)
                CheckBoxPos(bp, bbox.bottom.y,bbox.top.y,bbox.bottom.x,bbox.top.x);
               break;
             }
    }
    if(bp->sp->hit){
      if(do_fade){
        glColor4f(bp->sp->color[0],bp->sp->color[1],bp->sp->color[2],1-(ALPHA_AMT * bp->sp->alpha_count));
      }else{
        glColor3fv(bp->sp->color);
      }
      glBlendFunc(GL_SRC_ALPHA,GL_ONE);
      glPushMatrix();
      glRotatef(bp->sp->rot[0],bp->sp->rot[1],bp->sp->rot[2],bp->sp->rot[3]);
      glTranslatef(bp->bpos.x,bp->bpos.y,bp->bpos.z);
      if (do_dissolve) {
         glScalef(bp->bscale.wh-(bp->des_amt*bp->sp->des_count),bp->bscale.wh-(bp->des_amt*bp->sp->des_count),bp->bscale.d);
      }else{
        glScalef(bp->bscale.wh,bp->bscale.wh,bp->bscale.d);
      }
      glCallList(bp->boxList);
      mi->polygon_count += 6;
      glPopMatrix();
      bp->sp->counter--;
      bp->sp->des_count++;
      bp->sp->alpha_count++;
      if(!bp->sp->counter)
      {
        bp->sp->hit = 0;
      }
    }
    i++;
  }


   glPopMatrix();
  if (mi->fps_p) do_fps (mi);
   glFinish();
   glXSwapBuffers(dpy, window);

}
示例#29
0
/*******************************************************************************
 Draws a 3D cursor for the haptic device using the current local transform,
 the workspace to world transform and the screen coordinate scale.
*******************************************************************************/
void drawCursor()
{
    static const double kCursorRadius = 0.25;
    static const double kCursorHeight = 1.5;
    static const int kCursorTess = 15;

    HLdouble proxyxform[16];
    double proxyPos[3];

    hlGetDoublev(HL_PROXY_POSITION, proxyPos);
    GLUquadricObj *qobj = 0;
    glPushAttrib(GL_CURRENT_BIT | GL_ENABLE_BIT | GL_LIGHTING_BIT);
    glPushMatrix();

    if (!gCursorDisplayList)
    {
        gCursorDisplayList = glGenLists(1);
        glNewList(gCursorDisplayList, GL_COMPILE);
        qobj = gluNewQuadric();

        gluCylinder(qobj, 0.0, kCursorRadius, kCursorHeight,
            kCursorTess, kCursorTess);

        glTranslated(0.0, 0.0, kCursorHeight);

        gluCylinder(qobj, kCursorRadius, 0.0, kCursorHeight / 5.0,
            kCursorTess, kCursorTess);

        gluDeleteQuadric(qobj);
        glEndList();
    }

// Get the proxy transform in world coordinates.
    hlGetDoublev(HL_PROXY_TRANSFORM, proxyxform);

//If entered hole, then freeze the rotations.
    if (touchedHole)
    {
        proxyxform[0] = 1.0;
        proxyxform[1] = 0.0;
        proxyxform[2] = 0.0;
        proxyxform[3] = 0.0;
        proxyxform[4] = 0.0;
        proxyxform[5] = 1.0;
        proxyxform[6] = 0.0;
        proxyxform[7] = 0.0;
        proxyxform[8] = 0.0;
        proxyxform[9] = 0.0;
        proxyxform[10] = 1.0;
        proxyxform[11] = 0.0;
    }

//Get the depth of Penetration from HLAPI.
    hlGetDoublev(HL_DEPTH_OF_PENETRATION, &probeDop);
    glMultMatrixd(proxyxform);

    if (touchedHole)
        cursorToToolTranslation = 0.35;
    else
        cursorToToolTranslation = 0.25;

    glTranslatef(0.0,0.0,cursorToToolTranslation);

    if (touchedHole && force[2]>=0.0)
        glTranslatef(0.0,0.0,-1* probeDop);

    glCallList(toolObjList);
    glPopMatrix();
    glPopAttrib();
}
示例#30
0
ENTRYPOINT void
draw_knot (ModeInfo *mi)
{
  knot_configuration *bp = &bps[MI_SCREEN(mi)];
  Display *dpy = MI_DISPLAY(mi);
  Window window = MI_WINDOW(mi);

  GLfloat bcolor[4] = {0.0, 0.0, 0.0, 1.0};
  GLfloat bspec[4]  = {1.0, 1.0, 1.0, 1.0};
  GLfloat bshiny    = 128.0;

  if (!bp->glx_context)
    return;

  glXMakeCurrent(MI_DISPLAY(mi), MI_WINDOW(mi), *(bp->glx_context));

  if (bp->mode == 0)
    {
      if (bp->draw_tick++ > 10)
        {
          time_t now = time((time_t *) 0);
          if (bp->last_time == 0) bp->last_time = now;
          bp->draw_tick = 0;
          if (!bp->button_down_p &&
              now - bp->last_time >= duration)
            {
              bp->mode = 1;    /* go out */
              bp->mode_tick = 10 * speed;
              bp->last_time = now;
            }
        }
    }
  else if (bp->mode == 1)   /* out */
    {
      if (--bp->mode_tick <= 0)
        {
          new_knot (mi);
          bp->mode_tick = 10 * speed;
          bp->mode = 2;  /* go in */
        }
    }
  else if (bp->mode == 2)   /* in */
    {
      if (--bp->mode_tick <= 0)
        bp->mode = 0;  /* normal */
    }
  else
    abort();

  glShadeModel(GL_SMOOTH);

  glEnable(GL_DEPTH_TEST);
  glEnable(GL_NORMALIZE);
  glEnable(GL_CULL_FACE);

  if (bp->clear_p)
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

  glPushMatrix ();

  {
    double x, y, z;
    get_position (bp->rot, &x, &y, &z, !bp->button_down_p);
    glTranslatef((x - 0.5) * 8,
                 (y - 0.5) * 8,
                 (z - 0.5) * 15);

    gltrackball_rotate (bp->trackball);

    get_rotation (bp->rot, &x, &y, &z, !bp->button_down_p);

    glRotatef (x * 360, 1.0, 0.0, 0.0);
    glRotatef (y * 360, 0.0, 1.0, 0.0);
    glRotatef (z * 360, 0.0, 0.0, 1.0);
  }

  bcolor[0] = bp->colors[bp->ccolor].red   / 65536.0;
  bcolor[1] = bp->colors[bp->ccolor].green / 65536.0;
  bcolor[2] = bp->colors[bp->ccolor].blue  / 65536.0;
  bp->ccolor++;
  if (bp->ccolor >= bp->ncolors) bp->ccolor = 0;

  glMaterialfv (GL_FRONT, GL_SPECULAR,            bspec);
  glMateriali  (GL_FRONT, GL_SHININESS,           bshiny);
  glMaterialfv (GL_FRONT, GL_AMBIENT_AND_DIFFUSE, bcolor);

  glScalef(0.25, 0.25, 0.25);

  if (bp->mode != 0)
    {
      GLfloat s = (bp->mode == 1
                   ? bp->mode_tick / (10 * speed)
                   : ((10 * speed) - bp->mode_tick + 1) / (10 * speed));
      glScalef (s, s, s);
    }

  glCallList (bp->knot_list);

  glPopMatrix ();

  if (mi->fps_p) do_fps (mi);
  glFinish();

  glXSwapBuffers(dpy, window);
}