Exemplo n.º 1
0
// load the model, and if the texture has textures, then apply them on the geometric primitives
void Model::loadFile(const char *name)
{
	filename = name;
	// load file
	file = lib3ds_file_load(filename);
	if(!file) // if we were not able to load the file
	{
		// give some errors
		std::string event = "Error loading: ";
		std::string online = "On line 61 in file ";
		online.append(__FILE__);
		event.append(filename);
		std::cout << event << std::endl;
		std::cout << online << std::endl;
		std::cerr << "3DS Error" << std::endl;
		exit(1);
	}
	lib3ds_file_eval(file, 0); // set current frame to 0
	// apply texture to all meshes that have texels
	Lib3dsMesh *mesh;
	for(mesh = file->meshes;mesh != 0;mesh = mesh->next)
	{
		if(mesh->texels) //if there's texels for the mesh
			ApplyTexture(mesh); //then apply texture to it
	}
	if(file->lights) //if we have lights in our model
		CreateLightList();
}
Exemplo n.º 2
0
void ImageManager::LoadPendingTextures()
{
	while (!pendingTextures.empty())
	{
		TextureData *textureData(pendingTextures.back());
		pendingTextures.pop_back();
		ITexture *texture = DownloadTexture(textureData);
		if (texture)
			ApplyTexture(textureData, texture);
		delete textureData;
	}
}
Exemplo n.º 3
0
// load the model, and if the texture has textures, then apply them on the geometric primitives
void Model::LoadFile(const char *name)
{
	if(glIsEnabled(GL_LIGHTING))
	 lightEnabled = true;
	 else
	 lightEnabled = false;
	filename = name;
	// load file
	file = lib3ds_file_load(filename);
	if(!file) // if we were not able to load the file
	{
		// give some errors
		string event = "Error loading: ";
		event.append(filename);
		cout << event << endl;
		exit(1);
	}
	
//Node:
	/* No nodes?  Fabricate nodes to display all the meshes. */  
	if( !file->nodes )  
	{  
		cout << "No node found"<< endl;
		Lib3dsMesh *mesh;  
		Lib3dsNode *node;  
		
		for(mesh = file->meshes; mesh != NULL; mesh = mesh->next)  
		{  
			node = lib3ds_node_new_object();  
			strcpy(node->name, mesh->name);  
			node->parent_id = LIB3DS_NO_PARENT;  
			lib3ds_file_insert_node(file, node);  
		} 
		//goto Node;
	}  
	
	static Lib3dsVector bmin, bmax;  
	static float    sx, sy, sz, size;   /* bounding box dimensions */  
	static float    cx, cy, cz;     /* bounding box center */  
	
 
	lib3ds_file_bounding_box_of_nodes(file, LIB3DS_TRUE, LIB3DS_FALSE, LIB3DS_FALSE, bmin, bmax);  
	sx = bmax[0] - bmin[0];  
	sy = bmax[1] - bmin[1];  
	sz = bmax[2] - bmin[2];  
	size = MAX(sx, sy); size = MAX(size, sz);  
	cx = (bmin[0] + bmax[0])/2;  
	cy = (bmin[1] + bmax[1])/2;  
	cz = (bmin[2] + bmax[2])/2;  
	
	
	
	
	lib3ds_file_eval(file, 0); // set current frame to 0
	// apply texture to all meshes that have texels
	
	
	if (file->lights == NULL)  
	{  
		Lib3dsLight *light;  
		
		light = lib3ds_light_new("light0");  
		light->spot_light = 0;  
		light->see_cone = 0;  
		light->color[0] = light->color[1] = light->color[2] = .6;  
		light->position[0] = cx + size * .75;  
		light->position[1] = cy - size * 1.;  
		light->position[2] = cz + size * 1.5;  
		light->position[3] = 0.;  
		light->outer_range = 100;  
		light->inner_range = 10;  
		light->multiplier = 1;  
		lib3ds_file_insert_light(file, light);  
		
		light = lib3ds_light_new("light1");  
		light->spot_light = 0;  
		light->see_cone = 0;  
		light->color[0] = light->color[1] = light->color[2] = .3;  
		light->position[0] = cx - size;  
		light->position[1] = cy - size;  
		light->position[2] = cz + size * .75;  
		light->position[3] = 0.;  
		light->outer_range = 100;  
		light->inner_range = 10;  
		light->multiplier = 1;  
		lib3ds_file_insert_light(file, light);  
		
		light = lib3ds_light_new("light2");  
		light->spot_light = 0;  
		light->see_cone = 0;  
		light->color[0] = light->color[1] = light->color[2] = .3;  
		light->position[0] = cx;  
		light->position[1] = cy + size;  
		light->position[2] = cz + size;  
		light->position[3] = 0.;  
		light->outer_range = 100;  
		light->inner_range = 10;  
		light->multiplier = 1;  
		lib3ds_file_insert_light(file, light);  
		
	}  
	
	
	
	
	
	
	
	
	Lib3dsMesh *mesh;
	for(mesh = file->meshes;mesh != 0;mesh = mesh->next)
	{
		if(mesh->texels) //if there's texels for the mesh
			ApplyTexture(mesh); //then apply texture to it
	}
	if(file->lights) //if we have lights in our model
		CreateLightList();
}
Exemplo n.º 4
0
void nuiGLPainter::SetState(const nuiRenderState& rState, bool ForceApply)
{
  //TEST_FBO_CREATION();
  NUI_RETURN_IF_RENDERING_DISABLED;

  nuiCheckForGLErrors();

  // blending
  if (ForceApply || mState.mBlending != rState.mBlending)
  {
    mState.mBlending = rState.mBlending;
    if (mState.mBlending)
    {
      glEnable(GL_BLEND);
    }
    else
    {
      glDisable(GL_BLEND);
    }
  }

  if (ForceApply || mState.mBlendFunc != rState.mBlendFunc)
  {
    mState.mBlendFunc = rState.mBlendFunc;
    GLenum src, dst;
    nuiGetBlendFuncFactors(rState.mBlendFunc, src, dst);
    BlendFuncSeparate(src, dst);
    nuiCheckForGLErrors();
  }

  if (ForceApply || mState.mDepthTest != rState.mDepthTest)
  {
    mState.mDepthTest = rState.mDepthTest;
    if (mState.mDepthTest)
      glEnable(GL_DEPTH_TEST);
    else
      glDisable(GL_DEPTH_TEST);
  }
  
  if (ForceApply || mState.mDepthWrite != rState.mDepthWrite)
  {
    mState.mDepthWrite = rState.mDepthWrite;
    glDepthMask(mState.mDepthWrite);
  }
    
  // We don't care about the font in the lower layer of rendering
  //nuiFont* mpFont;
  // 

  ApplyTexture(rState, ForceApply);  
  
  // Rendering buffers:
  if (ForceApply || mState.mColorBuffer != rState.mColorBuffer)
  {
    mState.mColorBuffer = rState.mColorBuffer;
    GLboolean m = mState.mColorBuffer ? GL_TRUE : GL_FALSE;
    glColorMask(m, m, m, m);
    nuiCheckForGLErrors();
  }

  if (mClip.mEnabled || ForceApply)    
  {
    uint32 width = mWidth;
    uint32 height = mHeight;
    
    if (mpSurface)
    {
      width = mpSurface->GetWidth();
      height = mpSurface->GetHeight();
    }
    
    nuiRect clip(mClip);

    int x,y,w,h;
    uint angle = (mpSurface && mpSurface->GetRenderToTexture()) ? 0 : mAngle;
    if (angle == 90)
    {
      x = ToBelow(clip.Top());
      y = ToBelow(clip.Left());
      w = ToBelow(clip.GetHeight());
      h = ToBelow(clip.GetWidth());
    }
    else if (angle == 180)
    {
      w = ToBelow(clip.GetWidth());
      h = ToBelow(clip.GetHeight());
      x = ToBelow(width - w - clip.Left());
      y = ToBelow(clip.Top());
    }
    else if (angle == 270)
    {
      w = ToBelow(clip.GetHeight());
      h = ToBelow(clip.GetWidth());
      x = ToBelow(height - clip.Top() - w);
      y = ToBelow(width - clip.Left() - h);
    }
    else
    {
      NGL_ASSERT(!angle);
      x = ToBelow(clip.Left());
      y = ToBelow(height - clip.Bottom());
      w = ToBelow(clip.GetWidth());
      h = ToBelow(clip.GetHeight());
    }
    //NGL_OUT(_T("To Screen Clip {%d, %d, %d, %d}\n"), x,y,w,h);

    if (!mScissorOn || ForceApply)
    {
      glEnable(GL_SCISSOR_TEST);
      mScissorOn = true;
    }
    
    if (mScissorX != x || mScissorY != y || mScissorW != w || mScissorH != h || ForceApply)
    {
      mScissorX = x;
      mScissorY = y;
      mScissorW = w;
      mScissorH = h;
      
      x *= NUI_SCALE_FACTOR;
      y *= NUI_SCALE_FACTOR;
      w *= NUI_SCALE_FACTOR;
      h *= NUI_SCALE_FACTOR;
      glScissor(x, y, w, h);
    }
    nuiCheckForGLErrors();
  }
  else
  {
    if (mScissorOn || ForceApply)
    {
      glDisable(GL_SCISSOR_TEST);
      mScissorOn = false;
    }
  }

  mState.mClearColor = rState.mClearColor;
  mState.mStrokeColor = rState.mStrokeColor;
  mState.mFillColor = rState.mFillColor;

  nuiCheckForGLErrors();
}