void BillBoardTree::loadTexture(GLuint *tex) {
	char* filename = "pictures/tree.tga";
	int W, H;
	unsigned char* data = (unsigned char*)tga_load(filename, &W, &H, TGA_TRUECOLOR_32);

	glActiveTexture(GL_TEXTURE0);
	glGenTextures(1, tex);
	glBindTexture(GL_TEXTURE_2D, *tex);
	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, W, H, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);

	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_TO_BORDER);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);

	glBindTexture(GL_TEXTURE_2D, 0);
}
void background_load_data() {
	background = malloc(sizeof(background_t));

	background -> xscroll	= 0;
	background -> texture	= tga_load("background.tga");
}
// Initializer. Returns false if something went wrong, like not being able to
// load the texture.
bool
Ground::Initialize(void)
{

    //setupTexDefault("tex/grass.tga", texture_obj); 

    ubyte   *image_data;
    int	    image_height, image_width;
    // Load the image for the texture. The texture file has to be in
    // a place where it will be found.
    if ( ! ( image_data = (ubyte*)tga_load("tex/grass.tga", &image_width,
					   &image_height, TGA_TRUECOLOR_24) ) )
    {
	fprintf(stderr, "Ground::Initialize: Couldn't load grass.tga\n");
	return false;
    }

    // This creates a texture object and binds it, so the next few operations
    // apply to this texture.
    glGenTextures(1, &texture_obj);
    glBindTexture(GL_TEXTURE_2D, texture_obj);

    // This sets a parameter for how the texture is loaded and interpreted.
    // basically, it says that the data is packed tightly in the image array.
    glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

    // This sets up the texture with high quality filtering. First it builds
    // mipmaps from the image data, then it sets the filtering parameters
    // and the wrapping parameters. We want the grass to be repeated over the
    // ground.
    gluBuild2DMipmaps(GL_TEXTURE_2D,3, image_width, image_height, 
		      GL_RGB, GL_UNSIGNED_BYTE, image_data);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
		    GL_NEAREST_MIPMAP_LINEAR);

    // This says what to do with the texture. Modulate will multiply the
    // texture by the underlying color.
    glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); 

    delete[] image_data;

    // Now do the geometry. Create the display list.
    display_list = glGenLists(1);
    glNewList(display_list, GL_COMPILE);
	// Use white, because the texture supplies the color.
	glColor3f(1.0, 1.0, 1.0);

	// The surface normal is up for the ground.
	glNormal3f(0.0, 0.0, 1.0);

	// Turn on texturing and bind the grass texture.
	glEnable(GL_TEXTURE_2D);
	glBindTexture(GL_TEXTURE_2D, texture_obj);

	// Draw the ground as a quadrilateral, specifying texture coordinates.
	glBegin(GL_QUADS);
	    glTexCoord2f(20.0, 20.0);
	    glVertex3f(160.0, 160.0, 0.0);
	    glTexCoord2f(0.0, 20.0);
	    glVertex3f(-160.0, 160.0, 0.0);
	    glTexCoord2f(0.0, 0.0);
	    glVertex3f(-160.0, -160.0, 0.0);
	    glTexCoord2f(20.0, 0.0);
	    glVertex3f(160.0, -160.0, 0.0);
	glEnd();

	// Turn texturing off again, because we don't want everything else to
	// be textured.
	glDisable(GL_TEXTURE_2D);
    glEndList();

    // We only do all this stuff once, when the GL context is first set up.
    initialized = true;

    return true;
}
Exemple #4
0
bool TeaPot::Initialize(double x, double y, double z)
{
    ubyte   *image_data;
    int	    image_height, image_width;
    
    // Load the image for the texture. The texture file has to be in
    // a place where it will be found.
    if ( ! ( image_data = (ubyte*)tga_load("Teapot.tga", &image_width,
                                           &image_height, TGA_TRUECOLOR_24) ) )
    {
        fprintf(stderr, "Ground::Initialize: Couldn't load grass.tga\n");
        return false;
    }
    
    // This creates a texture object and binds it, so the next few operations
    // apply to this texture.
    glGenTextures(1, &texture_obj);
    glBindTexture(GL_TEXTURE_2D, texture_obj);
    
    // This sets a parameter for how the texture is loaded and interpreted.
    // basically, it says that the data is packed tightly in the image array.
    glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
    
    // This sets up the texture with high quality filtering. First it builds
    // mipmaps from the image data, then it sets the filtering parameters
    // and the wrapping parameters. We want the grass to be repeated over the
    // ground.
    gluBuild2DMipmaps(GL_TEXTURE_2D,3, image_width, image_height, GL_RGB, GL_UNSIGNED_BYTE, image_data);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
    
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_LINEAR);
    
    float maximumAnistropy;
    //get the value
    glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &maximumAnistropy);
    glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, maximumAnistropy);
    
    //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_LINEAR);
    
    // This says what to do with the texture. Modulate will multiply the
    // texture by the underlying color.
    glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
    
    // Now do the geometry. Create the display list.
    display_list = glGenLists(1);
    glNewList(display_list, GL_COMPILE);
    
    //glColor3f(119/255.0f,11/255.0f,0);
    
    glDisable(GL_CULL_FACE);
    
    // The surface normal is up for the ground.
	glNormal3f(0.0, 0.0, 1.0);
    
    glRotated(90, 1, 0, 0);
    
    glEnable(GL_TEXTURE_2D);
	glBindTexture(GL_TEXTURE_2D, texture_obj);
    glutSolidTeapot(3);
    glDisable(GL_TEXTURE_2D);
    glEnable(GL_CULL_FACE);
    
    glEndList();
    
    // We only do all this stuff once, when the GL context is first set up.
    initialized = true;
    
    return true;
}
Exemple #5
0
// Initializer. Would return false if anything could go wrong.
bool
Track::Initialize(void)
{
    CubicBspline    refined(3, true);
    int             n_refined;
    float           p[3];
    int             i;

    // Create the track spline.
    track = new CubicBspline(3, true);
    for ( i = 0 ; i < TRACK_NUM_CONTROLS ; i++ )
        track->Append_Control(TRACK_CONTROLS[i]);

    // Refine it down to a fixed tolerance. This means that any point on
    // the track that is drawn will be less than 0.1 units from its true
    // location. In fact, it's even closer than that.
    track->Refine_Tolerance(refined, 0.1f);
    n_refined = refined.N();

    // Create the display list for the track - just a set of line segments
    // We just use curve evaluated at integer paramer values, because the
    // subdivision has made sure that these are good enough.
    track_list = glGenLists(1);
    glNewList(track_list, GL_COMPILE);
        glColor3f(1.0f, 1.0, 1.0f);
        glBegin(GL_LINE_STRIP);
            for ( i = 0 ; i <= n_refined ; i++ )
            {
                refined.Evaluate_Point((float)i, p);
                glVertex3fv(p);
            }
        glEnd();
    glEndList();

    ubyte   *image_data;
    int     image_height, image_width;

    // Load the image for the texture. The texture file has to be in
    // a place where it will be found.
    if ( ! ( image_data = (ubyte*)tga_load("res/smiley.tga", &image_width,
                                           &image_height, TGA_TRUECOLOR_24) ) )
    {
        fprintf(stderr, "Track::Initialize: Couldn't load smiley.tga\n");
        return false;
    }

    // This creates a texture object and binds it, so the next few operations
    // apply to this texture.
    glGenTextures(1, &texture_obj);
    glBindTexture(GL_TEXTURE_2D, texture_obj);

    // This sets a parameter for how the texture is loaded and interpreted.
    // basically, it says that the data is packed tightly in the image array.
    glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

    // This sets up the texture with high quality filtering. First it builds
    // mipmaps from the image data, then it sets the filtering parameters
    // and the wrapping parameters. We want the grass to be repeated over the
    // ground.
    gluBuild2DMipmaps(GL_TEXTURE_2D,3, image_width, image_height,
                      GL_RGB, GL_UNSIGNED_BYTE, image_data);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
                    GL_NEAREST_MIPMAP_LINEAR);

    // This says what to do with the texture. Modulate will multiply the
    // texture by the underlying color.
    glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

    // Set up the train. At this point a cube is drawn. NOTE: The
    // x-axis will be aligned to point along the track. The origin of the
    // train is assumed to be at the bottom of the train.
    train_list = glGenLists(1);
    glNewList(train_list, GL_COMPILE);
        glColor3f(1.0, 1.0, 1.0);

        glEnable(GL_TEXTURE_2D);

        glBindTexture(GL_TEXTURE_2D, texture_obj);
        glBegin(GL_QUADS);

            glNormal3f(0.0f, 0.0f, -1.0f);
            glTexCoord2f(0.0, 0.0);
            glVertex3f(0.5f, -0.5f, 0.0f);
            glTexCoord2f(0.0, 1.0);
            glVertex3f(-0.5f, -0.5f, 0.0f);
            glTexCoord2f(1.0, 1.0);
            glVertex3f(-0.5f, 0.5f, 0.0f);
            glTexCoord2f(1.0, 0.0);
            glVertex3f(0.5f, 0.5f, 0.0f);

            glNormal3f(0.0f, 0.0f, 1.0f);
            glTexCoord2f(0.0, 0.0);
            glVertex3f(0.5f, 0.5f, 1.0f);
            glTexCoord2f(0.0, 1.0);
            glVertex3f(-0.5f, 0.5f, 1.0f);
            glTexCoord2f(1.0, 1.0);
            glVertex3f(-0.5f, -0.5f, 1.0f);
            glTexCoord2f(1.0, 0.0);
            glVertex3f(0.5f, -0.5f, 1.0f);

            glNormal3f(1.0f, 0.0f, 0.0f);
            glTexCoord2f(0.0, 0.0);
            glVertex3f(0.5f, 0.5f, 0.0f);
            glTexCoord2f(0.0, 1.0);
            glVertex3f(0.5f, 0.5f, 1.0f);
            glTexCoord2f(1.0, 1.0);
            glVertex3f(0.5f, -0.5f, 1.0f);
            glTexCoord2f(1.0, 0.0);
            glVertex3f(0.5f, -0.5f, 0.0f);

            glNormal3f(-1.0f, 0.0f, 0.0f);
            glTexCoord2f(0.0, 0.0);
            glVertex3f(-0.5f, 0.5f, 1.0f);
            glTexCoord2f(0.0, 1.0);
            glVertex3f(-0.5f, 0.5f, 0.0f);
            glTexCoord2f(1.0, 1.0);
            glVertex3f(-0.5f, -0.5f, 0.0f);
            glTexCoord2f(1.0, 0.0);
            glVertex3f(-0.5f, -0.5f, 1.0f);

            glNormal3f(0.0f, 1.0f, 0.0f);
            glTexCoord2f(0.0, 0.0);
            glVertex3f(0.5f, 0.5f, 1.0f);
            glTexCoord2f(0.0, 1.0);
            glVertex3f(0.5f, 0.5f, 0.0f);
            glTexCoord2f(1.0, 1.0);
            glVertex3f(-0.5f, 0.5f, 0.0f);
            glTexCoord2f(1.0, 0.0);
            glVertex3f(-0.5f, 0.5f, 1.0f);

            glNormal3f(0.0f, -1.0f, 0.0f);
            glTexCoord2f(0.0, 0.0);
            glVertex3f(0.5f, -0.5f, 0.0f);
            glTexCoord2f(0.0, 1.0);
            glVertex3f(0.5f, -0.5f, 1.0f);
            glTexCoord2f(1.0, 1.0);
            glVertex3f(-0.5f, -0.5f, 1.0f);
            glTexCoord2f(1.0, 0.0);
            glVertex3f(-0.5f, -0.5f, 0.0f);
        glEnd();

        glDisable(GL_TEXTURE_2D);
    glEndList();

    initialized = true;

    return true;
}