/*! Simple show text function
 */
void displayInfo(int x, int y)
{
  int len, i;
#ifdef WIN32
#ifdef OSG_WIN32_CL
  void *font = (void *) 2;
#else
  void *font = 2;
#endif
#else
#ifdef OSG_DEBUG_OLD_C_CASTS
  void *font = glutBitmap9By15;
#else
  void *font = GLUT_BITMAP_9_BY_15;
#endif
#endif

  char text[1024];
  sprintf(text,
          "FPS:        %12.1f\n"
          "Positions:  %12u\n"
          "Triangles:  %12u\n"
          "Geometries: %12u",
          1.0/frame_time,
          sum_positions,
          sum_triangles,
          sum_geometries);

  glPushAttrib(GL_ALL_ATTRIB_BITS);
  glDisable(GL_LIGHTING);
  glEnable(GL_COLOR_MATERIAL);
  glPushMatrix();
  glLoadIdentity();
  glMatrixMode(GL_PROJECTION);
  glPushMatrix();
  glLoadIdentity();
  gluOrtho2D(0,clientWindow->getWidth(),0,clientWindow->getHeight());
  glDisable(GL_DEPTH_TEST);  
  glEnable(GL_BLEND);
  glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);

  int x1=x-5;
  int x2=x1+24*9+10;
  int y1=y+14;
  int y2=y1-4*20;
  glBegin(GL_QUADS);
  glColor4f(.1f, .1f, .7f, .5f);
  glVertex2i(x1,y1);
  glVertex2i(x1,y2);
  glVertex2i(x2,y2);
  glVertex2i(x2,y1);
  glEnd();
  glBegin(GL_LINE_LOOP);
  glColor3f(1.0, 1.0, 0.0);
  glVertex2i(x1,y1);
  glVertex2i(x1,y2);
  glVertex2i(x2,y2);
  glVertex2i(x2,y1);
  glEnd();

  glColor3f(1.0, 1.0, 0.0);
  glRasterPos2f(x, y);
  len = int(strlen(text));
  for (i = 0; i < len; i++) {
      if(text[i] == '\n')
      {
          y-=20;
          glRasterPos2f(x, y);
      }
      else
          glutBitmapCharacter(font, text[i]);
  }
  glPopMatrix();
  glMatrixMode(GL_MODELVIEW);
  glPopMatrix();
  glPopAttrib();
}
void RAS_2DFilterManager::RenderFilters(RAS_ICanvas* canvas)
{
	bool need_depth=false;
	bool need_luminance=false;
	int num_filters = 0;

	int passindex;

	if (!isshadersupported)
		return;

	for (passindex =0; passindex<MAX_RENDER_PASS; passindex++)
	{
		if (m_filters[passindex] && m_enabled[passindex]) {
			num_filters ++;
			if (texflag[passindex] & 0x1)
				need_depth = true;
			if (texflag[passindex] & 0x2)
				need_luminance = true;
			if (need_depth && need_luminance)
				break;
		}
	}

	if (num_filters <= 0)
		return;

	const int *viewport = canvas->GetViewPort();
	RAS_Rect rect = canvas->GetWindowArea();
	int rect_width = rect.GetWidth()+1, rect_height = rect.GetHeight()+1;

	if (texturewidth != rect_width || textureheight != rect_height)
	{
		UpdateOffsetMatrix(canvas);
		UpdateCanvasTextureCoord(viewport);
		need_tex_update = true;
	}
	
	if (need_tex_update)
	{
		SetupTextures(need_depth, need_luminance);
		need_tex_update = false;
	}

	if (need_depth) {
		glActiveTextureARB(GL_TEXTURE1);
		glBindTexture(GL_TEXTURE_2D, texname[1]);
		glCopyTexImage2D(GL_TEXTURE_2D,0,GL_DEPTH_COMPONENT, rect.GetLeft(), rect.GetBottom(), rect_width, rect_height, 0);
	}
	
	if (need_luminance) {
		glActiveTextureARB(GL_TEXTURE2);
		glBindTexture(GL_TEXTURE_2D, texname[2]);
		glCopyTexImage2D(GL_TEXTURE_2D,0,GL_LUMINANCE16, rect.GetLeft(), rect.GetBottom(), rect_width, rect_height, 0);
	}

	// reverting to texunit 0, without this we get bug [#28462]
	glActiveTextureARB(GL_TEXTURE0);
	canvas->SetViewPort(0, 0, rect_width-1, rect_height-1);

	// We do this to make side-by-side stereo rendering work correctly with 2D filters. It would probably be nicer to just set the viewport,
	// but it can be easier for writing shaders to have the coordinates for the whole screen instead of just part of the screen. 
	RAS_Rect scissor_rect = canvas->GetDisplayArea();
	glScissor(scissor_rect.GetLeft() + viewport[0],
	          scissor_rect.GetBottom() + viewport[1],
	          scissor_rect.GetWidth() + 1,
	          scissor_rect.GetHeight() + 1);

	glDisable(GL_DEPTH_TEST);
	// in case the previous material was wire
	glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
	// if the last rendered face had alpha add it would messes with the color of the plane we apply 2DFilter to
	glDisable(GL_BLEND); 
	// fix for [#34523] alpha buffer is now available for all OSs
	glDisable(GL_ALPHA_TEST);

	glPushMatrix();		//GL_MODELVIEW
	glLoadIdentity();	// GL_MODELVIEW
	glMatrixMode(GL_TEXTURE);
	glLoadIdentity();
	glMatrixMode(GL_PROJECTION);
	glPushMatrix();
	glLoadIdentity();

	for (passindex =0; passindex<MAX_RENDER_PASS; passindex++)
	{
		if (m_filters[passindex] && m_enabled[passindex])
		{
			StartShaderProgram(passindex);

			glActiveTextureARB(GL_TEXTURE0);
			glBindTexture(GL_TEXTURE_2D, texname[0]);
			glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, rect.GetLeft(), rect.GetBottom(), rect_width, rect_height, 0); // Don't use texturewidth and textureheight in case we don't have NPOT support
			glClear(GL_COLOR_BUFFER_BIT);

			glBegin(GL_QUADS);
				glColor4f(1.f, 1.f, 1.f, 1.f);
				glTexCoord2f(1.0, 1.0);	glMultiTexCoord2fARB(GL_TEXTURE3_ARB, canvascoord[1], canvascoord[3]); glVertex2f(1,1);
				glTexCoord2f(0.0, 1.0);	glMultiTexCoord2fARB(GL_TEXTURE3_ARB, canvascoord[0], canvascoord[3]); glVertex2f(-1,1);
				glTexCoord2f(0.0, 0.0);	glMultiTexCoord2fARB(GL_TEXTURE3_ARB, canvascoord[0], canvascoord[2]); glVertex2f(-1,-1);
				glTexCoord2f(1.0, 0.0);	glMultiTexCoord2fARB(GL_TEXTURE3_ARB, canvascoord[1], canvascoord[2]); glVertex2f(1,-1);
			glEnd();
		}
	}

	glEnable(GL_DEPTH_TEST);
	//We can't pass the results of canvas->GetViewPort() directly because canvas->SetViewPort() does some extra math [#34517]
	canvas->SetViewPort(0, 0, viewport[2]-1, viewport[3]-1);
	EndShaderProgram();
	glPopMatrix();
	glMatrixMode(GL_MODELVIEW);
	glPopMatrix();
}
Exemple #3
0
void processNode(Object* object){

	//Transformacoes
	glPushMatrix();
	glMultMatrixf(object->m_object);

	//Material
	if(object->material->id == "null"){
		if(materials.empty())
			cout << "Erro! Não há materiais na stack!" << endl;
		else{
			Material* mat = materials.top();
			mat->setMaterial();
		}
	} else{
		object->material->setMaterial();
		materials.push(object->material);
	}
	
	if(object->type == "simple"){ //Desenhar os poligonos
		Simple* simple = (Simple*)object;
		
		//Texturas
		if(object->texture->id != "null")
			textures.push(object->texture);
		if((object->texture->id != "clear") && (textures.top()->id != "clear")){
			glEnable(GL_TEXTURE_2D);
			glBindTexture(GL_TEXTURE_2D, textures.top()->number);
		}
		
		//Triangulo
		if(simple->polygon->type == "triangle"){
			Triangle* triangle = (Triangle*)simple->polygon;
			float* n = newell(triangle);
			
			float length_A = sqrt((triangle->x2-triangle->x1)*(triangle->x2-triangle->x1) + (triangle->y2-triangle->y1)*(triangle->y2-triangle->y1) + (triangle->z2-triangle->z1)*(triangle->z2-triangle->z1));
			float length_B = sqrt((triangle->x3-triangle->x1)*(triangle->x3-triangle->x1) + (triangle->y3-triangle->y1)*(triangle->y3-triangle->y1) + (triangle->z3-triangle->z1)*(triangle->z3-triangle->z1));
			float length_N = sqrt(n[0]*n[0] + n[1]*n[1] + n[2]*n[2]);

			double height = length_N / length_A;

			double width = sqrt(length_B*length_B - height*height);
	
			glBegin(GL_POLYGON);
				glNormal3f(n[0],n[1],n[2]);
				glTexCoord2d(triangle->x1/textures.top()->length_s, triangle->y1/textures.top()->length_t); glVertex3d(triangle->x1, triangle->y1, triangle->z1);
				glTexCoord2d((triangle->x1 + length_A)/textures.top()->length_s, triangle->y1/textures.top()->length_t); glVertex3d(triangle->x2, triangle->y2, triangle->z2);
				glTexCoord2d((triangle->x1 + width)/textures.top()->length_s, (triangle->y1 + height)/textures.top()->length_t);glVertex3d(triangle->x3, triangle->y3, triangle->z3);
			glEnd();
		}
		//Rectangulo
		if(simple->polygon->type == "rectangle"){
			Rectangle* rect = (Rectangle*)simple->polygon;
			float s = mapText(rect->x1, rect->x2, textures.top()->length_s);
			float t = mapText(rect->y1, rect->y2, textures.top()->length_t);
			glBegin(GL_POLYGON);
				glNormal3d(0.0,0.0,1.0);
				glTexCoord2f(0.0,0.0);glVertex2d(rect->x1, rect->y1);
				glTexCoord2f(s  ,0.0);glVertex2d(rect->x2, rect->y1);
				glTexCoord2f(s  ,t  );glVertex2d(rect->x2, rect->y2);
				glTexCoord2f(0.0,t  );glVertex2d(rect->x1, rect->y2);
			glEnd();
		}

		if(simple->polygon->type == "cylinder"){
			Cylinder* cyl = (Cylinder*)simple->polygon;
			gluCylinder(glQ, cyl->base, cyl->top, cyl->height, cyl->slices, cyl->stacks);
		}
		if(simple->polygon->type == "sphere"){
			Sphere* sphere = (Sphere*)simple->polygon;
			gluSphere(glQ, sphere->radius, sphere->slices, sphere->stacks);
		}
		if(simple->polygon->type == "disk"){
			Disk* disk = (Disk*)simple->polygon;
			gluDisk(glQ, disk->inner, disk->outer, disk->slices, disk->loops);
		}
		glDisable(GL_TEXTURE_2D);
		
	}else if(object->type == "compound"){
		if(object->texture->id != "null"){
			textures.push(object->texture);
		}
		Compound* compound = (Compound*)object;
		vector<Object*>::iterator it = compound->childrenObj.begin();
		for( ; it != compound->childrenObj.end(); it++){
			processNode(*it);
		}
	}
	if(object->material->id != "null") materials.pop();
	if(object->texture->id != "null") textures.pop(); 
	glPopMatrix();	
}
 static void ArchFaceVault(float xValue, float resize) {
	 glPushMatrix();
	int i, numSlices;
	glTranslatef(xValue, 0, 0);
	glScalef(resize, 1, 1);
   double angle;
   double angInc;
   numSlices = 20;
   angle = 0;
   angInc = 3.14159/(2 * numSlices);

   for (i = 0; i < numSlices; i++) {

	   glNormal3f(0,0,1);
	      glColor3f(1,0,0);
       glBegin(GL_POLYGON);
       glVertex3f(1,0,1);  // corner
       glVertex3f( cos(angle) , sin(angle)-1, 1);
       glVertex3f( cos(angle+angInc), sin(angle+angInc)-1, 1);
       glEnd();

       glBegin(GL_POLYGON);
       glVertex3f(-1,0,1);  // corner
       glVertex3f(- cos(angle) , sin(angle)-1, 1);
       glVertex3f(- cos(angle+angInc), sin(angle+angInc)-1, 1);
       glEnd();

	   //---
	   glNormal3f(0,0,-1);
       glBegin(GL_POLYGON);
       glVertex3f(1,0,-1);  // corner
       glVertex3f( cos(angle) , sin(angle)-1, -1);
       glVertex3f( cos(angle+angInc), sin(angle+angInc)-1, -1);
       glEnd();

       glBegin(GL_POLYGON);
       glVertex3f(-1,0,-1);  // corner
       glVertex3f(- cos(angle) , sin(angle)-1, -1);
       glVertex3f(- cos(angle+angInc), sin(angle+angInc)-1, -1);
       glEnd();

	   // vault

	   glNormal3f(-cos(angle+angInc/2),-sin(angle+angInc/2),0);


	   glColor3f(0,0,1);
       glBegin(GL_POLYGON);
       glVertex3f(  cos(angle) ,    sin(angle)-1 ,1);  // corner
       glVertex3f( cos(angle) ,       sin(angle)-1, -1);
       glVertex3f( cos(angle+angInc), sin(angle+angInc)-1, -1);
       glEnd();

       glBegin(GL_POLYGON);
       glVertex3f(  cos(angle) ,    sin(angle)-1 ,1);  // corner
       glVertex3f( cos(angle+angInc) ,       sin(angle+angInc)-1, 1);
       glVertex3f( cos(angle+angInc), sin(angle+angInc)-1, -1);
       glEnd();

	   glNormal3f(cos(angle+angInc/2),-sin(angle+angInc/2),0);

       glBegin(GL_POLYGON);
       glVertex3f( - cos(angle) ,    sin(angle)-1 ,1);  // corner
       glVertex3f( -cos(angle) ,       sin(angle)-1, -1);
       glVertex3f( -cos(angle+angInc), sin(angle+angInc)-1, -1);
       glEnd();

       glBegin(GL_POLYGON);
       glVertex3f( - cos(angle) ,    sin(angle)-1 ,1);  // corner
       glVertex3f( -cos(angle+angInc) ,       sin(angle+angInc)-1, 1);
       glVertex3f( -cos(angle+angInc), sin(angle+angInc)-1, -1);
       glEnd();



	   angle += angInc;
   
   }
   glPopMatrix();
}
Exemple #5
0
void displayfunc()
   {
   unsigned int i;

   GLuint texid;

   clearbuffer(0,0,0);

   for (i=0; i<height; i++)
      memcpy(&image[i*components*imgwidth],
             &volume[(long long)frame*components*width*height+i*components*width],components*width);

   glGenTextures(1,&texid);
   glBindTexture(GL_TEXTURE_2D,texid);

   glPixelStorei(GL_UNPACK_ALIGNMENT,1);
   if (components==1) glTexImage2D(GL_TEXTURE_2D,0,GL_LUMINANCE,imgwidth,imgheight,0,GL_LUMINANCE,GL_UNSIGNED_BYTE,image);
   else if (components==3) glTexImage2D(GL_TEXTURE_2D,0,GL_RGB,imgwidth,imgheight,0,GL_RGB,GL_UNSIGNED_BYTE,image);
   else if (components==4) glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,imgwidth,imgheight,0,GL_RGBA,GL_UNSIGNED_BYTE,image);
   else ERRORMSG();

   glDepthMask(GL_FALSE);
   glDisable(GL_DEPTH_TEST);
   glDisable(GL_DITHER);
   glDisable(GL_CULL_FACE);

   glMatrixMode(GL_TEXTURE);
   glPushMatrix();
   glLoadIdentity();
   glTranslatef(0.5f/imgwidth,0.5f/imgheight,0.0f);
   glScalef((float)(width-1)/imgwidth,(float)(height-1)/imgheight,0.0f);
   glMatrixMode(GL_PROJECTION);
   glPushMatrix();
   glLoadIdentity();
   glOrtho(0.0f,winwidth-1,0.0f,winheight-1,-1.0f,1.0f);
   glMatrixMode(GL_MODELVIEW);
   glPushMatrix();
   glLoadIdentity();

   if (width*winheight<winwidth*height)
      {
      glTranslatef((winwidth-width*winheight/height)/2.0f,0.0f,0.0f);
      glScalef(width*winheight/height,winheight,0.0f);
      }
   else
      {
      glTranslatef(0.0f,(winheight-height*winwidth/width)/2.0f,0.0f);
      glScalef(winwidth,height*winwidth/width,0.0f);
      }

   glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MODULATE);

   glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
   glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);

   glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP);
   glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP);

   glEnable(GL_TEXTURE_2D);

   glColor3f(1.0f,1.0f,1.0f);
   glBegin(GL_TRIANGLE_FAN);
   glTexCoord2f(0.0f,1.0f);
   glVertex3f(0.0f,0.0f,0.0f);
   glTexCoord2f(1.0f,1.0f);
   glVertex3f(1.0f,0.0f,0.0f);
   glTexCoord2f(1.0f,0.0f);
   glVertex3f(1.0f,1.0f,0.0f);
   glTexCoord2f(0.0f,0.0f);
   glVertex3f(0.0f,1.0f,0.0f);
   glEnd();

   glDisable(GL_TEXTURE_2D);
   glDeleteTextures(1,&texid);

   glDepthMask(GL_TRUE);
   glEnable(GL_DEPTH_TEST);
   glEnable(GL_DITHER);
   glEnable(GL_CULL_FACE);

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

   glutSwapBuffers();
   waitfor(1.0/fps);

   if (!pausing)
      if (frame<depth-1) frame++;
      else frame=0;

   if (frame==depth-1) pausing=TRUE;
   }
    bool Render::frame(CZScene &scene, CZNode *pRootNode, bool clearColor /* = false */)
    {
        
# ifdef _WIN32
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
        gluLookAt(scene.eyePosition.x,scene.eyePosition.y,scene.eyePosition.z, 0,0,0,0,1,0);
# endif
        
        glClearColor(scene.bgColor.r, scene.bgColor.g, scene.bgColor.b, scene.bgColor.a);
        
        glClear(GL_DEPTH_BUFFER_BIT);
        if(clearColor)  glClear(GL_COLOR_BUFFER_BIT);
        
        projMat.SetPerspective(scene.cameraFov,(GLfloat)width/(GLfloat)height, scene.cameraNearPlane, scene.camearFarPlane);
        CZMat4 viewMat,viewProjMat;
        
        viewMat.SetLookAt(scene.eyePosition.x, scene.eyePosition.y, scene.eyePosition.z, 0, 0, 0, 0, 1, 0);
        viewProjMat = projMat * viewMat;
        
        curShader = getShader(kDirectionalLightShading);
        
        if (curShader == NULL)
        {
            LOG_ERROR("there's no shader designated\n");
            return false;
        }
        curShader->begin();
        
        // common uniforms
        glUniform3f(curShader->getUniformLocation("ambientLight.intensities"),
                    scene.ambientLight.intensity.x,
                    scene.ambientLight.intensity.y,
                    scene.ambientLight.intensity.z);
        
        glUniform3f(curShader->getUniformLocation("directionalLight.direction"),
                    scene.directionalLight.direction.x,scene.directionalLight.direction.y,scene.directionalLight.direction.z);
        
        glUniform3f(curShader->getUniformLocation("eyePosition"),scene.eyePosition.x,scene.eyePosition.y,scene.eyePosition.z);
        
        glUniform3f(curShader->getUniformLocation("directionalLight.intensities"),
                    scene.directionalLight.intensity.x,
                    scene.directionalLight.intensity.y,
                    scene.directionalLight.intensity.z);
        CZCheckGLError();
        
        draw(pRootNode, viewProjMat);
        CZCheckGLError();
        
        curShader->end();
#ifdef USE_OPENGL
        glColor3f(1.0,0.0,0.0);
        glPushMatrix();
        glTranslatef(scene.light.position.x, scene.light.position.y, scene.light.position.z);
        glDisable(GL_TEXTURE_2D);
        glutSolidSphere(2, 100, 100);
        glPopMatrix();
#endif
        
        return true;
    }
