Example #1
0
void GLWidget::paintGL() {
  if (_modelLighting)
    glEnable(GL_LIGHTING);
  else
    glDisable(GL_LIGHTING);

  glClearColor(_BackgroundColorR, _BackgroundColorG, _BackgroundColorB, 0.0);
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();
  gluLookAt(eyex, eyey, eyez, // camera position
            targetx, targety, targetz,          // target position
            up_vector.x, up_vector.y, up_vector.z);

  float scale_size(1 / 1.5);

	glPushMatrix();
	if (_showFilteredMesh && !filtered_mesh.empty()) {
		glTranslatef(0.6, 0, 0);
		glScalef(scale_size, scale_size, scale_size);
	}
	if (!primary_meshes.empty()) {
		draw_mesh(primary_meshes[0]);
		//draw_mesh_test(primary_meshes[0]);
		//*
		if (vertex_chosen) {
			drawSphereOnVertex(chosen, 0.05);
			drawSphereOnVertex(chosen, 0.14);
			drawSphereOnVertex(chosen, 0.22);
		}
		//*/
	}
	if (_showGrid)
		draw_grid(primary_meshes[0]);
	glPopMatrix();

  if (_showFilteredMesh && !filtered_mesh.empty()) {
    glPushMatrix();
    glTranslatef(-0.5, 0, 0);
    glScalef(scale_size, scale_size, scale_size);
    draw_mesh(filtered_mesh);
    glPopMatrix();
  }

  if (_showAxis) {
    glPushMatrix();
    glScalef(scale_size, scale_size, scale_size);
    draw_axis();
    glPopMatrix();
  }

}
Example #2
0
void Draw::draw_scene() {
  glClearColor(0,0,0,0);
  glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

  glMatrixMode(GL_MODELVIEW); 
  glLoadIdentity();
  gluLookAt(View::CameraPosition.x(),
	    View::CameraPosition.y(),
	    View::CameraPosition.z(),
	    0,0,0,0,1,0);
  
  glEnable(GL_DEPTH_TEST);
  glEnable(GL_NORMALIZE);

  glEnable(GL_LIGHTING);
  glEnable(GL_LIGHT0);
  glEnable(GL_LIGHT1);
  glLightfv(GL_LIGHT0,GL_DIFFUSE,  Vec4f(1,  1,  1, 1));
  glLightfv(GL_LIGHT0,GL_POSITION, Vec4f(0,  0,  1, 0));
  glLightfv(GL_LIGHT1,GL_DIFFUSE,  Vec4f(1,  1,  1, 1));
  glLightfv(GL_LIGHT1,GL_POSITION, Vec4f(0,  0, -1, 0));

  glLightModelf(GL_LIGHT_MODEL_TWO_SIDE,0);
  glShadeModel(GL_SMOOTH);
  glEnable(GL_ALPHA_TEST); //for alpha value: RGBA

  glEnable(GL_COLOR_MATERIAL);

  draw_mesh( TRACKBALL | SELECTED );

  glDisable(GL_LIGHTING);

  glutSwapBuffers();
}
Example #3
0
static void
display()
{
    GLfloat mat[4][4];

    glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glEnable(GL_DEPTH_TEST);

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

    // camera & rotate
    gluLookAt(view_org[0], view_org[1], view_org[2],
          view_tgt[0], view_tgt[1], view_tgt[2],
          0.0, 1.0, 0.0);

    build_rotmatrix(mat, curr_quat);
    glMultMatrixf(&mat[0][0]);

    glBindTexture(GL_TEXTURE_2D, gTexIDs[curr_layer]);

    draw_mesh();

    //glBegin(GL_POLYGON);
    //    glTexCoord2f(0 , 0); glVertex2f(-0.9 , -0.9);
    //    glTexCoord2f(0 , 1); glVertex2f(-0.9 , 0.9);
    //    glTexCoord2f(1 , 1); glVertex2f(0.9 , 0.9);
    //    glTexCoord2f(1 , 0); glVertex2f(0.9 , -0.9);
    //glEnd();

    glutSwapBuffers();
}
Example #4
0
//------------------------------------------------------------------------------
/// Draws a link and descends the hierarchy of child joints and draws any
/// links attached down the kinematic chain
/// Note: No Push or Pop Matrix
void draw_link( Link* link ) {
    GLfloat* material_Ka = (GLfloat*)link->material.ambient.arrayOpenGL();
    GLfloat* material_Kd = (GLfloat*)link->material.diffuse.arrayOpenGL();
    GLfloat* material_Ks = (GLfloat*)link->material.specular.arrayOpenGL();
    GLfloat* material_Ke = (GLfloat*)link->material.emissive.arrayOpenGL();
    GLfloat material_Se = (GLfloat)link->material.shininess;

    glMaterialfv(GL_FRONT, GL_AMBIENT, material_Ka);
    glMaterialfv(GL_FRONT, GL_DIFFUSE, material_Kd);
    glMaterialfv(GL_FRONT, GL_SPECULAR, material_Ks);
    glMaterialfv(GL_FRONT, GL_EMISSION, material_Ke);
    glMaterialf(GL_FRONT, GL_SHININESS, material_Se);

    glLoadMatrixd( link->pose.transform.arrayOpenGL() );

    for( unsigned int geometry_id = 0; geometry_id < link->geometryCount( ); geometry_id++ ) {
        Mesh* mesh = static_cast<Mesh*>( link->geometry( geometry_id ) );
        draw_mesh( mesh );
    }

    for( unsigned int i = 0; i < link->child_joints(); i++ ) {
        Joint* joint = link->child_joint( i );
        draw_link( joint->outboard_link );
    }

}
data_chunk* VDPMLoader::adaptive_refinement_server_rendering()
{
    VDPMMesh::HalfedgeHandle v0v1;
    
    float fovy = viewing_parameters_.fovy();
    
    float tolerance_square = viewing_parameters_.tolerance_square();
    float	tan_value = tanf(fovy / 2.0f);
    
    kappa_square_ = 4.0f * tan_value * tan_value * tolerance_square;
    
    split_counter = 0;
    ecol_counter = 0;
    for ( vfront_.begin(); !vfront_.end(); )
    {
        VHierarchyNodeHandle
        node_handle   = vfront_.node_handle(),
        parent_handle = vhierarchy_.parent_handle(node_handle);
        
        
        if (vhierarchy_.is_leaf_node(node_handle) != true &&
            qrefine(node_handle) == true)
        {
            force_vsplit(node_handle);
        }
        
        else if (vhierarchy_.is_root_node(node_handle) != true &&
                 ecol_legal(parent_handle, v0v1) == true       &&
                 qrefine(parent_handle) != true)
        {
            ++ecol_counter;
            ecol(parent_handle, v0v1);
        }
        
        else
        {
            vfront_.next();
        }
        
    }
    
    // free memories tagged as 'deleted'
    mesh_.garbage_collection(false, true, true);
    mesh_.update_face_normals();
    
    _glHandler->update_viewing_parameters(viewing_parameters_);
    
    if (split_counter > 0 || ecol_counter > 0) {
        draw_mesh();
        return _glHandler->getFrameBufferAsJPEGinMen();
    } else{
        data_chunk * returnData = (data_chunk *) malloc(sizeof(data_chunk));
        char * header = "svrender";
        memcpy(returnData->HEADER, header, 8);
        returnData->size = 0;
        returnData->data = NULL;
        return returnData;
    }
    
}
Example #6
0
void MeshInstance2D::_notification(int p_what) {

	if (p_what == NOTIFICATION_DRAW) {
		if (mesh.is_valid()) {
			draw_mesh(mesh, texture, normal_map);
		}
	}
}
Example #7
0
void Spine::draw()
{
    if (spine)
        draw_spine();
    if (mesh_rings or mesh_longs)
        draw_mesh();
    if (shade)
        draw_shade();
}
Example #8
0
void draw_motivator( ) {
    glPushMatrix();
    glLoadIdentity();

    Matrix4 transform = Matrix4::translationMatrix( motivator.position );
    glLoadMatrixd( transform.arrayOpenGL() );
    draw_mesh( motivator_mesh );

    glPopMatrix();
}
Example #9
0
void 
CubeViewer::
draw_scene(DrawMode _draw_mode)
{
	// clear screen
	glEnable(GL_DEPTH_TEST);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	//glEnable(GL_CULL_FACE);
	
    // first bind the shader
	m_cubeShader.bind(); 
	
	// set parameters to send to the shader
	m_cubeShader.setMatrix4x4Uniform("WorldCameraTransform", m_camera.getTransformation().Inverse());
	m_cubeShader.setMatrix3x3Uniform("WorldCameraNormalTransform", m_camera.getTransformation().Transpose());
	m_cubeShader.setMatrix4x4Uniform("ProjectionMatrix", m_camera.getProjectionMatrix());

    for (std::vector<Mesh3D*>::iterator mIt = m_meshes.begin(); mIt != m_meshes.end(); ++mIt)
    {
        Mesh3D *cube = *mIt;
        
        // besides during we can apply transformations just before rendering:
        // save the original transformation of the cube
        Matrix4 originalTransformation = cube->getTransformation();
        
        // rotate the cube before rendering
        cube->rotateObject(Vector3(0,1,0), M_PI/4);
        
        // send the model parameters to the shader
        m_cubeShader.setMatrix4x4Uniform("ModelWorldTransform", cube->getTransformation() );
        m_cubeShader.setMatrix3x3Uniform("ModelWorldNormalTransform", cube->getTransformation().Inverse().Transpose());
        
        // render the cube
        draw_mesh(cube);
        
        // ((( Exercise 3.6 )))
        
        // then reset the original transformation
        cube->setTransformation( originalTransformation );
    }
	
    // for illustration render a small sphere at the world center
	Matrix4 ident;
	ident.loadIdentity();
	m_cubeShader.setMatrix4x4Uniform("ModelWorldTransform", ident );
	m_cubeShader.setMatrix3x3Uniform("ModelWorldNormalTransform", ident );
	
	glColor3f(1.0,1.0,1.0); // set sphere color to white
	glutSolidSphere( 0.05, 10, 10 );
	
	// finally, unbind the shader
	m_cubeShader.unbind();
		
}
Example #10
0
void Draw::draw_selectable() {
  glClearColor(0.0,0.0,0.0,0);
  glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

  glDisable(GL_TEXTURE_2D);
  glEnable(GL_ALPHA_TEST); //for alpha value: RGBA
  
  glDisable(GL_LIGHTING);

  draw_mesh(SELECTABLE);
}
Example #11
0
static void draw_object(int i, int j, int f, float a)
{
    struct object      *o = get_object(i);
    struct object_mesh *m = NULL;

    float alpha = get_entity_alpha(j) * a;

    init_object(i);

    glPushMatrix();
    {
        /* Apply the local coordinate system transformation. */

        transform_entity(j);

        /* Render this object. */

        if (test_entity_aabb(j) >= 0)
        {
            glPushClientAttrib(GL_CLIENT_VERTEX_ARRAY_BIT);
            glPushAttrib(GL_LIGHTING_BIT | GL_TEXTURE_BIT);
            {
                int k, n = vecnum(o->mv);

                /* Bind a vertex buffer or array. */

                if (GL_has_vertex_buffer_object)
                {
                    glBindBufferARB(GL_ARRAY_BUFFER_ARB, o->buffer);
                    draw_vert(0);
                }
                else
                    draw_vert(vecget(o->vv, 0));

                /* Draw each surface. */

                for (k = 0; k < n; ++k)
                {
                    m = (struct object_mesh *) vecget(o->mv, k);
  
                    if (vecnum(m->fv) > 0 || vecnum(m->ev) > 0)
                        draw_mesh(m, alpha);
                }
            }
            glPopAttrib();
            glPopClientAttrib();
        }

        /* Render all child entities in this coordinate system. */

        draw_entity_tree(j, f, a * get_entity_alpha(j));
    }
    glPopMatrix();
}
Example #12
0
void Canvas::paintEvent(QPaintEvent *event)
{
    Q_UNUSED(event);

    glClearColor(0.0, 0.0, 0.0, 0.0);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glEnable(GL_DEPTH_TEST);

    backdrop->draw();
    if (mesh)  draw_mesh();

    if (status.isNull())    return;

    QPainter painter(this);
    painter.setRenderHint(QPainter::Antialiasing);
    painter.drawText(10, height() - 10, status);
}
Example #13
0
void draw_body( Body& body ) {

    // By requirements can only have one push and pop of OpenGL's matrix stack
    // Therefore do that here then descend the hierarchy
    glPushMatrix();

    glLoadMatrixd( body.pose.transform.arrayOpenGL() );

    for( unsigned int geometry_id = 0; geometry_id < body.geometryCount( ); geometry_id++ ) {
        Mesh* mesh = static_cast<Mesh*>( body.geometry( geometry_id ) );
        draw_mesh( mesh );
    }

    glPopMatrix();

    //sim_pause = true;
}
Example #14
0
void display(void) {
    glClear(GL_COLOR_BUFFER_BIT);

    glPushMatrix();
    glTranslatef(transx, transy, 0.f);
    glRotatef(rotx, 0.f, 1.f, 0.f);
    glRotatef(roty, 1.f, 0.f, 0.f);
    glScalef(10.f,1.f,10.f);
    if (!rgb)
	glColor3f(.31f, .41f, .97f);
    else
	glColor3f(1.f,1.f,1.f);
    glTranslatef(0.f,-1.f,0.f);
    glMatrixMode(GL_TEXTURE);
    glPushMatrix();
    glTranslatef(ttrans[0], ttrans[1], 0.);
    glScalef(10.f, 10.f,1.f);
    draw_mesh();
    glPopMatrix();
    glMatrixMode(GL_MODELVIEW);
    glPopMatrix();
    glutSwapBuffers();
}
Example #15
0
int main(void)
{
   GLuint pid;
   ALLEGRO_DISPLAY *d;
   ALLEGRO_EVENT_QUEUE *queue;
   ALLEGRO_EVENT event;
   int frames = 0;
   double start;

   if (!al_init()) {
      abort_example("Could not init Allegro.\n");
      return 1;
   }

   al_set_new_display_flags(ALLEGRO_OPENGL);
   al_set_new_display_option(ALLEGRO_SAMPLE_BUFFERS, 1, ALLEGRO_SUGGEST);
   al_set_new_display_option(ALLEGRO_SAMPLES, 4, ALLEGRO_SUGGEST);
   d = al_create_display(WINDOW_W, WINDOW_H);
   if (!d) {
      abort_example("Unable to open a OpenGL display.\n");
      return -1;
   }

   if (al_get_display_option(ALLEGRO_SAMPLE_BUFFERS)) {
      printf("With multisampling, level %i\n", al_get_display_option(ALLEGRO_SAMPLES));
   }
   else {
      printf("Without multisampling.\n");
   }

   al_install_keyboard();

   queue = al_create_event_queue();
   al_register_event_source(queue, al_get_keyboard_event_source());
   al_register_event_source(queue, al_get_display_event_source(d));


   if (al_get_opengl_extension_list()->ALLEGRO_GL_ARB_multisample) {
      glEnable(GL_MULTISAMPLE_ARB);
   }

   if (!al_get_opengl_extension_list()->ALLEGRO_GL_ARB_vertex_program) {
      abort_example("This example requires a video card that supports "
                     " the ARB_vertex_program extension.\n");
      return -1;
   }

   glEnable(GL_DEPTH_TEST);
   glShadeModel(GL_SMOOTH);
   glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
   glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
   glDisable(GL_CULL_FACE);

   /* Setup projection and modelview matrices */
   glMatrixMode(GL_PROJECTION);
   glLoadIdentity();
   gluPerspective(45.0, WINDOW_W/(float)WINDOW_H, 0.1, 100.0);

   glMatrixMode(GL_MODELVIEW);
   glLoadIdentity();

   /* Position the camera to look at our mesh from a distance */
   gluLookAt(0.0f, 20.0f, -45.0f, 0.0f, 0.0f, 0.0f, 0, 1, 0);

   create_mesh();

   /* Define the vertex program */
   glEnable(GL_VERTEX_PROGRAM_ARB);
   glGenProgramsARB(1, &pid);
   glBindProgramARB(GL_VERTEX_PROGRAM_ARB, pid);
   glGetError();

   if (al_get_opengl_extension_list()->ALLEGRO_GL_NV_vertex_program2_option) {
      glProgramStringARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
                        strlen(program_nv), program_nv);
   }
   else {
      glProgramStringARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
                        strlen(program), program);
   }

   /* Check for errors */
   if (glGetError()) {
      const char *pgm = al_get_opengl_extension_list()->ALLEGRO_GL_NV_vertex_program2_option
                        ? program_nv : program;
      GLint error_pos;
      const GLubyte *error_str = glGetString(GL_PROGRAM_ERROR_STRING_ARB);
      glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &error_pos);

      abort_example("Error compiling the vertex program:\n%s\n\nat "
            "character: %i\n%s\n", error_str, (int)error_pos,
            pgm + error_pos);
      return -1;
   }


   start = al_current_time();
   while (1) {
      if (!al_event_queue_is_empty(queue)) {
         while (al_get_next_event(queue, &event)) {
            switch (event.type) {
               case ALLEGRO_EVENT_DISPLAY_CLOSE:
                  goto done;

               case ALLEGRO_EVENT_KEY_DOWN:
                  if (event.keyboard.keycode == ALLEGRO_KEY_ESCAPE)
                     goto done;
                  break;
            }
         }
      }

      draw_mesh();
      al_flip_display();
      frames++;
   }

