Exemple #1
0
/*****************************************************************************
  Routine:  void event_display()

        returns        	: void
  Description          	: CallBack function for display
*****************************************************************************/
void event_display(void) 
{

	if(running)
	{
		nTime = glutGet(GLUT_ELAPSED_TIME);
		if((nTime-nLastTime) >= frameinterval)
		{
			GenTexture();
			nLastTime = nTime;
		}
	}

	
	glClear(GL_COLOR_BUFFER_BIT);
    glBindTexture(GL_TEXTURE_2D, textureid);
    glPushMatrix();
    glBegin(GL_POLYGON);
	glTexCoord2f(0.0, (1-relheight));
	glVertex2f(-1.0, -1.0);					// left top
	glTexCoord2f(relwidth, (1-relheight));
	glVertex2f(1.0, -1.0);					// right top
	glTexCoord2f(relwidth, 1.0);
	glVertex2f(1.0, 1.0);					// right bottom
	glTexCoord2f(0.0, 1.0);
	glVertex2f(-1.0, 1.0);					// left bottom
    glEnd();
    glPopMatrix();
    glutSwapBuffers();

	glBindTexture(GL_TEXTURE_2D, 0);

}
Exemple #2
0
void Texture::GBLTexture()
{
	GenTexture();
	BindTexture();
	if (m_filePath != NULL)
	{
		LoadTexture();
	}
	else
	{
		LOG_D("Texture.cpp: m_filePath == Nulll\n");
	}
}
Exemple #3
0
bool Texture::Load(const std::string & path, const TextureInfo & info, std::ostream & error)
{
	if (m_id)
	{
		error << "Tried to double load texture " << path << std::endl;
		return false;
	}

	if (!info.data && path.empty())
	{
		error << "Tried to load a texture with an empty name" << std::endl;
		return false;
	}

	if (!info.data && LoadDDS(path, info, error))
		return true;

	m_cube = info.cube;
	if (m_cube)
	{
		return LoadCube(path, info, error);
	}

	SDL_Surface * orig_surface = 0;
	if (info.data)
	{
		Uint32 rmask, gmask, bmask, amask;
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
		rmask = 0xff000000;
		gmask = 0x00ff0000;
		bmask = 0x0000ff00;
		amask = 0x000000ff;
#else
		rmask = 0x000000ff;
		gmask = 0x0000ff00;
		bmask = 0x00ff0000;
		amask = 0xff000000;
#endif
		orig_surface = SDL_CreateRGBSurfaceFrom(
			info.data, info.width, info.height,
			info.bytespp * 8, info.width * info.bytespp,
			rmask, gmask, bmask, amask);
	}
	if (!orig_surface)
	{
		orig_surface = IMG_Load(path.c_str());
		if (!orig_surface)
		{
			error << "Error loading texture file: " << path << std::endl;
			error << IMG_GetError() << std::endl;
			return false;
		}
	}

	SDL_Surface * surface = orig_surface;
	if (surface)
	{
		m_scale = Scale(info.maxsize, orig_surface->w, orig_surface->h);
		float scalew = m_scale;
		float scaleh = m_scale;

		// scale to power of two if necessary
		bool norescale = (IsPowerOfTwo(orig_surface->w) && IsPowerOfTwo(orig_surface->h)) ||
					(info.npot && (GLEW_VERSION_2_0 || GLEW_ARB_texture_non_power_of_two));

		if (!norescale)
		{
			int maxsize = 2048;
			int new_w = orig_surface->w;
			int new_h = orig_surface->h;

			if (!IsPowerOfTwo(orig_surface->w))
			{
				for (new_w = 1; new_w <= maxsize && new_w <= orig_surface->w * m_scale; new_w = new_w * 2);
			}

			if (!IsPowerOfTwo(orig_surface->h))
			{
				 for (new_h = 1; new_h <= maxsize && new_h <= orig_surface->h * m_scale; new_h = new_h * 2);
			}

			scalew = ((float)new_w + 0.5) / orig_surface->w;
			scaleh = ((float)new_h + 0.5) / orig_surface->h;
		}

		// scale texture down if necessary
		if (scalew < 1.0 || scaleh < 1.0)
		{
			surface = zoomSurface(orig_surface, scalew, scaleh, SMOOTHING_ON);
		}

		// store dimensions
		m_w = surface->w;
		m_h = surface->h;

		GenTexture(surface, info, m_id, m_alpha, error);
	}

	// free the texture surface separately if it's a scaled copy of the original
	if (surface && surface != orig_surface )
	{
		SDL_FreeSurface(surface);
	}

	// free the original surface if it's not a custom surface (used for the track map)
	if (!info.data && orig_surface)
	{
		SDL_FreeSurface(orig_surface);
	}

	return true;
}
Exemple #4
0
bool TEXTURE::Load(const std::string & path, const TEXTUREINFO & info, std::ostream & error)
{
	if (id)
	{
		error << "Tried to double load texture " << path << std::endl;
		return false;
	}

	if (path.empty() && !info.data)
	{
		error << "Tried to load a texture with an empty name" << std::endl;
		return false;
	}

	id = 0;
	cube = info.cube;
	if (info.cube && info.verticalcross)
	{
		return LoadCubeVerticalCross(path, info, error);
	}
	else if (info.cube)
	{
		return LoadCube(path, info, error);
	}

	SDL_Surface * orig_surface = 0;
	if (info.data)
	{
		Uint32 rmask, gmask, bmask, amask;
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
		rmask = 0xff000000;
		gmask = 0x00ff0000;
		bmask = 0x0000ff00;
		amask = 0x000000ff;
#else
		rmask = 0x000000ff;
		gmask = 0x0000ff00;
		bmask = 0x00ff0000;
		amask = 0xff000000;
#endif
		orig_surface = SDL_CreateRGBSurfaceFrom(
							info.data, info.width, info.height,
							info.bytespp * 8, info.width * info.bytespp,
							rmask, gmask, bmask, amask);
	}
	if (!orig_surface)
	{
		orig_surface = IMG_Load(path.c_str());
		if (!orig_surface)
		{
			error << "Error loading texture file: " << path << std::endl;
			return false;
		}
	}

	SDL_Surface * texture_surface = orig_surface;
	if (orig_surface)
	{
	    origw = texture_surface->w;
        origh = texture_surface->h;

		//scale to power of two if necessary
		bool norescale = (IsPowerOfTwo(orig_surface->w) && IsPowerOfTwo(orig_surface->h)) ||
					(info.npot && (GLEW_VERSION_2_0 || GLEW_ARB_texture_non_power_of_two));
		if (!norescale)
	    {
			int maxsize = 2048;
	        int newx = GetPowerOfTwo(orig_surface->w, maxsize);
	        int newy = GetPowerOfTwo(orig_surface->h, maxsize);
	        float scalew = ((float)newx+0.5) / orig_surface->w;
	        float scaleh = ((float)newy+0.5) / orig_surface->h;

	        SDL_Surface * pot_surface = zoomSurface(orig_surface, scalew, scaleh, SMOOTHING_ON);

	        assert(IsPowerOfTwo(pot_surface->w));
	        assert(IsPowerOfTwo(pot_surface->h));

	        SDL_FreeSurface(orig_surface);
	        orig_surface = pot_surface;
	        texture_surface = orig_surface;
	    }

		//scale texture down if necessary
		scale = Scale(info.maxsize, orig_surface->w, orig_surface->h);
		if (scale < 1.0)
		{
			texture_surface = zoomSurface(orig_surface, scale, scale, SMOOTHING_ON);
		}

		//store dimensions
		w = texture_surface->w;
		h = texture_surface->h;

		GenTexture(texture_surface, info, id, alpha, error);
	}

	//free the texture surface separately if it's a scaled copy of the original
	if (texture_surface != orig_surface && texture_surface)
	{
		SDL_FreeSurface(texture_surface);
	}

	//free the original surface if it's not a custom surface (used for the track map)
	if (!info.data && orig_surface)
	{
		SDL_FreeSurface(orig_surface);
	}

	return true;
}
Exemple #5
0
GLuint GfxContext::LoadTextureDDS(const char* filePath)
{
    GLuint texName = GenTexture();
    if(texName == 0)
    {
        return 0;
    }

    gli::texture2D tex(gli::load_dds(filePath));
    if(tex.empty())
    {
        DeleteTexture(texName);
        return 0;
    }

    glBindTexture(GL_TEXTURE_2D, texName);

    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, GLuint(tex.levels() - 1));

    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_R, GL_RED);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_G, GL_GREEN);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_B, GL_BLUE);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_A, GL_ALPHA);

    glTexStorage2D(
        GL_TEXTURE_2D,
        GLuint(tex.levels()),
        GLenum(gli::internalFormat(tex.format())),
        GLsizei(tex.dimensions().x),
        GLsizei(tex.dimensions().y));

    if(gli::is_compressed(tex.format()))
    {
        for(gli::texture2D::size_type level = 0; level < tex.levels(); ++level)
        {
            glCompressedTexSubImage2D(GL_TEXTURE_2D,
                GLint(level),
                0, 0,
                GLsizei(tex[level].dimensions().x),
                GLsizei(tex[level].dimensions().y),
                GLenum(gli::internal_format(tex.format())),
                GLsizei(tex[level].size()),
                tex[level].data());
        }
    }
    else
    {
        for(gli::texture2D::size_type level = 0; level < tex.levels(); ++level)
        {
            glTexSubImage2D(GL_TEXTURE_2D,
                GLint(level),
                0, 0,
                GLsizei(tex[level].dimensions().x),
                GLsizei(tex[level].dimensions().y),
                GLenum(gli::external_format(tex.format())),
                GLenum(gli::type_format(tex.format())),
                tex[level].data());
        }
    }

    return texName;
}
Exemple #6
0
bool TEXTURE::Load(const std::string & path, const TEXTUREINFO & info, std::ostream & error)
{
	if (id)
	{
		error << "Tried to double load texture " << path << std::endl;
		return false;
	}

	if (path.empty() && !info.surface)
	{
		error << "Tried to load a texture with an empty name" << std::endl;
		return false;
	}

	id = 0;
	if (info.cube)
	{
		cube = true;
		return LoadCube(path, info, error);
	}

	SDL_Surface * orig_surface = info.surface;
	if (!orig_surface)
	{
		orig_surface = IMG_Load(path.c_str());
		if (!orig_surface)
		{
			error << "Error loading texture file: " << path << std::endl;
			return false;
		}
	}

	SDL_Surface * texture_surface(orig_surface);
	if (orig_surface)
	{
	    origw = texture_surface->w;
        origh = texture_surface->h;

		//scale to power of two if necessary
		bool norescale = (IsPowerOfTwo(orig_surface->w) && IsPowerOfTwo(orig_surface->h)) ||
					(info.npot && (GLEW_VERSION_2_0 || GLEW_ARB_texture_non_power_of_two));
		if (!norescale)
	    {
	        int newx = orig_surface->w;
	        int maxsize = 2048;
	        if (!IsPowerOfTwo(orig_surface->w))
	        {
	            for (newx = 1; newx <= maxsize && newx <= orig_surface->w; newx = newx * 2)
	            {
	            }
	        }

	        int newy = orig_surface->h;
	        if (!IsPowerOfTwo(orig_surface->h))
	        {
	            for (newy = 1; newy <= maxsize && newy <= orig_surface->h; newy = newy * 2)
	            {
	            }
	        }

	        float scalew = ((float)newx+0.5) / orig_surface->w;
	        float scaleh = ((float)newy+0.5) / orig_surface->h;

	        SDL_Surface * pot_surface = zoomSurface (orig_surface, scalew, scaleh, SMOOTHING_ON);

	        assert(IsPowerOfTwo(pot_surface->w));
	        assert(IsPowerOfTwo(pot_surface->h));

	        SDL_FreeSurface(orig_surface);
	        orig_surface = pot_surface;
	        texture_surface = orig_surface;
	    }

		//scale texture down if necessary
		scale = Scale(info.size, orig_surface->w, orig_surface->h);
		if (scale < 1.0)
		{
			texture_surface = zoomSurface (orig_surface, scale, scale, SMOOTHING_ON);
		}

		//store dimensions
		w = texture_surface->w;
		h = texture_surface->h;

		GenTexture(texture_surface, info, id, alpha, error);
	}

	//free the texture surface separately if it's a scaled copy of the original
	if (texture_surface != orig_surface && texture_surface)
	{
		SDL_FreeSurface(texture_surface);
	}

	//free the original surface if it's not a custom surface (used for the track map)
	if (!info.surface && orig_surface)
	{
		SDL_FreeSurface(orig_surface);
	}

	return true;
}
Exemple #7
0
/*****************************************************************************
  Routine:  void event_specialkey(int key, int x, int y)

        returns        	: void
  Description          	: CallBack function for KeyHit
*****************************************************************************/
void event_specialkey(int key, int x, int y)
{
    switch(key) {

	case GLUT_KEY_PAGE_UP :
						framerate = framerate*TRICK_MODE_FAST_FWD;
						if (framerate > TRICK_MODE_MAXFRAMERATE)
							framerate = TRICK_MODE_MAXFRAMERATE;
						frameinterval = (int)((float)1000*(framenum)/framerate)-(int)((float)1000*(framenum-1)/framerate);
						nLastTime = -frameinterval;
						nTime = 0;
						break;

    case GLUT_KEY_PAGE_DOWN :
						framerate = framerate/TRICK_MODE_FAST_FWD;
						if (framerate< TRICK_MODE_MINFRAMERATE)
							framerate = TRICK_MODE_MINFRAMERATE;
						frameinterval = (int)((float)1000*(framenum)/framerate)-(int)((float)1000*(framenum-1)/framerate);
						nLastTime = -frameinterval;
						nTime = 0;
						break;


	case GLUT_KEY_RIGHT :
						framerate = framerate*TRICK_MODE_FAST_FWD;
						if (framerate > TRICK_MODE_MAXFRAMERATE)
							framerate = TRICK_MODE_MAXFRAMERATE;
						frameinterval = (int)((float)1000*(framenum)/framerate)-(int)((float)1000*(framenum-1)/framerate);
						nLastTime = -frameinterval;
						nTime = 0;
						break;

    case GLUT_KEY_LEFT :
						framerate = framerate/TRICK_MODE_FAST_FWD;
						if (framerate< TRICK_MODE_MINFRAMERATE)
							framerate = TRICK_MODE_MINFRAMERATE;
						frameinterval = (int)((float)1000*(framenum)/framerate)-(int)((float)1000*(framenum-1)/framerate);
						nLastTime = -frameinterval;
						nTime = 0;
						break;


    case GLUT_KEY_HOME :
						if(!feof(infile1))
		   					fseek(infile1, 0, SEEK_SET);
						else
						{
							fclose(infile1);
							fopen(infile1_name, "rb");
							fseek(infile1, 0, SEEK_SET);
						}
						if(bTwoFiles)
						{
							if(!feof(infile2))
								fseek(infile2, 0, SEEK_SET);
							else
							{
								fclose(infile2);
								fopen(infile2_name, "rb");
								fseek(infile2, 0, SEEK_SET);
							}
						}
						framenum = 0;
						running = 0;
						GenTexture();
						nLastTime = -frameinterval;
						nTime = 0;
						break;

    default: break;
    }
	event_display();
    glutPostRedisplay();
}