ENTRYPOINT void
draw_matrix (ModeInfo *mi)
{
  matrix_configuration *mp = &mps[MI_SCREEN(mi)];
  Display *dpy = MI_DISPLAY(mi);
  Window window = MI_WINDOW(mi);
  int i;

  if (!mp->glx_context)
    return;

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

  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

  glPushMatrix ();
  glRotatef(current_device_rotation(), 0, 0, 1);

  if (do_texture)
    {
      glEnable(GL_TEXTURE_2D);
      glEnable(GL_BLEND);

      /* Jeff Epler points out:
         By using GL_ONE instead of GL_SRC_ONE_MINUS_ALPHA, glyphs are
         added to each other, so that a bright glyph with a darker one
         in front is a little brighter than the bright glyph alone.
       */
      glBlendFunc (GL_SRC_ALPHA, GL_ONE);
    }

  if (do_rotate)
    {
      glRotatef (mp->view_x, 1, 0, 0);
      glRotatef (mp->view_y, 0, 1, 0);
    }

#ifdef DEBUG
# if 0
  glScalef(0.5, 0.5, 0.5);
# endif
# if 0
  glRotatef(-30, 0, 1, 0); 
# endif
  draw_grid (mi);
#endif

  mi->polygon_count = 0;

  /* Render (and tick) each strip, starting at the back
     (draw the ones farthest from the camera first, to make
     the alpha transparency work out right.)
   */
  {
    strip **sorted = malloc (mp->nstrips * sizeof(*sorted));
    for (i = 0; i < mp->nstrips; i++)
      sorted[i] = &mp->strips[i];
    qsort (sorted, i, sizeof(*sorted), cmp_strips);

    for (i = 0; i < mp->nstrips; i++)
      {
        strip *s = sorted[i];
        tick_strip (mi, s);
        draw_strip (mi, s);
      }
    free (sorted);
  }

  auto_track (mi);

#if 0
  glBegin(GL_QUADS);
  glColor3f(1,1,1);
  glTexCoord2f (0,0);  glVertex3f(-15,-15,0);
  glTexCoord2f (0,1);  glVertex3f(-15,15,0);
  glTexCoord2f (1,1);  glVertex3f(15,15,0);
  glTexCoord2f (1,0);  glVertex3f(15,-15,0);
  glEnd();
#endif

  glPopMatrix ();

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

  glXSwapBuffers(dpy, window);
}
Exemple #8
0
void Mesh::gen_controlpoints(int cpx, int cpy, int cpz, bool picking)
{
    //allocate memory for control points
    if(m_chainmail->objSize == 0){
        m_chainmail->object = new DeformElement[cpx*cpy*cpz];
    }
    // center of points
    double step_x = m_bbox->m_size[0]/(cpx - 1);
    double step_y = m_bbox->m_size[1]/(cpy - 1);
    double step_z = m_bbox->m_size[2]/(cpz - 1);

    double radius = std::min(step_x, std::min( step_y, step_z) );
    radius = radius/6.0;
    int cx= cpx/2; int cy = cpy/2; int cz = cpz/2;
    int index = 0;
    for(int i= 0; i < cpx; i++)
        for(int j= 0; j< cpy; j++)
            for(int k=0; k< cpz; k++){
                //translate the point
                Matrix4x4 m_trans;
                if(m_chainmail->objSize == 0 || m_chainmail->objSize <= index){
                    m_trans[0][3] = m_bbox->m_pos[0] + i*step_x;
                    m_trans[1][3] = m_bbox->m_pos[1] + j*step_y;
                    m_trans[2][3] = m_bbox->m_pos[2] + k*step_z;

                    //insert the point
                    m_chainmail->object[index].x = m_trans[0][3];
                    m_chainmail->object[index].y = m_trans[1][3];
                    m_chainmail->object[index].z = m_trans[2][3];
                    DeformElement* link = &m_chainmail->object[index];

                    //if point is'nt on left face add left neightbor
                    if(i>0){
                        link->left = &m_chainmail->object[index - cpy*cpz];
                        m_chainmail->object[index - cpy*cpz].right = link;
                    }
                    else{
                        link->left = NULL;
                    }
                    //if point is'nt on bottom face add bottom meightbor
                    if(j>0){
                        link->bottom = &m_chainmail->object[index - cpz];
                        m_chainmail->object[index - cpz].top = link;
                    }
                    else{
                        link->bottom = NULL;
                    }
                    //if point is'nt on back face add back meightbor
                    if(k>0){
                        link->back = &m_chainmail->object[index - 1];
                        m_chainmail->object[index - 1].front = link;
                    }
                    else{
                        link->back = NULL;
                    }
                    if(k == cpz-1){
                        link->front = NULL;
                    }
                    if(j == cpy -1){
                        link->top = NULL;
                    }
                    if(i == cpx - 1){
                        link->right = NULL;
                    }
                    if(i==cx && j == cy && k == cz)
                        m_chainmail->centre = link;

                    m_chainmail->objSize++;
                }
                else{
                    m_trans[0][3] = m_chainmail->object[index].x;
                    m_trans[1][3] = m_chainmail->object[index].y;
                    m_trans[2][3] = m_chainmail->object[index].z;
                }

                GLint mm;
                glGetIntegerv( GL_MATRIX_MODE, &mm);

                glMatrixMode(GL_MODELVIEW);
                glPushMatrix();

                GLdouble t[16];
                int z=0;
                for( int i=0; i < 4; i++ ){
                    for( int j=0; j < 4; j++ ){
                        t[z] = m_trans[j][i];
                        z++;
                    }
                }
                glMultMatrixd(t);

                Sphere cpoint;
                cpoint.walk_gl(radius, picking);

                glPopMatrix();
                glMatrixMode(mm);

                index++;
            }
}
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();

    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() * devicePixelRatio(), height() * devicePixelRatio());

    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);
}
void printDecimalNumbers(float inputValue) 
{
    tempInputValue  = inputValue;
    inputValueIsNegative = false;
    
    if(inputValue < 10.0f)
    {
     twoLeftOfDecimalPoint = 0;
    }
    
    if(tempInputValue < 0.0f)
    {
         inputValueIsNegative = true;
         tempInputValue       = tempInputValue * -1.0f;
         inputValue           = inputValue     * -1.0f;
    }
    if(tempInputValue >= 10.0f)
    {
         twoLeftOfDecimalPoint = (int)tempInputValue;
         twoLeftOfDecimalPoint = twoLeftOfDecimalPoint / 10;             
    } 

    tempValueA      = (int)inputValue;
    leftOfDecimalPoint = tempValueA;
    if(leftOfDecimalPoint >= 10 && leftOfDecimalPoint < 20)
    {
        leftOfDecimalPoint = leftOfDecimalPoint -10;
    }
    if(leftOfDecimalPoint >= 20 && leftOfDecimalPoint < 30)
    {
        leftOfDecimalPoint = leftOfDecimalPoint -20;
    }
    if(leftOfDecimalPoint >= 30 && leftOfDecimalPoint < 40)
    {
        leftOfDecimalPoint = leftOfDecimalPoint -30;
    }
    if(leftOfDecimalPoint >= 40 && leftOfDecimalPoint < 50)
    {
        leftOfDecimalPoint = leftOfDecimalPoint -40;
    }
    if(leftOfDecimalPoint >= 50 && leftOfDecimalPoint < 60)
    {
        leftOfDecimalPoint = leftOfDecimalPoint -50;
    }
    if(leftOfDecimalPoint >= 60 && leftOfDecimalPoint < 70)
    {
        leftOfDecimalPoint = leftOfDecimalPoint -60;
    }
    if(leftOfDecimalPoint >= 70 && leftOfDecimalPoint < 80)
    {
        leftOfDecimalPoint = leftOfDecimalPoint -70;
    }
    if(leftOfDecimalPoint >= 80 && leftOfDecimalPoint < 90)
    {
        leftOfDecimalPoint = leftOfDecimalPoint -80;
    }        
    if(leftOfDecimalPoint >= 90 && leftOfDecimalPoint < 100)
    {
        leftOfDecimalPoint = leftOfDecimalPoint -90;
    }    
    tempInputValueB =  tempInputValue;        

    inputValue      = inputValue  - tempValueA;
    tempInputValueB = tempInputValueB - tempValueA;
    tempInputValueB = tempInputValueB * 10;

    inputValue      = inputValue      * 10;

    input_01        = (int)inputValue;
    
    tempInputValueB = tempInputValueB - input_01;

    tempInputValue  = tempInputValueB * 10;
    
    input_02 = (int)tempInputValue;
    
 glScalef(.3,.3,.3);   
 if(leftOfDecimalPoint == 0)
 {
             glPushMatrix();        
                  glTranslatef(-.13, 0.0f, 0.0f);
                  glInterleavedArrays( GL_V3F, 0, zero_VERT );                        
                  glDrawArrays( GL_TRIANGLES, 0, 36);
             glPopMatrix();
 }
             
 if(leftOfDecimalPoint == 1)
 {
            glPushMatrix();
                glTranslatef(-.13f, 0.0f, 0.0f);            
                glInterleavedArrays( GL_V3F, 0, one_VERT );                        
                glDrawArrays( GL_TRIANGLES, 0, 6);
            glPopMatrix();       
 }
 if(twoLeftOfDecimalPoint == 1)
 {
            glPushMatrix();
                glTranslatef(-.23f, 0.0f, 0.0f);            
                glInterleavedArrays( GL_V3F, 0, one_VERT );                        
                glDrawArrays( GL_TRIANGLES, 0, 6);
            glPopMatrix();       
 }
 if(leftOfDecimalPoint == 2)
 {
            glPushMatrix();
                glTranslatef(-.13f, 0.0f, 0.0f);            
                glInterleavedArrays( GL_V3F, 0, two_VERT );                        
                glDrawArrays( GL_TRIANGLES, 0, 27);
            glPopMatrix();       
 }
 if(twoLeftOfDecimalPoint == 2)
 {
            glPushMatrix();
                glTranslatef(-.23f, 0.0f, 0.0f);            
                glInterleavedArrays( GL_V3F, 0, two_VERT );                        
                glDrawArrays( GL_TRIANGLES, 0, 27);
            glPopMatrix();       
 }
 if(leftOfDecimalPoint == 3)
 {
            glPushMatrix();
                glTranslatef(-.13f, 0.0f, 0.0f);            
                glInterleavedArrays( GL_V3F, 0, three_VERT );                        
                glDrawArrays( GL_TRIANGLES, 0, 51);
            glPopMatrix();       
 }
 if(twoLeftOfDecimalPoint == 3)
 {
            glPushMatrix();
                glTranslatef(-.23f, 0.0f, 0.0f);            
                glInterleavedArrays( GL_V3F, 0, three_VERT );                        
                glDrawArrays( GL_TRIANGLES, 0, 51);
            glPopMatrix();       
 }
 if(leftOfDecimalPoint == 4)
 {
            glPushMatrix();
                glTranslatef(-.13f, 0.0f, 0.0f);            
                glInterleavedArrays( GL_V3F, 0, four_VERT );                        
                glDrawArrays( GL_TRIANGLES, 0, 18);
            glPopMatrix();       
 }
 if(twoLeftOfDecimalPoint == 4)
 {
            glPushMatrix();
                glTranslatef(-.23f, 0.0f, 0.0f);            
                glInterleavedArrays( GL_V3F, 0, four_VERT );                        
                glDrawArrays( GL_TRIANGLES, 0, 18);
            glPopMatrix();       
 }
 if(leftOfDecimalPoint == 5)
 {
            glPushMatrix();
                glTranslatef(-.13f, 0.0f, 0.0f);            
                glInterleavedArrays( GL_V3F, 0, five_VERT );                        
                glDrawArrays( GL_TRIANGLES, 0, 39);
            glPopMatrix();       
 }
 if(twoLeftOfDecimalPoint == 5)
 {
            glPushMatrix();
                glTranslatef(-.23f, 0.0f, 0.0f);            
                glInterleavedArrays( GL_V3F, 0, five_VERT );                        
                glDrawArrays( GL_TRIANGLES, 0, 39);
            glPopMatrix();       
 }
 if(leftOfDecimalPoint == 6)
 {
            glPushMatrix();
                glTranslatef(-.13f, 0.0f, 0.0f);            
                glInterleavedArrays( GL_V3F, 0, six_VERT );                        
                glDrawArrays( GL_TRIANGLES, 0, 69);
            glPopMatrix();       
 }
 if(twoLeftOfDecimalPoint == 6)
 {
            glPushMatrix();
                glTranslatef(-.23f, 0.0f, 0.0f);            
                glInterleavedArrays( GL_V3F, 0, six_VERT );                        
                glDrawArrays( GL_TRIANGLES, 0, 69);
            glPopMatrix();       
 }
 if(leftOfDecimalPoint == 7)
 {
            glPushMatrix();
                glTranslatef(-.13f, 0.0f, 0.0f);            
                glInterleavedArrays( GL_V3F, 0, seven_VERT );                        
                glDrawArrays( GL_TRIANGLES, 0, 15);
            glPopMatrix();       
 }
 if(twoLeftOfDecimalPoint == 7)
 {
            glPushMatrix();
                glTranslatef(-.23f, 0.0f, 0.0f);            
                glInterleavedArrays( GL_V3F, 0, seven_VERT );                        
                glDrawArrays( GL_TRIANGLES, 0, 15);
            glPopMatrix();       
 }
 if(leftOfDecimalPoint == 8)
 {
            glPushMatrix();
                glTranslatef(-.13f, 0.0f, 0.0f);            
                glInterleavedArrays( GL_V3F, 0, eight_VERT );                        
                glDrawArrays( GL_TRIANGLES, 0, 84);
            glPopMatrix();       
 }
 if(twoLeftOfDecimalPoint == 8)
 {
            glPushMatrix();
                glTranslatef(-.23f, 0.0f, 0.0f);            
                glInterleavedArrays( GL_V3F, 0, eight_VERT );                        
                glDrawArrays( GL_TRIANGLES, 0, 84);
            glPopMatrix();       
 }
 if(leftOfDecimalPoint == 9)
 {
            glPushMatrix();
                glTranslatef(-.13f, 0.0f, 0.0f);            
                glInterleavedArrays( GL_V3F, 0, nine_VERT );                        
                glDrawArrays( GL_TRIANGLES, 0, 60);
            glPopMatrix();       
 }
 if(twoLeftOfDecimalPoint == 9)
 {
            glPushMatrix();
                glTranslatef(-.23f, 0.0f, 0.0f);            
                glInterleavedArrays( GL_V3F, 0, nine_VERT );                        
                glDrawArrays( GL_TRIANGLES, 0, 60);
            glPopMatrix();       
 } 
 
        if(inputValueIsNegative)
        {
            glPushMatrix();        
                  glTranslatef(-0.33, 0.0f, 0.0f);
                  glScalef(10.0f, 3.0f, 3.0f);
                  glInterleavedArrays( GL_V3F, 0, decimalPoint_VERT );                        
                  glDrawArrays( GL_TRIANGLES, 0, 6);
             glPopMatrix();
        }             
             
        glPushMatrix();        
                  glTranslatef(-0.07, 0.0f, 0.0f);
                  glScalef(3.0f, 3.0f, 3.0f);
                  glInterleavedArrays( GL_V3F, 0, decimalPoint_VERT );                        
                  glDrawArrays( GL_TRIANGLES, 0, 6);
        glPopMatrix();
             
        if(input_01 == 0)
        {    
             glPushMatrix();        
                  glTranslatef(numberPosition, 0.0f, 0.0f);
                  glInterleavedArrays( GL_V3F, 0, zero_VERT );                        
                  glDrawArrays( GL_TRIANGLES, 0, 36);
             glPopMatrix();
        }
        if(input_02 == 0)
        {    
             glPushMatrix();        
                  glTranslatef(numberPosition + pushNumber, 0.0f, 0.0f);
                  glInterleavedArrays( GL_V3F, 0, zero_VERT );                        
                  glDrawArrays( GL_TRIANGLES, 0, 36);
             glPopMatrix();
        }
////////////////////////////////////////////////////////////////////////////////       
        if(input_01 == 1)
        {
            glPushMatrix();
                glTranslatef(numberPosition, 0.0f, 0.0f);            
                glInterleavedArrays( GL_V3F, 0, one_VERT );                        
                glDrawArrays( GL_TRIANGLES, 0, 6);
            glPopMatrix();
        }
        if(input_02 == 1)
        {
            glPushMatrix();
                glTranslatef(numberPosition + pushNumber, 0.0f, 0.0f);            
                glInterleavedArrays( GL_V3F, 0, one_VERT );                        
                glDrawArrays( GL_TRIANGLES, 0, 6);
            glPopMatrix();
        }
////////////////////////////////////////////////////////////////////////////////        
        if(input_01 == 2)
        {
            glPushMatrix();
                glTranslatef(numberPosition, 0.0f, 0.0f);            
                glInterleavedArrays( GL_V3F, 0, two_VERT );                        
                glDrawArrays( GL_TRIANGLES, 0, 27);
            glPopMatrix();
        }
        if(input_02 == 2)
        {
            glPushMatrix();
                glTranslatef(numberPosition + pushNumber, 0.0f, 0.0f);            
                glInterleavedArrays( GL_V3F, 0, two_VERT );                        
                glDrawArrays( GL_TRIANGLES, 0, 27);
            glPopMatrix();
        }        
////////////////////////////////////////////////////////////////////////////////        
        if(input_01 == 3)
        {    
            glPushMatrix();
                glTranslatef(numberPosition, 0.0f, 0.0f);           
                glInterleavedArrays( GL_V3F, 0, three_VERT );                        
                glDrawArrays( GL_TRIANGLES, 0, 51);   
            glPopMatrix();
        }
        if(input_02 == 3)
        {    
            glPushMatrix();
                glTranslatef(numberPosition + pushNumber, 0.0f, 0.0f);           
                glInterleavedArrays( GL_V3F, 0, three_VERT );                        
                glDrawArrays( GL_TRIANGLES, 0, 51);   
            glPopMatrix();
        }
////////////////////////////////////////////////////////////////////////////////        
        if(input_01 == 4)
        {    
            glPushMatrix();
                glTranslatef(numberPosition, 0.0f, 0.0f);            
                glInterleavedArrays( GL_V3F, 0, four_VERT );                        
                glDrawArrays( GL_TRIANGLES, 0, 18);
            glPopMatrix();
        }
        if(input_02 == 4)
        {    
            glPushMatrix();
                glTranslatef(numberPosition + pushNumber, 0.0f, 0.0f);            
                glInterleavedArrays( GL_V3F, 0, four_VERT );                        
                glDrawArrays( GL_TRIANGLES, 0, 18);
            glPopMatrix();
        }
////////////////////////////////////////////////////////////////////////////////        
        if(input_01 == 5)
        {    
            glPushMatrix();
                glTranslatef(numberPosition, 0.0f, 0.0f);            
                glInterleavedArrays( GL_V3F, 0, five_VERT );                        
                glDrawArrays( GL_TRIANGLES, 0, 39);
            glPopMatrix();
        }
        if(input_02 == 5)
        {    
            glPushMatrix();
                glTranslatef(numberPosition + pushNumber, 0.0f, 0.0f);            
                glInterleavedArrays( GL_V3F, 0, five_VERT );                        
                glDrawArrays( GL_TRIANGLES, 0, 39);
            glPopMatrix();
        }
////////////////////////////////////////////////////////////////////////////////        
        if(input_01 == 6)
        {    
            glPushMatrix();
                glTranslatef(numberPosition, 0.0f, 0.0f);    
                glInterleavedArrays( GL_V3F, 0, six_VERT );                        
                glDrawArrays( GL_TRIANGLES, 0, 69);
            glPopMatrix();
        }
        if(input_02 == 6)
        {    
            glPushMatrix();
                glTranslatef(numberPosition + pushNumber, 0.0f, 0.0f);    
                glInterleavedArrays( GL_V3F, 0, six_VERT );                        
                glDrawArrays( GL_TRIANGLES, 0, 69);
            glPopMatrix();
        }
////////////////////////////////////////////////////////////////////////////////        
        if(input_01 == 7)
        {    
            glPushMatrix();
                glTranslatef(numberPosition, 0.0f, 0.0f);            
                glInterleavedArrays( GL_V3F, 0, seven_VERT );                        
                glDrawArrays( GL_TRIANGLES, 0, 15);
            glPopMatrix();
        }
        if(input_02 == 7)
        {    
            glPushMatrix();
                glTranslatef(numberPosition + pushNumber, 0.0f, 0.0f);            
                glInterleavedArrays( GL_V3F, 0, seven_VERT );                        
                glDrawArrays( GL_TRIANGLES, 0, 15);
            glPopMatrix();
        }
////////////////////////////////////////////////////////////////////////////////        
        if(input_01 == 8)
        {    
            glPushMatrix();
                glTranslatef(numberPosition, 0.0f, 0.0f);            
                glInterleavedArrays( GL_V3F, 0, eight_VERT );                        
                glDrawArrays( GL_TRIANGLES, 0, 84);
            glPopMatrix();
        }
        if(input_02 == 8)
        {    
            glPushMatrix();
                glTranslatef(numberPosition + pushNumber, 0.0f, 0.0f);            
                glInterleavedArrays( GL_V3F, 0, eight_VERT );                        
                glDrawArrays( GL_TRIANGLES, 0, 84);
            glPopMatrix();
        }
////////////////////////////////////////////////////////////////////////////////        
        if(input_01 == 9)
        {    
            glPushMatrix();
                glTranslatef(numberPosition, 0.0f, 0.0f);           
                glInterleavedArrays( GL_V3F, 0, nine_VERT );                        
                glDrawArrays( GL_TRIANGLES, 0, 60);
            glPopMatrix();   
        }
        if(input_02 == 9)
        {    
            glPushMatrix();
                glTranslatef(numberPosition + pushNumber, 0.0f, 0.0f);           
                glInterleavedArrays( GL_V3F, 0, nine_VERT );                        
                glDrawArrays( GL_TRIANGLES, 0, 60);
            glPopMatrix();   
        }
}//__close-->>  printNumbers(function)
Exemple #11
0
int MD2MODEL_draw(CMD2MODEL *_object, double frame, int texture, float *pos, float *scale, float *rotate)
{
	int i;
	int n, n2;
	double interp;
	GLfloat v_curr[3], v_next[3], v[3], norm[3];
	GLfloat *n_curr, *n_next;
	const framemd2 *pframe1, *pframe2;
	const vertexmd2 *pvert1, *pvert2;
	bool enabled;
	int nvert = 0;

	int *pglcmds;
	glcmd *packet;

	if (texture < 0)
		return 0;

	n = (int)frame;
	interp = frame - n;

	if (n < 0 || n >= THIS->num_frames)
		return 0;

	n2 = n + 1;
	if (n2 >= THIS->num_frames)
		n2 = 0;

	enabled = glIsEnabled(GL_TEXTURE_2D);
  if (!enabled)
		glEnable(GL_TEXTURE_2D);

	glPushMatrix();

	if (pos)
		glTranslatef(pos[0], pos[1], pos[2]);

	glRotatef(-90, 1, 0, 0);
	glRotatef(-90, 0, 0, 1);

	if (rotate && rotate[0] != 0)
		glRotatef(rotate[0], rotate[1], rotate[2], rotate[3]);

	glScalef(THIS->scale[0], THIS->scale[1], THIS->scale[2]);

	if (scale)
		glScalef(scale[0], scale[1], scale[2]);

	glBindTexture(GL_TEXTURE_2D, texture);

#if 1
	// pglcmds points at the start of the command list
	pglcmds = THIS->glcmds;

	pframe1 = &THIS->frames[n];
	pframe2 = &THIS->frames[n2];

	//fprintf(stderr, "\n******** %p: n = %d / %d | %p %p\n", _object, n, THIS->num_frames, pframe1->verts, pframe2->verts);

	// Draw the model
	while ((i = *(pglcmds++)) != 0)
	{
		//fprintf(stderr, "i = %d\n", i);

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

		// Draw each vertex of this group
		for (/* Nothing */ ; i > 0; --i, pglcmds += 3)
		{
			packet = (glcmd *)pglcmds;

			//fprintf(stderr, "%d (%d) ", i, packet->index);

			pvert1 = &pframe1->verts[packet->index];
			pvert2 = &pframe2->verts[packet->index];
			//if (!pvert1 || !pvert2)
			//	continue;

			// Pass texture coordinates to OpenGL
			//glTexCoord2f (pGLcmd->s, 1.0f - pGLcmd->t);
			glTexCoord2f(packet->s, packet->t);

			// Compute interpolated normal vector
			n_curr = anorms_table[pvert1->normalIndex];
			n_next = anorms_table[pvert2->normalIndex];

			norm[0] = n_curr[0] + interp * (n_next[0] - n_curr[0]);
			norm[1] = n_curr[1] + interp * (n_next[1] - n_curr[1]);
			norm[2] = n_curr[2] + interp * (n_next[2] - n_curr[2]);

			// Normal vector
			glNormal3fv(norm);

			v_curr[0] = pframe1->scale[0] * pvert1->v[0] + pframe1->translate[0];
			v_curr[1] = pframe1->scale[1] * pvert1->v[1] + pframe1->translate[1];
			v_curr[2] = pframe1->scale[2] * pvert1->v[2] + pframe1->translate[2];

			v_next[0] = pframe2->scale[0] * pvert2->v[0] + pframe2->translate[0];
			v_next[1] = pframe2->scale[1] * pvert2->v[1] + pframe2->translate[1];
			v_next[2] = pframe2->scale[2] * pvert2->v[2] + pframe2->translate[2];

			v[0] = v_curr[0] + interp * (v_next[0] - v_curr[0]);
			v[1] = v_curr[1] + interp * (v_next[1] - v_curr[1]);
			v[2] = v_curr[2] + interp * (v_next[2] - v_curr[2]);

			glVertex3fv(v);
			nvert++;
		}

		//fprintf(stderr, "\n");

		glEnd();
	}
#else
	{
		int j;
		GLfloat s, t;

		glBegin (GL_TRIANGLES);

		for (i = 0; i < THIS->num_tris; ++i)
		{
			for (j = 0; j < 3; ++j)
			{
				pframe1 = &THIS->frames[n];
				pframe2 = &THIS->frames[n2];
				pvert1 = &pframe1->verts[THIS->triangles[i].vertex[j]];
				pvert2 = &pframe2->verts[THIS->triangles[i].vertex[j]];

				s = (GLfloat)THIS->texcoords[THIS->triangles[i].st[j]].s / THIS->skinwidth;
				t = (GLfloat)THIS->texcoords[THIS->triangles[i].st[j]].t / THIS->skinheight;

				glTexCoord2f (s, t);

				n_curr = anorms_table[pvert1->normalIndex];
				n_next = anorms_table[pvert2->normalIndex];

				norm[0] = n_curr[0] + interp * (n_next[0] - n_curr[0]);
				norm[1] = n_curr[1] + interp * (n_next[1] - n_curr[1]);
				norm[2] = n_curr[2] + interp * (n_next[2] - n_curr[2]);

				glNormal3fv (norm);

				v_curr[0] = pframe1->scale[0] * pvert1->v[0] + pframe1->translate[0];
				v_curr[1] = pframe1->scale[1] * pvert1->v[1] + pframe1->translate[1];
				v_curr[2] = pframe1->scale[2] * pvert1->v[2] + pframe1->translate[2];

				v_next[0] = pframe2->scale[0] * pvert2->v[0] + pframe2->translate[0];
				v_next[1] = pframe2->scale[1] * pvert2->v[1] + pframe2->translate[1];
				v_next[2] = pframe2->scale[2] * pvert2->v[2] + pframe2->translate[2];

				v[0] = v_curr[0] + interp * (v_next[0] - v_curr[0]);
				v[1] = v_curr[1] + interp * (v_next[1] - v_curr[1]);
				v[2] = v_curr[2] + interp * (v_next[2] - v_curr[2]);

				glVertex3fv (v);
				nvert++;
			}
		}

		glEnd();
	}
#endif

	//glScalef(1/THIS->scale[0], 1/THIS->scale[1], 1/THIS->scale[2]);
	glPopMatrix();

	if (!enabled)
		glDisable(GL_TEXTURE_2D);

	return nvert;
}
Exemple #12
0
// draw_characterを改変して使ってみる
void draw_one_character(s_character *character)
{
    GLfloat color_body[4];
    GLfloat color_eye[4] = {0.6, 0.0, 0.0, 1.0};

    double pos_base[3] = {-0.27, 0.0, 0.27};
    double pos_x, pos_y, pos_z;
    e_color color;
    int i;

    //ここだけ変えた
    pos_x = character->x;
    pos_y = character->y;
    pos_z = character->z;
    color = character->color;

    // set color
    color_body[0] = color_val[color][0];
    color_body[1] = color_val[color][1];
    color_body[2] = color_val[color][2];
    color_body[3] = 1.0;

    // start drawing an object
    glPushMatrix();

    glMaterialfv(GL_FRONT, GL_AMBIENT, color_body);
    glMaterialfv(GL_FRONT, GL_DIFFUSE, color_body);
    glMaterialfv(GL_FRONT, GL_SPECULAR, color_body);
    glMaterialf(GL_FRONT, GL_SHININESS, 80.0);

    glTranslatef(pos_x, pos_y, pos_z);

    // 動いてる向きに回転させる
    if (character->speed < 0) {
        glRotatef(90.0f, 0.0f, 0.0f, 1.0f); 
    } else {
        glRotatef(-90.0f, 0.0f, 0.0f, 1.0f); 
    }

    // body
    draw_rectangle(0.5, 0.8, 0.3, 0.0, -0.1, 0.0);
    // head
    draw_rectangle(0.3, 0.3, 0.3, 0.0, 0.3, 0.2);

    for (i = 0; i < 3; i++) {
        // right
            // baseleg
            draw_rectangle(0.4, 0.07, 0.07, -0.2, pos_base[i] - 0.1, 0.0);
            // endleg
            draw_rectangle(0.07, 0.07, 0.3, -0.4, pos_base[i] - 0.1, -0.15);
        // left
            // baseleg
            draw_rectangle(0.4, 0.07, 0.07, 0.2, pos_base[i] - 0.1, 0.0);
            // endleg
            draw_rectangle(0.07, 0.07, 0.3, 0.4, pos_base[i] - 0.1, -0.15);
    }

    glMaterialfv(GL_FRONT, GL_AMBIENT, color_eye);
    glMaterialfv(GL_FRONT, GL_DIFFUSE, color_eye);
    glMaterialfv(GL_FRONT, GL_SPECULAR, color_eye);
    glMaterialf(GL_FRONT, GL_SHININESS, 80.0);

    // eyes
    draw_rectangle(0.05, 0.05, 0.05, 0.07, 0.45, 0.25);
    draw_rectangle(0.05, 0.05, 0.05, -0.07, 0.45, 0.25);

    // finish drawing an object
    glPopMatrix();
}
void TextFieldWidget::Render()
{
	//Color BackgroundColor(1.0, 1.0, 1.0);
	Color BackgroundColor = m_BackgroundColor;
	Color BorderColor(0.3, 0.3, 0.3);

	/*if (CheckHover(WidgetManager) && CheckActive(WidgetManager))
	{
	}
	else if ((CheckHover(WidgetManager) && !CheckAnyActive(WidgetManager)) || (!CheckHover(WidgetManager) && CheckActive(WidgetManager)))
	{
		BorderColor[0] = 0.898;
		BorderColor[1] = 0.765;
		BorderColor[2] = 0.396;
	}
	else
	{
	}*/
	//if (CheckHover())
	// HACK
	if (HasTypingFocus())
	{
		BorderColor[0] = 0.898;
		BorderColor[1] = 0.765;
		BorderColor[2] = 0.396;
	}

	/*glBegin(GL_QUADS);
		glVertex2d(m_Position.X(), m_Position.Y());
		glVertex2d(m_Position.X(), m_Position.Y() + 30);
		glVertex2d(m_Position.X() + 30, m_Position.Y() + 30);
		glVertex2d(m_Position.X() + 30, m_Position.Y());
	glEnd();*/
	DrawAroundBox(GetPosition(), GetDimensions(), BackgroundColor, BorderColor);

	// TEST
	auto ContentWithInsertion = m_Content;
	if (!m_TypingModule.GetString().empty())
	{
		for (auto & Pointer : GetGestureRecognizer().GetConnected())
		{
			if (Pointer::VirtualCategory::POINTING == Pointer->GetVirtualCategory())
			{
				Vector2n GlobalPosition(Pointer->GetPointerState().GetAxisState(0).GetPosition(), Pointer->GetPointerState().GetAxisState(1).GetPosition());
				Vector2n LocalPosition(GlobalToLocal(GlobalPosition));
				LocalPosition = m_TypingModule.GetInsertionPosition(LocalPosition);

				auto InsertionPosition = GetNearestCaretPosition(LocalPosition);
				ContentWithInsertion.insert(InsertionPosition, m_TypingModule.GetString());
			}
		}
	}

	glColor3d(0, 0, 0);
	OpenGLStream OpenGLStream(GetPosition());
	OpenGLStream << ContentWithInsertion.substr(0, std::min(m_CaretPosition, m_SelectionPosition));

	Vector2n CaretPosition;

	// Remember caret position at selection front
	if (std::min(m_CaretPosition, m_SelectionPosition) == m_CaretPosition)
	{
		CaretPosition = OpenGLStream.GetCaretPosition();
	}

	// Draw selected text as highlighted
	if (HasTypingFocus())
	{
		OpenGLStream.SetBackgroundColor(Color(static_cast<uint8>(195), 212, 242));
	}
	else
	{
		OpenGLStream.SetBackgroundColor(Color(static_cast<uint8>(212), 212, 212));
	}
	auto SelectionLength = std::max(m_CaretPosition, m_SelectionPosition) - std::min(m_CaretPosition, m_SelectionPosition);
	OpenGLStream << ContentWithInsertion.substr(std::min(m_CaretPosition, m_SelectionPosition), SelectionLength);
	OpenGLStream.SetBackgroundColor(Color(1.0, 1.0, 1.0));

	// Remember caret position at selection back
	if (std::max(m_CaretPosition, m_SelectionPosition) == m_CaretPosition)
	{
		CaretPosition = OpenGLStream.GetCaretPosition();
	}

	OpenGLStream << ContentWithInsertion.substr(std::max(m_CaretPosition, m_SelectionPosition));

	//if (CheckHover())
	// HACK
	if (HasTypingFocus())
	{
		// Draw caret
		//if (static_cast<int>(glfwGetTime() * 2) % 2)
		{
			glPushMatrix();
			glTranslated(CaretPosition.X(), CaretPosition.Y(), 0);
			glColor3d(0, 0, 0);
			glBegin(GL_QUADS);
				glVertex2d(-1, 0);
				glVertex2d(-1, lineHeight);
				glVertex2d(+1, lineHeight);
				glVertex2d(+1, 0);
			glEnd();
			glPopMatrix();
		}
	}
}
void DaisyWheelTool::display(GLContextData&) const
	{
	if(active)
		{
		/* Save OpenGL state: */
		glPushAttrib(GL_ENABLE_BIT|GL_LINE_BIT);
		
		/* Draw the daisy wheel: */
		glPushMatrix();
		glMultMatrix(wheelTransform);
		
		/* Set up OpenGL state: */
		glDisable(GL_LIGHTING);
		
		glBegin(GL_QUADS);
		Scalar angle0=Scalar(0);
		Scalar angleDiff=zoomAngle-angle0;
		if(angleDiff<-Math::Constants<Scalar>::pi)
			angleDiff+=Scalar(2)*Math::Constants<Scalar>::pi;
		else if(angleDiff>Math::Constants<Scalar>::pi)
			angleDiff-=Scalar(2)*Math::Constants<Scalar>::pi;
		Scalar weight=Math::abs(angleDiff)/Math::Constants<Scalar>::pi;
		angleDiff*=Math::pow(weight,Scalar(1)-zoomStrength)/weight;
		Scalar wAngle0=zoomAngle-angleDiff;
		Scalar c0=Math::cos(wAngle0);
		Scalar s0=Math::sin(wAngle0);
		for(int i=0;i<numCharacters;++i)
			{
			Scalar angle1=angle0+dynamicWeights[i]*Scalar(2)*Math::Constants<Scalar>::pi/dynamicWeightSum;
			angleDiff=zoomAngle-angle1;
			if(angleDiff<-Math::Constants<Scalar>::pi)
				angleDiff+=Scalar(2)*Math::Constants<Scalar>::pi;
			else if(angleDiff>Math::Constants<Scalar>::pi)
				angleDiff-=Scalar(2)*Math::Constants<Scalar>::pi;
			weight=Math::abs(angleDiff)/Math::Constants<Scalar>::pi;
			angleDiff*=Math::pow(weight,Scalar(1)-zoomStrength)/weight;
			Scalar wAngle1=zoomAngle-angleDiff;
			Scalar c1=Math::cos(wAngle1);
			Scalar s1=Math::sin(wAngle1);
			
			if(i%2==0)
				glColor3f(1.0f,0.5f,0.5f);
			else
				glColor3f(0.0f,0.5f,1.0f);
			glVertex3f(s0*factory->innerRadius,0.0f,c0*factory->innerRadius);
			glVertex3f(s1*factory->innerRadius,0.0f,c1*factory->innerRadius);
			glVertex3f(s1*factory->outerRadius,0.0f,c1*factory->outerRadius);
			glVertex3f(s0*factory->outerRadius,0.0f,c0*factory->outerRadius);
			
			angle0=angle1;
			wAngle0=wAngle1;
			c0=c1;
			s0=s1;
			}
		glEnd();
		
		glPopMatrix();
		
		/* Draw the menu selection ray: */
		glLineWidth(3.0f);
		glColor3f(1.0f,0.0f,0.0f);
		glBegin(GL_LINES);
		glVertex(selectionRay.getOrigin());
		glVertex(selectionRay(getDisplaySize()*Scalar(5)));
		glEnd();
		
		/* Restore OpenGL state: */
		glPopAttrib();
		}
	}