done:
   printf("%.1f FPS\n", frames / (al_current_time() - start));
   glDeleteProgramsARB(1, &pid);
   al_destroy_event_queue(queue);

   return 0;
}
Example #16
0
ENTRYPOINT void
draw_triangle (ModeInfo * mi)
{
    trianglestruct *tp = &triangles[MI_SCREEN(mi)];
    int         d, d2, i, j, delta;

    if (!tp->init_now) {
        draw_mesh(mi, tp, tp->d / 2, MAX_SIZE / tp->d);

        /* The init_now flag will pop up when the scene is complete.
         * Cycles specifies how long to wait, in 1/10 secs.
         TODO: This is wrong for multi-screens ***
         */
        if (tp->init_now) {
#ifndef STANDALONE
            MI_PAUSE(mi) = 2000000;
#else
            if (tp->stage == -1)
            {
                XClearWindow(MI_DISPLAY(mi), MI_WINDOW(mi));
                if (!mono_p)
                {
                    free_colors(mi->xgwa.screen, mi->xgwa.colormap, mi->colors,
                                mi->npixels);
                    mi->npixels =
                        get_integer_resource (mi->dpy, "ncolors", "Integer");
                    make_smooth_colormap (mi->xgwa.screen,
                                          mi->xgwa.visual, mi->xgwa.colormap,
                                          mi->colors, &mi->npixels,
                                          True, &mi->writable_p, True);
                }
            }
#endif
        }
        return;
    }
    if (tp->delta[0] > 0) {
        if (!(++tp->stage)) {
            tp->h[0][0] = (short int) MAX(0, DISPLACE(0, tp->delta[0]));
            tp->h[tp->size][0] = (short int) MAX(0, DISPLACE(0, tp->delta[0]));
            tp->h[0][tp->size] = (short int) MAX(0, DISPLACE(0, tp->delta[0]));
        } else {
            d = 2 << (tp->steps - tp->stage);
            d2 = d / 2;
            delta = tp->delta[tp->stage - 1];

            for (i = 0; i < tp->size; i += d) {
                for (j = 0; j < (tp->size - i); j += d) {
                    tp->h[i + d2][j] = (short int) DISPLACE(tp->h[i][j] +
                                                            tp->h[i + d][j], delta);
                    tp->h[i][j + d2] = (short int) DISPLACE(tp->h[i][j] +
                                                            tp->h[i][j + d], delta);
                    tp->h[i + d2][j + d2] = (short int) DISPLACE(tp->h[i + d][j] +
                                            tp->h[i][j + d], delta);
                }

                tp->init_now = 0;
                tp->i = 0;
                tp->j = 0;
                tp->d = d;
            }
        }
    }
    if (tp->stage == tp->steps) {
        tp->stage = -1;
    }
}
Example #17
0
static void draw(void *void_data) {
    struct cube_data *data = (struct cube_data*) void_data;

    cam_get_mvp(data->mvp, get_main_camera(), data->m);
    draw_mesh(data->shader, data->mesh, data->uniforms);
}
Example #18
0
void draw_model(Model* model) {
    for (int i = 0; i < model->num_meshes; i++) {
        draw_mesh(model->meshes[i], model->shader_program);
    }
}
Example #19
0
void cls_object_draw_mesh(t_object *object)
{
	t_context *C=ctx_get();
	t_draw *draw=C->draw;
	t_scene *scene=C->scene;

	if(object->mesh)
	{
		if( draw->mode == mode_draw || (draw->mode == mode_selection && draw->with_object_selection))
		{
			t_mesh *mesh=object->mesh;

			float x  = (float)(180 * object->rot[0] / PI );
			float y  = (float)(180 * object->rot[1] / PI );
			float z  = (float)(180 * object->rot[2] / PI );
		
			glPushMatrix();

				glTranslatef(object->loc[0],object->loc[1],object->loc[2]);
				glScalef(object->size[0],object->size[1],object->size[2]);
				glRotatef(z,0,0,1);
				glRotatef(y,0,1,0);
				glRotatef(x,1,0,0);

				if(mesh)
				{
					// selected
					if(object->is_selected)
					{
						mesh->state.is_selected=1;
						if(object->is_edit_mode)
						{
							mesh->state.is_edit_mode = 1;
							find_vertex(C,mesh);
						}
						else
						{
							mesh->state.is_edit_mode = 0;
						}
					}
					else
					{
						mesh->state.is_selected = 0;
						mesh->state.is_edit_mode = 0;
					}

					// shader
					if( draw->with_shaders && object->shader) object->shader( object, OBJECT_SHADER_ON);

					// draw
					if(draw->mode_direct)
					{
						draw_mesh_direct(draw,scene,mesh);
					}
					else
					{
						draw_mesh(draw,scene,mesh);
					}

					// shader
					if( draw->with_shaders && object->shader) object->shader( object, OBJECT_SHADER_OFF);

				}

			glPopMatrix();
		}
	}
}