summaryrefslogtreecommitdiff
path: root/cubedbusTexture.c.in
blob: 4e02daaed0824450afb3d7ec3a293e3b0dc1dc2f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#define CUBEDBUS_TEXTURE_OBJECT 3

typedef struct _CubedbusTextureObject CubedbusTextureObject;


static bool cubedbusDrawTextureObject (CubedbusObject *obj);
static bool cubedbusDeleteTextureObject (CubedbusObject *obj);
static bool cubedbusModifyTextureObject (CubedbusObject *obj, CompOption *option, int nOption);
static bool cubedbusAddTextureObject (CubedbusObject *obj, CompOption *option, int nOption);

struct _CubedbusTextureObject
{
CompTexture tex;

unsigned height;
unsigned width;

GLuint dList;
bool order;
float rotate[4], translate[3], scale[3];
float rotateSpeed;
};


static bool
cubedbusAddTextureObject (CubedbusObject *obj, CompOption *option, int nOption)
{
	obj->data= malloc( sizeof(CubedbusTextureObject) );
		if(obj->data == NULL) return FALSE;
				
	CubedbusTextureObject *textureData=obj->data;	
	
	textureData->rotate[0]=getFloatOptionNamed (option,nOption, "rotateAngle", 0.0);
	textureData->rotate[1]=getFloatOptionNamed (option,nOption, "rotateX", 0.0);
	textureData->rotate[2]=getFloatOptionNamed (option,nOption, "rotateY", 0.0);
	textureData->rotate[3]=getFloatOptionNamed (option,nOption, "rotateZ", 0.0);
	textureData->translate[0]=getFloatOptionNamed (option,nOption, "translateX", 0.0);
	textureData->translate[1]=getFloatOptionNamed (option,nOption, "translateY", 0.0);
	textureData->translate[2]=getFloatOptionNamed (option,nOption, "translateZ", 0.0);
	textureData->scale[0]=getFloatOptionNamed (option,nOption, "scaleX", 1.0);
	textureData->scale[1]=getFloatOptionNamed (option,nOption, "scaleY", 1.0);
	textureData->scale[2]=getFloatOptionNamed (option,nOption, "scaleZ", 1.0);
	textureData->order=getBoolOptionNamed (option, nOption, "order", TRUE);
	textureData->rotateSpeed=getFloatOptionNamed (option, nOption, "rotateSpeed", 0);


		
	/* Code to make textureData->dList */
	
			if(!(readImageToTexture (obj->s, &(textureData->tex),  														/*texture pointer*/
		           					 getStringOptionNamed (option, nOption, "file", ""),                       		/*file*/            
		           					 &(textureData->width),                        									/*pointer for width*/
		           					 &(textureData->height) ) ) )													/*pointer for height*/
		           {
		           compLogMessage (obj->s->display, "photo", CompLogLevelWarn, "Failed to load image");
		           		
		           finiTexture(obj->s, &(textureData->tex));
		           initTexture(obj->s, &(textureData->tex));
		           }                      
		           
		     CompMatrix *mat = &textureData->tex.matrix;
	
	textureData->dList=glGenLists (1);
	glNewList (textureData->dList, GL_COMPILE);
		
		glBegin(GL_QUADS); 

    		glTexCoord2f (COMP_TEX_COORD_X (mat, 0), 
    			COMP_TEX_COORD_Y (mat, 0));
    		 	 	glVertex3f( getFloatOptionNamed (option, nOption, "x0", 0) ,
    		 	 				getFloatOptionNamed (option, nOption, "y0", 0) ,
    		 	 				getFloatOptionNamed (option, nOption, "z0", 0) );	// Top Left Of The Texture and Quad     
  
    		glTexCoord2f (COMP_TEX_COORD_X (mat, (textureData->width)),
    			 COMP_TEX_COORD_Y (mat, 0));  
    				glVertex3f( getFloatOptionNamed (option, nOption, "x1", 0) ,
    		 	 				getFloatOptionNamed (option, nOption, "y1", 0) ,
    		 	 				getFloatOptionNamed (option, nOption, "z1", 0)   );	// Top Right Of The Texture and Quad    				
    				
    		glTexCoord2f (COMP_TEX_COORD_X (mat, (textureData->width)), 
    			COMP_TEX_COORD_Y (mat, (textureData->height)));  
    				glVertex3f( getFloatOptionNamed (option, nOption, "x2", 0) ,
    		 	 				getFloatOptionNamed (option, nOption, "y2", 0) ,
    		 	 				getFloatOptionNamed (option, nOption, "z2", 0)  );	// Bot Right Of The Texture and Quad    
    								
    		glTexCoord2f (COMP_TEX_COORD_X (mat, 0), 
    			COMP_TEX_COORD_Y (mat, (textureData->height))); 
    				glVertex3f( getFloatOptionNamed (option, nOption, "x3", 0) ,
    		 	 				getFloatOptionNamed (option, nOption, "y3", 0) ,
    		 	 				getFloatOptionNamed (option, nOption, "z3", 0)   );	// Bot Left Of The Texture and Quad    		 	 	

		glEnd();
		
	glEndList();



	return TRUE;
}

static bool
cubedbusDeleteTextureObject (CubedbusObject *obj)
{
	CubedbusTextureObject *data=obj->data;
		finiTexture (obj->s, &data->tex);
		glDeleteLists (data->dList, 1);
		free(obj->data);
		free(obj);		
	return TRUE;
}

static bool
cubedbusModifyTextureObject (CubedbusObject *obj, CompOption *option, int nOption)
{
	return TRUE;
}

static bool
cubedbusDrawTextureObject (CubedbusObject *obj)
{
	
	CubedbusTextureObject *data=obj->data;
	
			if(data->order) glTranslatef (data->translate[0], data->translate[1], data->translate[2]);
		glRotatef ( data->rotate[0], data->rotate[1], data->rotate[2], data->rotate[3]);
			if(!(data->order)) glTranslatef (data->translate[0], data->translate[1], data->translate[2]); 
		
		glScalef( data->scale[0],data->scale[1], data->scale[2]); /* Rotate, translate and scale  */

    		glEnable (data->tex.target);
    	
    		enableTexture (obj->s, &(data->tex), 
    			COMP_TEXTURE_FILTER_GOOD); 

	glCallList(data->dList);		
					
    		disableTexture (obj->s, &(data->tex));
    		
    	data->rotate[0]+=data->rotateSpeed;
    	if(data->rotate[0]>360) data->rotate[0]=0;
    	if(data->rotate[0]<0) data->rotate[0]=360;					
	return TRUE;
}