PsychError SCREENFillOval(void)  
{	
	PsychRectType			rect;
	double					numSlices, radius, xScale, yScale, xTranslate, yTranslate, rectY, rectX;
	PsychWindowRecordType	*windowRecord;
	psych_bool				isArgThere, isclassic;
    double					*xy, *colors;
	unsigned char			*bytecolors;
	int						numRects, i, nc, mc, nrsize;
	GLUquadricObj			*diskQuadric;
	double					perfectUpToMaxDiameter;
	static double			perfectUpToMaxDiameterOld = 0;

	//all sub functions should have these two lines
	PsychPushHelp(useString, synopsisString,seeAlsoString);
	if(PsychIsGiveHelp()){PsychGiveHelp();return(PsychError_none);}
	
	//check for superfluous arguments
	PsychErrorExit(PsychCapNumInputArgs(4));   //The maximum number of inputs
	PsychErrorExit(PsychCapNumOutputArgs(0));  //The maximum number of outputs

	//get the window record from the window record argument and get info from the window record
	PsychAllocInWindowRecordArg(kPsychUseDefaultArgPosition, TRUE, &windowRecord);
    isclassic = PsychIsGLClassic(windowRecord);

	perfectUpToMaxDiameter = PsychGetWidthFromRect(windowRecord->clientrect);
	if (PsychGetHeightFromRect(windowRecord->clientrect) < perfectUpToMaxDiameter) perfectUpToMaxDiameter = PsychGetHeightFromRect(windowRecord->clientrect);
	PsychCopyInDoubleArg(4, kPsychArgOptional, &perfectUpToMaxDiameter);

    // Compute number of subdivisions (slices) to provide a perfect oval, i.e., one subdivision for each
    // distance unit on the circumference of the oval.
    numSlices = 3.14159265358979323846 * perfectUpToMaxDiameter;

    if ((perfectUpToMaxDiameter != perfectUpToMaxDiameterOld) || (windowRecord->fillOvalDisplayList == 0)) {
        perfectUpToMaxDiameterOld = perfectUpToMaxDiameter;

        // Destroy old display list so it gets rebuilt with the new numSlices setting:
        if (isclassic && (windowRecord->fillOvalDisplayList != 0)) {
            glDeleteLists(windowRecord->fillOvalDisplayList, 1);
            windowRecord->fillOvalDisplayList = 0;
        }
    }

    // Already cached display list for filled ovals for this windowRecord available?
    if (isclassic && (windowRecord->fillOvalDisplayList == 0)) {
        // Nope. Create our prototypical filled oval:
        // Generate a filled disk of that radius and subdivision and store it in a display list:
        diskQuadric=gluNewQuadric();
        windowRecord->fillOvalDisplayList = glGenLists(1);
        glNewList(windowRecord->fillOvalDisplayList, GL_COMPILE);
        gluDisk(diskQuadric, 0, 1, (int) numSlices, 1);
        glEndList();
        gluDeleteQuadric(diskQuadric);
        // Display list ready for use in this and all future drawing calls for this windowRecord.
    }

	// Query, allocate and copy in all vectors...
	numRects = 4;
	nrsize = 0;
	colors = NULL;
	bytecolors = NULL;
	mc = nc = 0;
	
	// The negative position -3 means: xy coords are expected at position 3, but they are optional.
	// NULL means - don't want a size's vector.
	PsychPrepareRenderBatch(windowRecord, -3, &numRects, &xy, 2, &nc, &mc, &colors, &bytecolors, 0, &nrsize, NULL, FALSE);

	// Only up to one rect provided?
	if (numRects <= 1) {
		// Get the oval and draw it:
		PsychCopyRect(rect, windowRecord->clientrect);
		isArgThere=PsychCopyInRectArg(kPsychUseDefaultArgPosition, FALSE, rect);
		if (isArgThere && IsPsychRectEmpty(rect)) return(PsychError_none);
		numRects = 1;
	}
	else {
		// Multiple ovals provided. Set up the first one:
		PsychCopyRect(rect, &xy[0]);
	}

	// Draw all ovals (one or multiple):
	for (i = 0; i < numRects;) {
		// Per oval color provided? If so then set it up. If only one common color
		// was provided then PsychPrepareRenderBatch() has already set it up.
		if (nc>1) {
			// Yes. Set color for this specific item:
			PsychSetArrayColor(windowRecord, i, mc, colors, bytecolors);
		}

		// Compute drawing parameters for ellipse:
		if (!IsPsychRectEmpty(rect)) {
			//The glu disk object location and size with a  center point and a radius,   
			//whereas FillOval accepts a bounding rect.   Converting from one set of parameters
			//to the other we should careful what we do for rects size of even number of pixels in length.
			PsychGetCenterFromRectAbsolute(rect, &xTranslate, &yTranslate);
			rectY=PsychGetHeightFromRect(rect);
			rectX=PsychGetWidthFromRect(rect);
			if(rectX == rectY){
				xScale=1; 
				yScale=1;
				radius=rectX/2;
			} else if(rectX > rectY){
				xScale=1;
				yScale=rectY/rectX;
				radius=rectX/2;
			} else {
				yScale=1;
				xScale=rectX/rectY;
				radius=rectY/2;
			}

            if (isclassic) {
                // Draw: Set up position, scale and size via matrix transform:
                glPushMatrix();
                glTranslatef((float) xTranslate, (float) yTranslate, (float) 0);
                glScalef((float) (xScale * radius), (float) (yScale * radius), (float) 1);
                // Draw cached disk object (stored in display list):
                glCallList(windowRecord->fillOvalDisplayList);
                glPopMatrix();
            }
            else {
                PsychDrawDisc(windowRecord, (float) xTranslate, (float) yTranslate, (float) 0, (float) radius, (int) numSlices, (float) xScale, (float) yScale, 0, 360);
            }
		}
		
		// Done with this one. Set up the next one, if any...
		i++;
		if (i < numRects) PsychCopyRect(rect, &xy[i*4]);

		// Next oval.
	}
	
	// Mark end of drawing op. This is needed for single buffered drawing:
	PsychFlushGL(windowRecord);

 	//All psychfunctions require this.
	return(PsychError_none);
}
Exemple #16
0
/*
 *  Draw the hand
 *     at (x,y,z)
 *     fingers facing (dx,dy,dz)
 *     up towards (ux,uy,uz)
 */
