~ubuntu-branches/ubuntu/lucid/graphviz/lucid-updates

« back to all changes in this revision

Viewing changes to lib/glcomp/glcomptexture.c

  • Committer: Bazaar Package Importer
  • Author(s): Bryce Harrington
  • Date: 2008-06-19 20:23:23 UTC
  • mfrom: (1.2.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20080619202323-ls23h96ntj9ny94m
Tags: 2.18-1ubuntu1
* Merge from debian unstable, remaining changes:
  - Build depend on liblualib50-dev instead of liblua5.1-0-dev.
  - Drop libttf-dev (libttf-dev is in universe) (LP: #174749).
  - Replace gs-common with ghostscript.
  - Build-depend on python-dev instead of python2.4-dev or python2.5-dev.
  - Mention the correct python version for the python bindings in the
    package description.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include "glcomptexture.h"
 
2
 
 
3
glCompTexture* glCompCreateTextureFromRaw(char* filename,int width,int height,int wrap)
 
4
{
 
5
        glCompTexture* t;       
 
6
#ifdef _WIN32
 
7
        BYTE * data;
 
8
#else
 
9
        unsigned char *data;
 
10
#endif
 
11
        FILE * file;
 
12
        t=malloc(sizeof(glCompTexture));
 
13
        glGenTextures( 1, &t->id );
 
14
 
 
15
        // allocate buffer
 
16
        data = malloc( width * height * 3 );
 
17
        // open and read texture data
 
18
        file = fopen( filename, "rb" );
 
19
        fread( data, width * height * 3, 1, file );
 
20
        fclose( file );
 
21
 
 
22
 
 
23
// select our current texture
 
24
        glBindTexture( GL_TEXTURE_2D, t->id);
 
25
 
 
26
    // select modulate to mix texture with color for shading
 
27
    glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
 
28
 
 
29
    // when texture area is small, bilinear filter the closest mipmap
 
30
    glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
 
31
                     GL_LINEAR_MIPMAP_NEAREST );
 
32
    // when texture area is large, bilinear filter the first mipmap
 
33
    glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
 
34
 
 
35
    // if wrap is true, the texture wraps over at the edges (repeat)
 
36
    //       ... false, the texture ends at the edges (clamp)
 
37
    glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,
 
38
                     (GLfloat)wrap ? (GLfloat)GL_REPEAT : GL_CLAMP );
 
39
    glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,
 
40
                     (GLfloat)wrap ? (GLfloat)GL_REPEAT : GL_CLAMP );
 
41
 
 
42
/*      glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,GL_REPEAT );
 
43
        glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
 
44
        glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
 
45
        glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
 
46
        glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
 
47
 
 
48
        
 
49
        // build our texture mipmaps
 
50
        glTexImage2D(GL_TEXTURE_2D, 0, 4, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE,data);*/
 
51
 
 
52
    gluBuild2DMipmaps( GL_TEXTURE_2D, GL_RGB, width, height,
 
53
                       GL_RGB, GL_UNSIGNED_BYTE, data );
 
54
 
 
55
    // free buffer
 
56
    free( data );
 
57
        t->w=(float)width;
 
58
        t->h=(float)height;
 
59
        return t;
 
60
}
 
61
int glCompDeleteTexture(glCompTexture* t)
 
62
{
 
63
        return 0;
 
64
}