void hand::drawHand( note n, note prev_n, double t )
{

	vector<double> pt, j, next_pt, prev_pt;
	vector< vector<double> >::iterator j_it;
	finger f = fingers[0]; //dummy assignment to avoid using a constructor
	vector< vector<double> > prev_verts, next_verts, verts;
	vector< vector<double> >::iterator v_it;
	vector< vector< vector<double> > > fingVerts;
	vector< vector< vector<double> > >::iterator f_it;

	// Get current position of all fingers at this time
	if (t<0.1)
		t = t/0.1;
	else
		t =1;
	pt.assign(3,0);
	prev_verts.clear();
	verts.clear();
	fingVerts.clear();
	for (int i=0; i<fingers.size(); i++){
		next_verts  = fingers[i].fVerts;
		prev_verts = this->prevFingers[i].fVerts;
		for (int j=0; j<next_verts.size(); j++){
			prev_pt = prev_verts[j];
			next_pt = next_verts[j];
			pt[0] = next_pt[0]*t + (1-t)*prev_pt[0];
			pt[1] = next_pt[1]*t + (1-t)*prev_pt[1];
			pt[2] = next_pt[2]*t + (1-t)*prev_pt[2];
			verts.push_back(pt);
			pt.assign(3,0);
		}
		fingVerts.push_back(verts);
		verts.clear();
	}

	// Begin drawing  =================================

	// DRAW WRIST (aka base)
	glPushMatrix();
		vector<double> wrist_pt; wrist_pt.assign(3, 0);
		wrist_pt[0]=0; wrist_pt[1]=0; wrist_pt[2]=-(neck_r+buffHelp+baseH);
		glTranslated(this->wrist[0]*t+prevWrist[0]*(1-t),0,0);
		glRotated(-90, 0,0,1);
		glRotated(theta, 0,1,0);
		draw_axes(1,1,1);
		glColor3ub(hRGB[0],hRGB[1],hRGB[2]);

		glTranslated(0,0,baseH);
		glBegin( GL_POLYGON );
			glVertex3d(wrist_pt[0],wrist_pt[1],wrist_pt[2]);
			Vertex(  fingerTh[4]-thHelp, 0, baseLen[4],
						0,0,-(neck_r+buffHelp+baseH) );
			for (int i=0; i<4; i++){
				Vertex(  fingerTh[i], 0, baseLen[i],
							0,0,-(neck_r+buffHelp+baseH) );
			}
		glEnd();
		glTranslated(0,0,-2*baseH);
		glBegin( GL_POLYGON );
			glVertex3d(wrist_pt[0],wrist_pt[1],wrist_pt[2]);
			Vertex(  fingerTh[4]-thHelp, 0, baseLen[4],
						0,0,-(neck_r+buffHelp+baseH) );
			for (int i=0; i<4; i++){
				Vertex(  fingerTh[i], 0, baseLen[i],
							0,0,-(neck_r+buffHelp+baseH) );
			}
		glEnd();

		glBegin( GL_QUAD_STRIP );
			for (int i=0; i<baseVerts.size(); i++){
				pt = baseVerts[i];
				glVertex3d( pt[0],pt[1],pt[2]);
				glVertex3d( pt[0],pt[1],pt[2]+2*baseH);
			}
			pt = baseVerts[0];
			glVertex3d( pt[0],pt[1],pt[2]);
			glVertex3d( pt[0],pt[1],pt[2]+2*baseH);
		glEnd();
	glPopMatrix();

	// DRAW FINGERS
	glColor3ub( hRGB[0], hRGB[1], hRGB[2] );
	for (f_it = fingVerts.begin(); f_it!=fingVerts.end(); f_it++){
		verts = *f_it;
		for (v_it = verts.begin(); v_it!=verts.end()-1; v_it++){
			pt      = *v_it;
			next_pt = *(v_it+1);
			renderCylinder_convenient( pt[0],pt[1],pt[2],
												next_pt[0],next_pt[1],next_pt[2],
												fingRadius, fingSubDiv);
		}
	}



	// DRAW JOINTS
	for (f_it = fingVerts.begin(); f_it!=fingVerts.end(); f_it++){
		verts = *f_it;
		for (v_it = verts.begin(); v_it!=verts.end(); v_it++){
			pt      = *v_it;
			ball( pt[0],pt[1],pt[2],
					jRGB[0],jRGB[1],jRGB[2],
					jointRadius);
		}
	}

	// for (int ii=0; ii<fingers.size(); ii++){
	// 	fingers[ii];
	// 	for (int jj=0; jj<f.joints.size(); jj++){
	// 		j = f.joints[jj];
	// 		ball(j[0],j[1],j[2],
	// 				jRGB[0],jRGB[1],jRGB[2],
	// 				jointRadius);
	// 	}
	// 	ball(f.tip[0],f.tip[1],f.tip[2],
	// 			hRGB[0],hRGB[1],hRGB[2],
	// 			jointRadius);
	// }

	// currentFingers.clear();
	ErrCheck("drawHand");
}
Exemple #17
0
void display(void)
{
   GLfloat no_mat[] = { 0.0, 0.0, 0.0, 1.0 };
   GLfloat mat_ambient[] = { 0.7, 0.7, 0.7, 1.0 };
   GLfloat mat_ambient_color[] = { 0.8, 0.8, 0.2, 1.0 };
   GLfloat mat_diffuse[] = { 0.1, 0.5, 0.8, 1.0 };
   GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 };
   GLfloat no_shininess[] = { 0.0 };
   GLfloat low_shininess[] = { 5.0 };
   GLfloat high_shininess[] = { 100.0 };
   GLfloat mat_emission[] = {0.3, 0.2, 0.2, 0.0};

   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

/*  draw sphere in first row, first column
 *  diffuse reflection only; no ambient or specular
 */
   glPushMatrix();
   glTranslatef (-3.75, 3.0, 0.0);
   glMaterialfv(GL_FRONT, GL_AMBIENT, no_mat);
   glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
   glMaterialfv(GL_FRONT, GL_SPECULAR, no_mat);
   glMaterialfv(GL_FRONT, GL_SHININESS, no_shininess);
   glMaterialfv(GL_FRONT, GL_EMISSION, no_mat);
   glutSolidSphere(1.0, 16, 16);
   glPopMatrix();

/*  draw sphere in first row, second column
 *  diffuse and specular reflection; low shininess; no ambient
 */
   glPushMatrix();
   glTranslatef (-1.25, 3.0, 0.0);
   glMaterialfv(GL_FRONT, GL_AMBIENT, no_mat);
   glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
   glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
   glMaterialfv(GL_FRONT, GL_SHININESS, low_shininess);
   glMaterialfv(GL_FRONT, GL_EMISSION, no_mat);
   glutSolidSphere(1.0, 16, 16);
   glPopMatrix();

/*  draw sphere in first row, third column
 *  diffuse and specular reflection; high shininess; no ambient
 */
   glPushMatrix();
   glTranslatef (1.25, 3.0, 0.0);
   glMaterialfv(GL_FRONT, GL_AMBIENT, no_mat);
   glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
   glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
   glMaterialfv(GL_FRONT, GL_SHININESS, high_shininess);
   glMaterialfv(GL_FRONT, GL_EMISSION, no_mat);
   glutSolidSphere(1.0, 16, 16);
   glPopMatrix();

/*  draw sphere in first row, fourth column
 *  diffuse reflection; emission; no ambient or specular reflection
 */
   glPushMatrix();
   glTranslatef (3.75, 3.0, 0.0);
   glMaterialfv(GL_FRONT, GL_AMBIENT, no_mat);
   glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
   glMaterialfv(GL_FRONT, GL_SPECULAR, no_mat);
   glMaterialfv(GL_FRONT, GL_SHININESS, no_shininess);
   glMaterialfv(GL_FRONT, GL_EMISSION, mat_emission);
   glutSolidSphere(1.0, 16, 16);
   glPopMatrix();

/*  draw sphere in second row, first column
 *  ambient and diffuse reflection; no specular
 */
   glPushMatrix();
   glTranslatef (-3.75, 0.0, 0.0);
   glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
   glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
   glMaterialfv(GL_FRONT, GL_SPECULAR, no_mat);
   glMaterialfv(GL_FRONT, GL_SHININESS, no_shininess);
   glMaterialfv(GL_FRONT, GL_EMISSION, no_mat);
   glutSolidSphere(1.0, 16, 16);
   glPopMatrix();

/*  draw sphere in second row, second column
 *  ambient, diffuse and specular reflection; low shininess
 */
   glPushMatrix();
   glTranslatef (-1.25, 0.0, 0.0);
   glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
   glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
   glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
   glMaterialfv(GL_FRONT, GL_SHININESS, low_shininess);
   glMaterialfv(GL_FRONT, GL_EMISSION, no_mat);
   glutSolidSphere(1.0, 16, 16);
   glPopMatrix();

/*  draw sphere in second row, third column
 *  ambient, diffuse and specular reflection; high shininess
 */
   glPushMatrix();
   glTranslatef (1.25, 0.0, 0.0);
   glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
   glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
   glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
   glMaterialfv(GL_FRONT, GL_SHININESS, high_shininess);
   glMaterialfv(GL_FRONT, GL_EMISSION, no_mat);
   glutSolidSphere(1.0, 16, 16);
   glPopMatrix();

/*  draw sphere in second row, fourth column
 *  ambient and diffuse reflection; emission; no specular
 */
   glPushMatrix();
   glTranslatef (3.75, 0.0, 0.0);
   glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
   glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
   glMaterialfv(GL_FRONT, GL_SPECULAR, no_mat);
   glMaterialfv(GL_FRONT, GL_SHININESS, no_shininess);
   glMaterialfv(GL_FRONT, GL_EMISSION, mat_emission);
   glutSolidSphere(1.0, 16, 16);
   glPopMatrix();

/*  draw sphere in third row, first column
 *  colored ambient and diffuse reflection; no specular
 */
   glPushMatrix();
   glTranslatef (-3.75, -3.0, 0.0);
   glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient_color);
   glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
   glMaterialfv(GL_FRONT, GL_SPECULAR, no_mat);
   glMaterialfv(GL_FRONT, GL_SHININESS, no_shininess);
   glMaterialfv(GL_FRONT, GL_EMISSION, no_mat);
   glutSolidSphere(1.0, 16, 16);
   glPopMatrix();

/*  draw sphere in third row, second column
 *  colored ambient, diffuse and specular reflection; low shininess
 */
   glPushMatrix();
   glTranslatef (-1.25, -3.0, 0.0);
   glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient_color);
   glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
   glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
   glMaterialfv(GL_FRONT, GL_SHININESS, low_shininess);
   glMaterialfv(GL_FRONT, GL_EMISSION, no_mat);
   glutSolidSphere(1.0, 16, 16);
   glPopMatrix();

/*  draw sphere in third row, third column
 *  colored ambient, diffuse and specular reflection; high shininess
 */
   glPushMatrix();
   glTranslatef (1.25, -3.0, 0.0);
   glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient_color);
   glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
   glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
   glMaterialfv(GL_FRONT, GL_SHININESS, high_shininess);
   glMaterialfv(GL_FRONT, GL_EMISSION, no_mat);
   glutSolidSphere(1.0, 16, 16);
   glPopMatrix();

/*  draw sphere in third row, fourth column
 *  colored ambient and diffuse reflection; emission; no specular
 */
   glPushMatrix();
   glTranslatef (3.75, -3.0, 0.0);
   glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient_color);
   glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
   glMaterialfv(GL_FRONT, GL_SPECULAR, no_mat);
   glMaterialfv(GL_FRONT, GL_SHININESS, no_shininess);
   glMaterialfv(GL_FRONT, GL_EMISSION, mat_emission);
   glutSolidSphere(1.0, 16, 16);
   glPopMatrix();

   glFlush();
}
Exemple #18
0
void Sketcher::renderSelection(QGLShaderProgram *shader, Selection *selection)
{
	glPushAttrib(GL_ALL_ATTRIB_BITS);
	glPushClientAttrib(GL_CLIENT_ALL_ATTRIB_BITS);

	selection->getSelectionMask()->bind();

	glMatrixMode(GL_MODELVIEW);
	glPushMatrix();
	glViewport(0, 0, selection->getSelectionMask()->size().width(), selection->getSelectionMask()->size().height());


	glMatrixMode(GL_PROJECTION);
	glPushMatrix();
	glLoadIdentity();
	glOrtho(-1.0, +1.0, -1.0, +1.0, -1.0, +1.0);
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();

	glClearColor(0.0, 1.0, 0.0, 1.0);
	glClear(GL_COLOR_BUFFER_BIT);

	shader->bind();
	shader->setUniformValue("texture", textureIndex);

	//glActiveTexture(GL_TEXTURE3);
	this->createSelectionTexture(selection);
	//glActiveTexture(GL_TEXTURE0);

	glDisable(GL_TEXTURE_2D);

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

	glEnable(GL_COLOR_MATERIAL);
	glColor4f(1.0, 0.0, 1.0, 1.0);
	glBegin(GL_QUADS);
		glVertex2f( 1.0, -1.0);
		glVertex2f(-1.0, -1.0);
		glVertex2f(-1.0,  1.0);
		glVertex2f( 1.0,  1.0);
	glEnd();
	glEnable(GL_COLOR_MATERIAL);

	shader->release();

	selection->getSelectionMask()->release();

	/*QImage p = selection->getSelectionMask()->toImage();
	p.save("c:/users/mindek/documents/a.png");*/

	selection->setRendered();


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

	glPopClientAttrib();
	glPopAttrib();

	emit selectionRendered();
}
Exemple #19
0
static void
draw(void)
{
   static char frbuf[80] = "";

   dojoy();

   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

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

   glPushMatrix();
   calcposobs();

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

   drawbase();
   drawobj();

   glColor3f(1.0, 1.0, 1.0);
   glDisable(GL_TEXTURE_2D);

   glPushMatrix();
   glTranslatef(lightpos[0], lightpos[1], lightpos[2]);
   glCallList(lightdlist);
   glPopMatrix();

   glPopMatrix();

   glDisable(GL_DEPTH_TEST);
   glDisable(GL_FOG);

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

   glColor3f(0.0f, 0.3f, 1.0f);

   if (showcheckmap) {
      glEnable(GL_TEXTURE_2D);
      glBindTexture(GL_TEXTURE_2D, checkid);
      glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);

      glBegin(GL_QUADS);
      glTexCoord2f(1.0f, 0.0f);
      glVertex2i(10, 30);
      glTexCoord2f(1.0f, 1.0f);
      glVertex2i(10 + 90, 30);
      glTexCoord2f(0.0f, 1.0f);
      glVertex2i(10 + 90, 30 + 90);
      glTexCoord2f(0.0f, 0.0f);
      glVertex2i(10, 30 + 90);
      glEnd();

      glDisable(GL_TEXTURE_2D);
      glBegin(GL_LINE_LOOP);
      glVertex2i(10, 30);
      glVertex2i(10 + 90, 30);
      glVertex2i(10 + 90, 30 + 90);
      glVertex2i(10, 30 + 90);
      glEnd();
      glRasterPos2i(105, 65);
      printstring(GLUT_BITMAP_HELVETICA_18, "Plane Texture Map");
   }

   if (showreflectmap) {
      glEnable(GL_TEXTURE_2D);
      glBindTexture(GL_TEXTURE_2D, reflectid);
      glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);

      glBegin(GL_QUADS);
      glTexCoord2f(1.0f, 0.0f);
      glVertex2i(540, 30);
      glTexCoord2f(1.0f, 1.0f);
      glVertex2i(540 + 90, 30);
      glTexCoord2f(0.0f, 1.0f);
      glVertex2i(540 + 90, 30 + 90);
      glTexCoord2f(0.0f, 0.0f);
      glVertex2i(540, 30 + 90);
      glEnd();

      glDisable(GL_TEXTURE_2D);
      glBegin(GL_LINE_LOOP);
      glVertex2i(540, 30);
      glVertex2i(540 + 90, 30);
      glVertex2i(540 + 90, 30 + 90);
      glVertex2i(540, 30 + 90);
      glEnd();
      glRasterPos2i(360, 65);
      printstring(GLUT_BITMAP_HELVETICA_18, "Sphere Texture Map");
   }

   glDisable(GL_TEXTURE_2D);

   glRasterPos2i(10, 10);
   printstring(GLUT_BITMAP_HELVETICA_18, frbuf);
   glRasterPos2i(360, 470);
   printstring(GLUT_BITMAP_HELVETICA_10,
	       "Ray V1.0 Written by David Bucciarelli (tech.hmw@plus.it)");

   if (help)
      printhelp();

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

   updatemaps();

   glutSwapBuffers();

   Frames++;
   {
      GLint t = glutGet(GLUT_ELAPSED_TIME);
      if (t - T0 >= 2000) {
         GLfloat seconds = (t - T0) / 1000.0;
         GLfloat fps = Frames / seconds;
         sprintf(frbuf, "Frame rate: %f", fps);
         T0 = t;
         Frames = 0;
      }
   }
}
Exemple #20
0
void Tp1Application::draw()
{
    if ( mIsShaderOn )
        mShaderProgram->use();
    else
        glUseProgram(EMPTY_SHADER_PROGRAM);

    // Draw Cube
    glPushMatrix();
    {
        if (mAutomaticRotation) 
        {
            mRotationAngleX += 360.0f * (mRotationFreqX / mFramerate);
            mRotationAngleY += 360.0f * (mRotationFreqY / mFramerate);
            mRotationAngleZ += 360.0f * (mRotationFreqZ / mFramerate);

            if (mRotationAngleX >= 360.0f) mRotationAngleX -= 360.0f;
            if (mRotationAngleY >= 360.0f) mRotationAngleY -= 360.0f;
            if (mRotationAngleZ >= 360.0f) mRotationAngleZ -= 360.0f;
        }	

        glRotatef(180.0, 1.0, 0.0, 0.0);
        glRotatef(mRotationAngleX, 1.0, 0.0, 0.0);
        glRotatef(mRotationAngleY, 0.0, 1.0, 0.0);
        glRotatef(mRotationAngleZ, 0.0, 0.0, 1.0);

        glColor4f(0.0, 0.0, 1.0, 1.0);

        glCallList(mCubeListId);
    }
    glPopMatrix();

    glUseProgram(EMPTY_SHADER_PROGRAM); 

    // Draw Axis without shaders
    glPushMatrix();
    {		
        glLineWidth(3.0);

        glBegin(GL_LINES);
        {
            // X axis in red
            glColor4f(1.0, 0.0, 0.0, 1.0);
            glVertex3f(0.0, 0.0, 0.0);
            glVertex3f(1.0f * mAxisScaleFactor, 0.0, 0.0);

            // Y axis in green
            glColor4f(0.0, 1.0, 0.0, 1.0);
            glVertex3f(0.0, 0.0, 0.0);
            glVertex3f(0.0, 1.0f * mAxisScaleFactor, 0.0);

            // Z axis in blue
            glColor4f(0.0, 0.0, 1.0, 1.0);
            glVertex3f(0.0, 0.0, 0.0);
            glVertex3f(0.0, 0.0, 1.0f * mAxisScaleFactor);
        }
        glEnd();
    }
    glPopMatrix();

    if ( mIsShaderOn )
        mShaderProgram->use();
    else
        glUseProgram(EMPTY_SHADER_PROGRAM);
    
    glFlush();
}
 //core elements
 static void arch() {

   int i, numSlices;
   double angle;
   double angInc;

   glPushMatrix();
   glTranslatef(0,0.5,0);
   glScalef(4,1,2);
   glutSolidCube(1);
   glPopMatrix();

   glPushMatrix();
   glTranslatef(-1.5,-1 ,0);
   glScalef(1,4,2);
   glutSolidCube(1);
   glPopMatrix();

   glPushMatrix();
   glTranslatef(1.5, -1,0);
   glScalef(1,4,2);
   glutSolidCube(1);
   glPopMatrix();
	glPushMatrix();
	glMaterialfv(GL_FRONT, GL_AMBIENT, blueWindows);
	glMaterialfv(GL_FRONT, GL_DIFFUSE, blueWindows);
	glTranslatef(0,-1.5,0);
	glScalef(2,3.25,0.125);
	glutSolidCube(1);
	glMaterialfv(GL_FRONT, GL_AMBIENT, brickMat);
	glMaterialfv(GL_FRONT, GL_DIFFUSE, brickMat);
	glPopMatrix();
	glPushMatrix();
	glTranslatef(0,-1.75,0);
	glScalef(3.0,0.25,0.25);
	glutSolidCube(1);
	glPopMatrix();
	glPushMatrix();
	glTranslatef(0.5,-2,0);
	glScalef(0.25,4,0.25);
	glutSolidCube(1);
	glPopMatrix();
	glPushMatrix();
	glTranslatef(-0.5,-2,0);
	glScalef(0.25,4,0.25);
	glutSolidCube(1);
	glPopMatrix();

   numSlices = 20;
   angle = 0;
   angInc = 3.14159/(2 * numSlices);

   for (i = 0; i < numSlices; i++) {

	   glNormal3f(0,0,1);
       glBegin(GL_POLYGON);
       glVertex3f(1,0,1);  // corner
       glVertex3f( cos(angle) , sin(angle)-1, 1);
       glVertex3f( cos(angle+angInc), sin(angle+angInc)-1, 1);
       glEnd();

       glBegin(GL_POLYGON);
       glVertex3f(-1,0,1);  // corner
       glVertex3f(- cos(angle) , sin(angle)-1, 1);
       glVertex3f(- cos(angle+angInc), sin(angle+angInc)-1, 1);
       glEnd();

	   //---
	   glNormal3f(0,0,-1);
       glBegin(GL_POLYGON);
       glVertex3f(1,0,-1);  // corner
       glVertex3f( cos(angle) , sin(angle)-1, -1);
       glVertex3f( cos(angle+angInc), sin(angle+angInc)-1, -1);
       glEnd();

       glBegin(GL_POLYGON);
       glVertex3f(-1,0,-1);  // corner
       glVertex3f(- cos(angle) , sin(angle)-1, -1);
       glVertex3f(- cos(angle+angInc), sin(angle+angInc)-1, -1);
       glEnd();

	   // vault

	   glNormal3f(-cos(angle+angInc/2),-sin(angle+angInc/2),0);


	   glColor3f(0,0,1);
       glBegin(GL_POLYGON);
       glVertex3f(  cos(angle) ,    sin(angle)-1 ,1);  // corner
       glVertex3f( cos(angle) ,       sin(angle)-1, -1);
       glVertex3f( cos(angle+angInc), sin(angle+angInc)-1, -1);
       glEnd();

       glBegin(GL_POLYGON);
       glVertex3f(  cos(angle) ,    sin(angle)-1 ,1);  // corner
       glVertex3f( cos(angle+angInc) ,       sin(angle+angInc)-1, 1);
       glVertex3f( cos(angle+angInc), sin(angle+angInc)-1, -1);
       glEnd();

	   glNormal3f(cos(angle+angInc/2),-sin(angle+angInc/2),0);

       glBegin(GL_POLYGON);
       glVertex3f( - cos(angle) ,    sin(angle)-1 ,1);  // corner
       glVertex3f( -cos(angle) ,       sin(angle)-1, -1);
       glVertex3f( -cos(angle+angInc), sin(angle+angInc)-1, -1);
       glEnd();

       glBegin(GL_POLYGON);
       glVertex3f( - cos(angle) ,    sin(angle)-1 ,1);  // corner
       glVertex3f( -cos(angle+angInc) ,       sin(angle+angInc)-1, 1);
       glVertex3f( -cos(angle+angInc), sin(angle+angInc)-1, -1);
       glEnd();



	   angle += angInc;
   
   }
}
Exemple #22
0
void
ConsoleWindow::drawUILayer() {


    glLineWidth ( 3.0 );

//    _contentWindow.outlineRounded(0.05);
//    _cubeWindow.outlineRounded(0.05);

    Audicle* audi = Audicle::instance();

    double glomod =  fabs( -1.0 + 2.0 * ( m_time * 0.6  - floor(m_time * 0.6 ) ) );

    double xdiv = 0.5 * ( _cubeWindow.right() + _contentWindow.left() ) ;
    glBegin(GL_LINES);
    glColor4d ( 0.2,0.2, 0.2, 1.0 );
    glVertex2d ( xdiv, _cubeWindow.top() - _marginSize );
    glVertex2d ( xdiv, _cubeWindow.bottom() + _marginSize );
    glEnd();


    _sizeBox.outlineRounded();


    glLineWidth(1.5);

    _curLabel.draw( 0.75 );
    _curDisplay.draw( 0.75 );
    
    if ( _active ) { 
        _prevLabel.draw( 0.75 );
        _prevDisplay.draw( 0.75 );
    }

    static char buffer[256];
    double time = the()->shreduler()->now_system;
    int sr = Digitalio::sampling_rate(); //m_sampling_rate;

    int samp = (int) time;
    int sec = samp / sr;
    int min = ( sec / 60 ) ;
    int hr =  ( min / 60 ) ;
    int day = ( hr / 24 );

    samp = samp % sr;
    sec = sec % 60;
    min = min % 60;
    hr = hr % 24;

    if ( day ) sprintf(buffer, "%dd:%02d:%02d:%02d.%05d", day,  hr, min, sec, samp );
    else if ( hr ) sprintf(buffer, "%02d:%02d:%02d.%05d", hr, min, sec, samp );
    else if ( min ) sprintf(buffer, "%02d:%02d.%05d", min, sec, samp );
    else if ( sec ) sprintf(buffer, "%02d.%05d", sec, samp );
    else sprintf(buffer, "%05d", samp );

    _timeDisplay.setLabel( buffer ) ;
    _timeDisplay.fitLabel( 1 );
    _timeDisplay.setw( _timeDisplay.w() * 0.70 );
    _timeDisplay.filledRounded( 0.03 );
    _timeDisplay.drawLabel( 0.75, 1 );
    _timeDisplay.outlineRounded( 0.03 );

    glPushName( _timeLabel.id() );

    Color4D tdark = Color4D( 0.6, 0.9, 0.6, 1.0 );
    Color4D tglow = tdark.interp( _timeLabel.col(), glomod * 1.2  );
    tglow[3] = 1.0;

    _timeLabel.setCol( tglow );

    glBegin( GL_POLYGON );
    _timeLabel.roundVerts( );
    glEnd( );

    _timeLabel.drawLeadedLabel( 0.75, 0.15 );
    _timeLabel.outlineRounded( ); 

    glPopName();

    if ( _active ) { 

        glLineWidth( 3.0 );
        glPushMatrix();
        
        double cubh = _cubeSides[0].h();
        
        glTranslated ( _cubeWindow.center()[0] - cubh * 3.5 , _cubeWindow.center()[1] + cubh * 1.5, 0 );
        
        if ( _cube_swapping )  { 

            double w = ( m_time - _cube_swap_start ) / _cube_swap_span ;
            if ( w > 1.0 ) { 
                _cube_swapping = false ;
                for ( int i = 0 ; i < 6 ; i++ ) 
                    _swapPos[i] = _cubeSides[i].pos();
            }
            else if ( w > 0 ) 
            {
                for ( int i = 0; i < 6 ; i++ ) { 
                    
                    glPushMatrix();
                    glPushName( _cubeSides[i].id() );
                    Point2D animp = _swapPos[i].interp ( _cubeSides[i].pos() , w );
                    
                    glTranslated( animp[0] - _cubeSides[i].pos()[0], \
                                  animp[1] - _cubeSides[i].pos()[1], 0 );
                    
                    _cubeSides[i].drawQuad( 0.75 );
                    
                    glPopName();
                    glPopMatrix();
                }
            }
        }
        
        if ( !_cube_swapping ) {  
            for ( int i = 0 ; i < 6; i++ ) { 
                glPushName( _cubeSides[i].id() );
                _cubeSides[i].drawQuad( 0.75 );
                glPopName();
            }
        }

        t_CKUINT cur = audi->look_here();
        
        Point2D _cube_spot( cubh * 6.0 , -cubh * 1.5 );
        
        glPushMatrix();
        glTranslated ( _cube_spot[0], _cube_spot[1], 0 );
        glScaled  ( 1.5, 1.5, 1.5 );
        glRotatef ( -30, 1.0, 0.0, 0.0 );
        glRotatef ( 30, 0.0, 1.0 ,0.0 );
        
        glPushMatrix();
        glTranslated( 0, 0, -0.5 * cubh );
        glTranslated(-_cubeSides[cur].center()[0], -_cubeSides[cur].center()[1], 0.0  );
        glPushName( _cubeSides[cur].id() );
        
        
        
        Color4D dark = _cubeSides[cur].col().scale(0.75);
        Color4D glow = dark.interp( _cubeSides[cur].col(), glomod * 1.1  );
        glow[3] = 1.0;
        _cubeSides[cur].setCol( glow );
        
        glBegin( GL_QUADS);
        _cubeSides[cur].quadVerts( );
        glEnd( );
        
        _cubeSides[cur].drawLabel( 0.75 );
        _cubeSides[cur].outlineQuad( );
        
//    _cubeSides[cur].drawQuad( 0.75 );
        
        
        glPopName();
        glPopMatrix();
        
        glPushMatrix();
        glRotatef ( 90, 1.0 , 0, 0 );
        t_CKUINT up = audi->look_from( cur, Audicle::UP ) ;
        glTranslated( 0, 0, -0.5 * cubh );
        glTranslated(-_cubeSides[up].center()[0], -_cubeSides[up].center()[1], 0.0  );
        glPushName( _cubeSides[up].id() );
        _cubeSides[up].drawQuad( 0.75 );
        glPopName();
        glPopMatrix();
        
        glPushMatrix();
        glRotatef ( -90, 0.0 , 1.0 , 0 );
        t_CKUINT rt = audi->look_from( cur, Audicle::RIGHT ); 
        glTranslated( 0, 0, -0.5 * cubh );
        glTranslated(-_cubeSides[rt].center()[0], -_cubeSides[rt].center()[1], 0.0  );
        glPushName( _cubeSides[rt].id() );
        _cubeSides[rt].drawQuad( 0.75 );
        glPopName();
        glPopMatrix();
        
        glPopMatrix();
        
        glPopMatrix();

    }


}
Exemple #23
0
// Test a particular primitive mode
static bool
testPrim(GLenum mode, const GLfloat *verts, GLuint count)
{
	GLfloat x, y;
	GLuint facing, fill;
	int drawMode;
	bool pass = true;

	// Loop over polygon mode: filled vs. outline
	for (fill = 0; fill < 2; fill++) {

		glPolygonMode(GL_FRONT_AND_BACK, fill ? GL_LINE : GL_FILL);

		// Loop over drawing mode: glBegin/End vs glDrawArrays vs glDrawElements
		for (drawMode = 0; drawMode < NUM_DRAW_MODES; drawMode++) {

			// Loop over CW vs. CCW winding (should make no difference)
			for (facing = 0; facing < 2; facing++) {

				if (facing == 0) {
					glFrontFace(GL_CCW);
					glCullFace(GL_BACK);
				}
				else {
					glFrontFace(GL_CW);
					glCullFace(GL_FRONT);
				}

				// Position the geometry at 9 different locations to test
				// clipping against the left, right, bottom and top edges of
				// the window.
				// Only the center location will be unclipped.
				for (y = -1.0; y <= 1.0; y += 1.0) {
					for (x = -1.0; x <= 1.0; x += 1.0) {
						bool quad_pass;
						GLfloat badColor[3];

						glPushMatrix();
						glTranslatef(x, y, 0.0);

						glClear(GL_COLOR_BUFFER_BIT);

						switch (drawMode) {
						case BEGIN_END:
							drawBeginEnd(mode, verts, count);
							break;
						case DRAW_ARRAYS:
							drawArrays(mode, verts, count);
							break;
						case DRAW_ELEMENTS:
							drawElements(mode, verts, count);
							break;
						default:
							assert(0);
						}

						glPopMatrix();

						quad_pass = checkResult(badColor);
						pass = pass && quad_pass;
						reportSubtest(mode, drawMode, facing, fill,
							      badColor, x, y, quad_pass);
					}
				}
			}
		}
	}
	return pass;
}
Exemple #24
0
void 
ShellContent::draw() { 
    _fixCanvas();
    _fixView();

    glPushMatrix();
       
    glPushMatrix();
    _viewport.setCols( UI_BASE, Color4D( 1.0,1.0,1.0, 0.8 ), Color4D(0.2, 0.5, 0.2, 0.8 ) );
    _viewport.viewTranslate();
    _viewport.filledQuad();
    glPopMatrix();
    
    _viewport.scale();
    _viewport.viewTranslate();

        
    glColor4d( 0,0,0,0.9);
    glLineWidth (2.0);

    glLineWidth ( _fontWeight );

    //translate to bottom to draw our input line
    glTranslated ( 0, - _viewport.vpH() + _leading * 0.333, 0 );

    glColor4d( 1.0,1.0,0.9,1.0);

    glBegin (GL_QUADS);
    glVertex2d (0.0, 0.0  );
    glVertex2d (0.0, _leading  );
    glVertex2d ( _viewport.vpW(), _leading  );
    glVertex2d ( _viewport.vpW(), 0.0  );
    glEnd();

    //draw current entry
    glColor4d( 0.0,0.0,0,1.0);
    glPushMatrix();
      bufferFont->scale ( _fontScale, _fontAspect );
 //     scaleFont_mono ( _fontScale, _fontAspect );
      glPushMatrix();
      drawPromptLine ( _entry );
      glPopMatrix();
      double ds = bufferFont->length( _prompt + "% " + _entry.substr( 0, _loc.chr ) );
      glTranslated ( ds , 0 , 0 );
      glLineWidth(2.0);
      glColor4d( 1.0,0.0,0,1.0);

      glBegin(GL_LINES);
      glVertex2d ( 0 , bufferFont->height() * -0.2 );
      glVertex2d ( 0 , bufferFont->height() *  1.2 );
      glEnd();

    glPopMatrix();


    if ( !_output->empty() ) { 
        int range = min ( _output->nlines(), 8 );
        glColor4d( 0,0.0,0,0.9);
        glTranslated( 0, _leading * ( range + 1 ) , 0 );
        for ( t_CKUINT i = _output->nlines()-range ; i < _output->nlines() ; i++ ) { 
            
            glTranslated ( 0, -_leading, 0 );
            glPushMatrix();
            bufferFont->scale ( _fontScale, _fontAspect );
            drawPromptLine( _output->line(i) );
            glPopMatrix();
            
        }
    }

    glPopMatrix();

}
Exemple #25
0
static void
draw_textured_cube(void)
{
   static const GLfloat verts[][2] = {
      { -4, -4 },
      {  4, -4 },
      {  4,  4 },
      { -4,  4 }
   };
   static const GLfloat colors[][4] = {
      { 1, 1, 1, 0.5 },
      { 1, 1, 1, 0.5 },
      { 1, 1, 1, 0.5 },
      { 1, 1, 1, 0.5 }
   };
   static const GLfloat texs[][2] = {
      { 0, 0 },
      { 1, 0 },
      { 1, 1 },
      { 0, 1 }
   };
   static const GLfloat xforms[6][4] = {
      {   0, 0, 1, 0 },
      {  90, 0, 1, 0 },
      { 180, 0, 1, 0 },
      { 270, 0, 1, 0 },
      {  90, 1, 0, 0 },
      { -90, 1, 0, 0 }
   };
   GLint i;

   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

   if (blend) {
      glDisable(GL_DEPTH_TEST);
      glEnable(GL_BLEND);
   } else {
      glEnable(GL_DEPTH_TEST);
      glDisable(GL_BLEND);
   }

   glVertexPointer(2, GL_FLOAT, 0, verts);
   glColorPointer(4, GL_FLOAT, 0, colors);
   glTexCoordPointer(2, GL_FLOAT, 0, texs);

   glEnableClientState(GL_VERTEX_ARRAY);
   glEnableClientState(GL_COLOR_ARRAY);
   glEnableClientState(GL_TEXTURE_COORD_ARRAY);

   for (i = 0; i < 6; i++) {
      glPushMatrix();
      glRotatef(xforms[i][0], xforms[i][1], xforms[i][2], xforms[i][3]);
      glTranslatef(0, 0, 4.1);
      glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
      glPopMatrix();
   }

   glDisableClientState(GL_VERTEX_ARRAY);
   glDisableClientState(GL_COLOR_ARRAY);
   glDisableClientState(GL_TEXTURE_COORD_ARRAY);
}
Exemple #26
0
void C3ds::render() {

  ShaderMgr::get().useProgram(shader);
  //glVertexPointer(3,GL_FLOAT,0,vertex);
  //glNormalPointer(GL_FLOAT,0,normal);
  glEnable(GL_TEXTURE_2D);
  //glEnable(GL_LIGHTING);
  //glDisable(GL_BLEND);
  //glEnable(GL_BLEND);
  glEnable(GL_COLOR_MATERIAL);
  glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  glPushMatrix();

  glMaterialfv(GL_FRONT, GL_AMBIENT, (float*) (&ambientColor));
  glMaterialfv(GL_FRONT, GL_DIFFUSE, (float*) (&diffuseColor));
  glMaterialfv(GL_FRONT, GL_SPECULAR, (float*) (&specColor));

  glMaterialf(GL_FRONT, GL_SHININESS, shininess);

  glScalef(scale, scale, scale);
  TextureMgr::get().use(texture);

  glEnableClientState(GL_VERTEX_ARRAY);
  glEnableClientState(GL_NORMAL_ARRAY);
  glBindBufferARB(GL_ARRAY_BUFFER_ARB, buffer[1]);
  glVertexPointer(3, GL_FLOAT, 0, 0);
  glBindBufferARB(GL_ARRAY_BUFFER_ARB, buffer[2]);
  glNormalPointer(GL_FLOAT, 0, 0);
  if (numTexCoords == numVerts) {
    glEnableClientState(GL_TEXTURE_COORD_ARRAY);
    glBindBufferARB(GL_ARRAY_BUFFER_ARB, buffer[3]);
    glTexCoordPointer(2, GL_FLOAT, 0, 0);
  }
  glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, buffer[0]);
  glDrawElements(GL_TRIANGLES, numFaces * 3, GL_UNSIGNED_SHORT, 0);
  glDisableClientState(GL_VERTEX_ARRAY);
  glDisableClientState(GL_NORMAL_ARRAY);
  glDisableClientState(GL_TEXTURE_COORD_ARRAY);

  /*
   glBegin(GL_TRIANGLES);
   
   for(int i=0;i<numFaces;i++)
   {
   //glNormal3f(fnormal[i].x,fnormal[i].y,fnormal[i].z);
   if(texcoord)glTexCoord2f(texcoord[face[i].p1].u*TexCoordUScale,texcoord[face[i].p1].v*TexCoordVScale);
   glNormal3f(normal[face[i].p1].x,normal[face[i].p1].y,normal[face[i].p1].z);
   glVertex3f(vertex[face[i].p1].x,vertex[face[i].p1].y,vertex[face[i].p1].z);
   if(texcoord)glTexCoord2f(texcoord[face[i].p2].u*TexCoordUScale,texcoord[face[i].p2].v*TexCoordVScale);
   glNormal3f(normal[face[i].p2].x,normal[face[i].p2].y,normal[face[i].p2].z);
   glVertex3f(vertex[face[i].p2].x,vertex[face[i].p2].y,vertex[face[i].p2].z);
   if(texcoord)glTexCoord2f(texcoord[face[i].p3].u*TexCoordUScale,texcoord[face[i].p3].v*TexCoordVScale);
   glNormal3f(normal[face[i].p3].x,normal[face[i].p3].y,normal[face[i].p3].z);
   glVertex3f(vertex[face[i].p3].x,vertex[face[i].p3].y,vertex[face[i].p3].z);
   }
   glEnd();
   */
  glPopMatrix();
  glDisable(GL_COLOR_MATERIAL);
  ShaderMgr::get().useNone();
  //glEnable(GL_TEXTURE_2D);
}
Exemple #27
0
void SurfaceSdlGraphicsManager::drawFramebufferOpenGL() {
	// Save current state
	glPushAttrib(GL_TRANSFORM_BIT | GL_ENABLE_BIT | GL_DEPTH_BUFFER_BIT | GL_SCISSOR_BIT);

	// prepare view
	glMatrixMode(GL_PROJECTION);
	glPushMatrix();
	glLoadIdentity();
	glOrtho(0, 1.0, 1.0, 0, 0, 1);

	glMatrixMode(GL_MODELVIEW);
	glPushMatrix();
	glLoadIdentity();

	glMatrixMode(GL_TEXTURE);
	glPushMatrix();
	glLoadIdentity();

	glDisable(GL_LIGHTING);
	glEnable(GL_TEXTURE_2D);
	glDisable(GL_DEPTH_TEST);
	glDepthMask(GL_FALSE);
	glEnable(GL_SCISSOR_TEST);

	glScissor(0, 0, _desktopW, _desktopH);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);

	float texcropX = _frameBuffer->getWidth() / float(_frameBuffer->getTexWidth());
	float texcropY = _frameBuffer->getHeight() / float(_frameBuffer->getTexHeight());

	float offsetX = _gameRect.getTopLeft().getX();
	float offsetY = _gameRect.getTopLeft().getY();
	float sizeX   = _gameRect.getWidth();
	float sizeY   = _gameRect.getHeight();

	glColor4f(1.0, 1.0, 1.0, 1.0);

	glBindTexture(GL_TEXTURE_2D, _frameBuffer->getColorTextureName());
	glBegin(GL_QUADS);
	glTexCoord2f(0, texcropY);
	glVertex2f(offsetX, offsetY);
	glTexCoord2f(texcropX, texcropY);
	glVertex2f(offsetX + sizeX, offsetY);
	glTexCoord2f(texcropX, 0.0);
	glVertex2f(offsetX + sizeX, offsetY + sizeY);
	glTexCoord2f(0.0, 0.0);
	glVertex2f(offsetX, offsetY + sizeY);
	glEnd();

	// Restore previous state
	glMatrixMode(GL_PROJECTION);
	glPopMatrix();

	glMatrixMode(GL_MODELVIEW);
	glPopMatrix();

	glMatrixMode(GL_TEXTURE);
	glPopMatrix();

	glPopAttrib();
}
Exemple #28
0
void Material::SelectMaterial(int nmat, int force)
{
    int i;
  
#ifdef MEGADEBUG
   sprintf (FANTASY_DEBUG_STRING, "->Me piden seleccionar material %d\n",nmat);
   Debug(DEBUG_LEVEL_OVERDEBUG);
#endif  
    
    if((nmat == last_used_material) && (!force))
      return;
    last_used_material = nmat;
    
    
    if((nmat < numero_materiales)  && (nmat >= 0))
    {
            if(materiales[nmat].opaque)		// Materiales opacos
            {

#ifdef MEGADEBUG
   sprintf (FANTASY_DEBUG_STRING, "->Es un material opaco\n");
   Debug(DEBUG_LEVEL_OVERDEBUG);
#endif  

                if(blend_enabled)
                {
                    if(force_always_blend)
                        glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
                    else
                        glDisable(GL_BLEND);

                    glDepthMask(GL_TRUE);
                    blend_enabled=0;
                }
               
            }
            else					// Materiales traslúcidos
            {
                if(!blend_enabled)
                {
                    if(!force_always_blend) glEnable(GL_BLEND);
                    glDepthMask(GL_FALSE);
                    blend_enabled=1;
                }
                
                if(blend_substract_supported) f_glBlendEquationEXT(GL_FUNC_ADD_EXT);
                
                switch(materiales[nmat].blend_type)
                {
                case BLEND_BLEND: glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
                break;
                case BLEND_ADD:   glBlendFunc(GL_SRC_ALPHA,GL_ONE);
                break;
                case BLEND_MULTIPLY: glBlendFunc(GL_DST_COLOR,GL_ZERO);
                break;
                case BLEND_SUB: if(blend_substract_supported)
                		{
                		 glBlendFunc(GL_SRC_ALPHA,GL_ONE);
                	         f_glBlendEquationEXT(GL_FUNC_REVERSE_SUBTRACT_EXT);                	         
                	        }
                break;
                }
            }


            if(materiales[nmat].ntextures)
            {
                    for(i=0;i<materiales[nmat].ntextures;i++)
                    {
                     if(EXTGL_multitexturing)
                      f_glActiveTextureARB(TextureUnits[i]);
		     
		     if(materiales[nmat].texcoordgen[i] != TEXGEN_CUBE_MAP)
		     {
		      glEnable(GL_TEXTURE_2D);
                      ConjuntoTexturas->SeleccionaTextura(materiales[nmat].textures[i]);
                     }
                     
                     
                     // Seleccionamos el tipo de blend de texturas
                     switch(materiales[nmat].multitexblend[i])
                     {
                       case BLEND_ADD: glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_ADD);
                                       break;
                       case BLEND_MODULATE: glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
                                       break;
                       case BLEND_MASK: if(EXTGL_texture_env_combine_supported)
                        		 {                         	
                        		  glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
                        		  glTexEnvf (GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_INTERPOLATE_ARB);                      		  
                                          
                                          glTexEnvf(GL_TEXTURE_ENV,GL_SOURCE0_RGB_ARB,GL_PREVIOUS_ARB);
                                          glTexEnvf(GL_TEXTURE_ENV,GL_OPERAND0_RGB_ARB,GL_SRC_COLOR);
                                          glTexEnvf(GL_TEXTURE_ENV,GL_SOURCE1_RGB_ARB,GL_TEXTURE);
                                          glTexEnvf(GL_TEXTURE_ENV,GL_OPERAND1_RGB_ARB,GL_SRC_COLOR);
                                          glTexEnvf(GL_TEXTURE_ENV,GL_SOURCE2_RGB_ARB,GL_TEXTURE);
                                          glTexEnvf(GL_TEXTURE_ENV,GL_OPERAND2_RGB_ARB,GL_ONE_MINUS_SRC_ALPHA);                                        
                                         }
                                        break;
                       case BLEND_MASK2: if(EXTGL_texture_env_combine_supported)
                        		 {                         	
                        		  glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
                        		  glTexEnvf (GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_INTERPOLATE_ARB);                      		  
                                          
                                          glTexEnvf(GL_TEXTURE_ENV,GL_SOURCE0_RGB_ARB,GL_PREVIOUS_ARB);
                                          glTexEnvf(GL_TEXTURE_ENV,GL_OPERAND0_RGB_ARB,GL_SRC_COLOR);
                                          glTexEnvf(GL_TEXTURE_ENV,GL_SOURCE1_RGB_ARB,GL_TEXTURE);
                                          glTexEnvf(GL_TEXTURE_ENV,GL_OPERAND1_RGB_ARB,GL_SRC_COLOR);
                                          glTexEnvf(GL_TEXTURE_ENV,GL_SOURCE2_RGB_ARB,GL_PREVIOUS_ARB);
                                          glTexEnvf(GL_TEXTURE_ENV,GL_OPERAND2_RGB_ARB,GL_SRC_ALPHA);                                        
                                         }
                                        break;                                        
                       case BLEND_DOT3: if(EXTGL_texture_env_dot3_supported)
                        		{
                                // UNIT 0 
         			// find dot product of N (stored in the texture map) and L (stored
         			// as the PRIMARY_COLOR).
                                 	f_glActiveTextureARB(TextureUnits[i-1]);
                                 	ConjuntoTexturas->SeleccionaTextura(materiales[nmat].textures[i]);
         		         	glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
         			 	glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_DOT3_RGB_ARB); 
               			 	glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_TEXTURE);
         			 	glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR);
           			 	glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_PRIMARY_COLOR_ARB);
         			 	glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND1_RGB_ARB, GL_SRC_COLOR);
                                // UNIT 1
         			// modulate the base texture by N.L        
         			 	f_glActiveTextureARB(TextureUnits[i]);
         			 	ConjuntoTexturas->SeleccionaTextura(materiales[nmat].textures[i-1]);
         			 	glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
         			 	glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_MODULATE);
         			 	glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_PREVIOUS_EXT);
         			 	glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR);
         			 	glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_TEXTURE);
         			 	glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND1_RGB_ARB, GL_SRC_COLOR);                                                         			 
               				}
                            		break;                                                        
                       case BLEND_REPLACE: glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
                                        break;
                        }
                
                        // Seleccionamos el tipo de generaci¢n de coord. 
                        switch(materiales[nmat].texcoordgen[i])
                        {
                        case TEXGEN_UV:
                            glDisable(GL_TEXTURE_GEN_S);
                            glDisable(GL_TEXTURE_GEN_T);
                            glDisable(GL_TEXTURE_GEN_R);
                            if(EXTGL_texture_cube_map_supported) glDisable(GL_TEXTURE_CUBE_MAP_ARB);
                            break;
                        case TEXGEN_EYE_LINEAR:
                            {
                        	GLfloat xplane[]={1.0f,0.0f,0.0f,0.0f};
                        	GLfloat yplane[]={0.0f,1.0f,0.0f,0.0f};
                        	
                             glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
                             glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
                             glEnable(GL_TEXTURE_GEN_S);                         
                             glEnable(GL_TEXTURE_GEN_T);
                             glDisable(GL_TEXTURE_GEN_R);
                             if(EXTGL_texture_cube_map_supported) glDisable(GL_TEXTURE_CUBE_MAP_ARB);
                             xplane[0]=materiales[nmat].linearmultiplier[i];
                             yplane[1]=materiales[nmat].linearmultiplier[i];

			// Lo del glpushmatrix y demás lo cogí de un ejemplo de sgi
			// que estaba colgado por internet. Aún tengo que saber por que
			// funciona asi :)
                             
                             glPushMatrix();
	    		     glMatrixMode(GL_MODELVIEW);
	    		     glLoadIdentity();
	    		     glTexGenfv(GL_S, GL_EYE_PLANE, xplane);
	    		     glTexGenfv(GL_T, GL_EYE_PLANE, yplane);
	    		     glPopMatrix();
                            }
                            break;
                        case TEXGEN_OBJECT_LINEAR:
                            {
                       	     GLfloat xplane[]={1.0f,0.0f,0.0f,0.0f};
                             GLfloat yplane[]={0.0f,1.0f,0.0f,0.0f};
                        	
                             glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
                             glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
                             glEnable(GL_TEXTURE_GEN_S);                         
                             glEnable(GL_TEXTURE_GEN_T);
                             glDisable(GL_TEXTURE_GEN_R);
                             if(EXTGL_texture_cube_map_supported) glDisable(GL_TEXTURE_CUBE_MAP_ARB);
                             xplane[0]=materiales[nmat].linearmultiplier[i];
                             yplane[1]=materiales[nmat].linearmultiplier[i];
                             glTexGenfv(GL_S, GL_OBJECT_PLANE, xplane);
        		     glTexGenfv(GL_T, GL_OBJECT_PLANE, yplane);
                            }
                            
                            break;
                        case TEXGEN_SPHERE_MAP:
                            glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
                            glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
                            glEnable(GL_TEXTURE_GEN_S);
                            glEnable(GL_TEXTURE_GEN_T);
                            glDisable(GL_TEXTURE_GEN_R);
                            if(EXTGL_texture_cube_map_supported) glDisable(GL_TEXTURE_CUBE_MAP_ARB);
                            break;
                        case TEXGEN_CUBE_MAP:              
                            if(EXTGL_texture_cube_map_supported)              
                            {                                                        	
                             glEnable(GL_TEXTURE_CUBE_MAP_ARB); 
                             glDisable(GL_TEXTURE_2D);                            	
                             ConjuntoTexturas->SeleccionaCubeMap(materiales[nmat].textures[i]);
			     glEnable(GL_TEXTURE_GEN_S); 
			     glEnable(GL_TEXTURE_GEN_T); 
			     glEnable(GL_TEXTURE_GEN_R);
                             glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP_ARB); 
			     glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP_ARB); 
			     glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP_ARB); 			     
			    }
			    break;
                        }
                    }
                if(EXTGL_multitexturing) // Deshabilitamos todas menos la 1¦
                {
                    for(i=materiales[nmat].ntextures;i<EXTGL_number_of_texture_units;i++)
                    {
                        f_glActiveTextureARB(TextureUnits[i]);
                        glDisable(GL_TEXTURE_2D);
                        if(EXTGL_texture_cube_map_supported) glDisable(GL_TEXTURE_CUBE_MAP_ARB);
                    }
                }   
                    
	    }

            else
            {
                if(EXTGL_multitexturing)
                {
                    for(i=1;i<EXTGL_number_of_texture_units;i++)
                    {
                        f_glActiveTextureARB(TextureUnits[i]);
                        glDisable(GL_TEXTURE_2D);
                    }
                    f_glActiveTextureARB(TextureUnits[0]);
                }
                ConjuntoTexturas->SeleccionaTextura(0);
            }
        
   
        if(materiales[nmat].twosided)
        {
            if(culling_enabled)
            {
                glDisable(GL_CULL_FACE); // Deshabilitamos el testeo de profundidad
                culling_enabled=0;
            }
        }
        else
        {
            if(!culling_enabled)
            {
                glCullFace(GL_BACK);
                glEnable(GL_CULL_FACE); // Habilitamos el testeo de profundidad
                culling_enabled=1;
            }
        }
      // Finalmente tenemos en cuenta los parámetros para la iluminación
      glMaterialfv(GL_FRONT,GL_SPECULAR,materiales[nmat].specular);  
      glMaterialfv(GL_FRONT,GL_EMISSION,materiales[nmat].emission);
      glMaterialf(GL_FRONT_AND_BACK,GL_SHININESS,materiales[nmat].shininess);

      // Ok, la textura está puesta. Sólo nos falta el shader
      // If there is no shader, shader 0 (NULL) will be selected, meaning no shader program

      
      GLSL_SelectShader(&(materiales[nmat]));
    }
}
Exemple #29
0
void cTilePicker::render()
{
	tileListStartXY = spritePos2D;
	glm::vec2 tilePosXY = tileListStartXY;
	for (int row = 0; row < 2; row++)
	{
		for (int column = 0; column < 3; column++)
		{
			switch (tilePickingList[row][column])
			{
				case 1:
					GLTextureID = tileTextureList[1]->getTexture();
					break;
				case 2:
					GLTextureID = tileTextureList[2]->getTexture();
					break;
				case 3:
					GLTextureID = tileTextureList[3]->getTexture();
					break;
				case 4:
					GLTextureID = tileTextureList[4]->getTexture();
					break;
				case 5:
					GLTextureID = tileTextureList[5]->getTexture();
					break;
				case 6:
					GLTextureID = tileTextureList[6]->getTexture();
					break;
			}
			
			setTextureDimensions(tileTextureList[0]->getTWidth(), tileTextureList[0]->getTHeight());
			setSpriteCentre();

			glPushMatrix();

			glTranslatef(tilePosXY.x, tilePosXY.y, 0.0f);

			glEnable(GL_TEXTURE_2D);
			glBindTexture(GL_TEXTURE_2D, GLTextureID); // Binding of GLtexture name 

			glBegin(GL_QUADS);
			glColor3f(255.0f, 255.0f, 255.0f);
			glTexCoord2f(spriteTexCoordData[0].x, spriteTexCoordData[0].y);
			glVertex2f(0, 0);
			glTexCoord2f(spriteTexCoordData[1].x, spriteTexCoordData[1].y);
			glVertex2f(textureWidth, 0);
			glTexCoord2f(spriteTexCoordData[2].x, spriteTexCoordData[2].y);
			glVertex2f(textureWidth, textureHeight);
			glTexCoord2f(spriteTexCoordData[3].x, spriteTexCoordData[3].y);
			glVertex2f(0, textureHeight);

			glEnd();
			glDisable(GL_TEXTURE_2D);

			glPopMatrix();

			tilePosXY.x += cSprite::textureWidth;
		}
		tilePosXY.x = tileListStartXY.x;
		tilePosXY.y += cSprite::textureHeight;
	}
}
void ScreenTexture::drawImplementation( osg::RenderInfo & renderInfo ) const
{
    if (!_isNeededValidation)
        return;

    _isNeededValidation = false;

    osg::State & state = *renderInfo.getState();
    const osg::Viewport * viewport = state.getCurrentViewport();

#if defined(_SCREEN_TEXTURE_DEBUG_)
    const unsigned texunit = state.getActiveTextureUnit();
    state.setActiveTextureUnit(0);
#endif // _SCREEN_TEXTURE_DEBUG_

    // instead of doing copyTexImage we would do FBO blit operation to ensure it correctly handles multisampled FBO

    // get fbo extension which provides us with the glGenerateMipmapEXT function
#if OSG_MIN_VERSION_REQUIRED(3,3,2)
	osg::GLExtensions * fbo_ext = renderInfo.getState()->get<osg::GLExtensions>();
#else
	osg::FBOExtensions * fbo_ext = osg::FBOExtensions::instance(state.getContextID(), true);
#endif

    // get current draw binding
    GLint oldDrawFBO = 0;
    glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING_EXT, &oldDrawFBO);

    // recreate FBO, is sizes were changed
    if (viewport->width() != _texture->getTextureWidth() || viewport->height() != _texture->getTextureHeight())
    {
        //_resolveFbo = new osg::FrameBufferObject();
        _texture->dirtyTextureObject();
        _texture->setTextureSize(viewport->width(), viewport->height());
        if (_blitBitMask == GL_DEPTH_BUFFER_BIT)
        {
            _resolveFbo->setAttachment(osg::Camera::DEPTH_BUFFER, osg::FrameBufferAttachment(_texture));
            _resolveFbo->setAttachment(osg::Camera::COLOR_BUFFER, osg::FrameBufferAttachment(new osg::RenderBuffer(viewport->width(), viewport->height(), GL_RGB)));
        }
        else if (_blitBitMask == GL_COLOR_BUFFER_BIT)
        {
            _resolveFbo->setAttachment(osg::Camera::COLOR_BUFFER, osg::FrameBufferAttachment(_texture));
        }
    }

    // apply resolve FBO for blit operation
    _resolveFbo->apply(state, osg::FrameBufferObject::DRAW_FRAMEBUFFER);

#if defined(_SCREEN_TEXTURE_DEBUG_)
    GLenum status = fbo_ext->glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
    if (status != GL_FRAMEBUFFER_COMPLETE_EXT)
        OutputDebugString("\nCannot create FBO for texture blitting\n");
#endif // _SCREEN_TEXTURE_DEBUG_

    // blit to the resolve framebuffer.
    fbo_ext->glBlitFramebuffer(
        0, 0, static_cast<GLint>(viewport->width()), static_cast<GLint>(viewport->height()),
        0, 0, static_cast<GLint>(viewport->width()), static_cast<GLint>(viewport->height()),
        _blitBitMask, GL_NEAREST);

    // restore old draw framebuffer
    fbo_ext->glBindFramebuffer(osg::FrameBufferObject::DRAW_FRAMEBUFFER, oldDrawFBO);

    // get depth settings
    if (_settings.valid())
    {
        const osg::Matrix & projection = state.getProjectionMatrix();
        const float 
            znear = projection(3, 2) / (projection(2, 2) - 1.0),
            zfar = projection(3, 2) / (1.0 + projection(2, 2));
        //double left, right, bottom, top, znear, zfar;
        //state.getProjectionMatrix().getFrustum(left, right, bottom, top, znear, zfar);
        
        const osg::Vec2f settings = osg::Vec2f((zfar - znear) / (zfar * znear), -1.0 / znear);
        _settings->set(settings);
    }

#if defined(_SCREEN_TEXTURE_DEBUG_)

    glPushAttrib(GL_LIGHTING_BIT);
    glDisable(GL_LIGHTING);

    glMatrixMode(GL_PROJECTION);
    glPushMatrix();
    glLoadIdentity();

    glEnable(GL_TEXTURE_RECTANGLE);
    glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
    glBegin(GL_QUADS);
        glTexCoord2f(0.0f, 0.0f);
        glVertex2f(0.0f, 0.0f);

        glTexCoord2f(viewport->width(), 0.0f);
        glVertex2f(1.0f, 0.0f);

        glTexCoord2f(viewport->width(), viewport->height());
        glVertex2f(1.0f, 1.0f);

        glTexCoord2f(0.0f, viewport->height());
        glVertex2f(0.0f, 1.0f);
    glEnd();
    glDisable(GL_TEXTURE_RECTANGLE);

    glPopMatrix();
    glMatrixMode(GL_MODELVIEW);

    glPopAttrib();

    state.setActiveTextureUnit(texunit);

    state.checkGLErrors("ScreenTexture");

#endif // _SCREEN_TEXTURE_DEBUG_
}