1 /***********************************************************************
5 File OpenGl_togl_texture.c :
12 HISTORIQUE DES MODIFICATIONS :
13 --------------------------------
14 05-08-97 : PCT ; Support texture mapping
15 20-11-97 : FMN ; Ajout call_togl_inquiretexture
16 Ajout coupure du texture mapping
18 ************************************************************************/
20 #define OCC1188 /*SAV 23/12/02 - added methods to set background image */
22 /*----------------------------------------------------------------------*/
28 #include <OpenGl_tgl_all.hxx>
29 #include <InterfaceGraphic_Labels.hxx>
30 #include <InterfaceGraphic_Graphic3d.hxx>
31 #include <InterfaceGraphic_Visual3d.hxx>
32 #include <OpenGl_tgl_funcs.hxx>
33 #include <OpenGl_TextureBox.hxx>
35 #include <OpenGl_cmn_varargs.hxx>
36 #include <OpenGl_tsm.hxx>
37 #include <OpenGl_tsm_ws.hxx>
43 /*----------------------------------------------------------------------*/
46 call_togl_create_texture
55 if (call_togl_inquiretexture ())
60 return GetTextureData1D(FileName, Width, Height, Data);
63 return GetTextureData2D(FileName, Width, Height, Data);
66 return GetTextureData2DMipMap(FileName, Width, Height, Data);
75 /*----------------------------------------------------------------------*/
78 call_togl_destroy_texture
83 if (call_togl_inquiretexture ())
87 /*----------------------------------------------------------------------*/
90 call_togl_modify_texture
93 CALL_DEF_INIT_TEXTURE *init_tex
96 if (call_togl_inquiretexture ())
98 if (init_tex->doModulate)
99 SetTextureModulate(TexId);
101 SetTextureDecal(TexId);
103 if (init_tex->doRepeat)
104 SetTextureRepeat(TexId);
106 SetTextureClamp(TexId);
108 switch (init_tex->Mode)
112 &init_tex->sparams[0], &init_tex->tparams[0]);
116 SetModeSphere(TexId);
121 &init_tex->sparams[0], &init_tex->tparams[0]);
125 SetModeManual(TexId);
129 if (init_tex->doLinear)
130 SetRenderLinear(TexId);
132 SetRenderNearest(TexId);
134 SetTexturePosition(TexId,
135 init_tex->sx, init_tex->sy,
136 init_tex->tx, init_tex->ty,
141 /*----------------------------------------------------------------------*/
144 call_togl_environment(CALL_DEF_VIEW *aview)
148 if (call_togl_inquiretexture ())
150 data.ldata = aview->Context.TexEnvId;
151 TsmSetWSAttri(aview->WsId, WSTextureEnv, &data);
153 data.ldata = aview->Context.SurfaceDetail;
154 TsmSetWSAttri(aview->WsId, WSSurfaceDetail, &data);
158 /*----------------------------------------------------------------------*/
161 call_togl_inquiretexture ()
170 /*----------------------------------------------------------------------*/
173 void EXPORT call_togl_create_bg_texture( CALL_DEF_VIEW* view, int width, int height,
174 unsigned char* data, int style )
177 tsm_bg_texture createdTex;
178 CMN_KEY_DATA cmnData;
181 GLubyte *image = (GLubyte *)malloc(width * height * 3 * sizeof(GLubyte));
182 memcpy( image, data, ( width * height * 3 ) );
184 /* check if some bg texture is already created */
185 TsmGetWSAttri( view->WsId, WSBgTexture, &cmnData );
186 createdTex = (tsm_bg_texture)cmnData.pdata;
187 if ( createdTex->texId != 0 )
188 glDeleteTextures( 1, (GLuint*)&(createdTex->texId) );
189 glGenTextures( 1, &texture );
190 glBindTexture( GL_TEXTURE_2D, texture );
191 /* Create MipMapped Texture */
192 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
193 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
194 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
195 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
196 gluBuild2DMipmaps( GL_TEXTURE_2D, 3/*4*/, width, height, GL_RGB, GL_UNSIGNED_BYTE, image );
204 tex.style = TSM_FS_CENTER;
207 tex.style = TSM_FS_TILE;
210 tex.style = TSM_FS_STRETCH;
213 tex.style = TSM_FS_CENTER;
217 /* setting flag to update changes */
218 cmnKey.ldata = TNotDone;
219 TsmSetWSAttri( view->WsId, WSUpdateState, &cmnKey );
221 /* storing background texture */
222 cmnData.pdata = &tex;
223 TsmSetWSAttri( view->WsId, WSBgTexture, &cmnData );
227 /*----------------------------------------------------------------------*/
229 void EXPORT call_togl_set_bg_texture_style( CALL_DEF_VIEW* view, int style )
231 tsm_bg_texture texture;
232 CMN_KEY_DATA cmnData;
235 /* check if background texture is already created */
236 TsmGetWSAttri( view->WsId, WSBgTexture, &cmnData );
237 texture = (tsm_bg_texture)cmnData.pdata;
238 if ( texture->texId != 0 ) {
242 texture->style = TSM_FS_CENTER;
245 texture->style = TSM_FS_TILE;
248 texture->style = TSM_FS_STRETCH;
251 texture->style = TSM_FS_CENTER;
255 /* setting flag to update changes */
256 cmnKey.ldata = TNotDone;
257 TsmSetWSAttri( view->WsId, WSUpdateState, &cmnKey );
259 /* storing background texture */
260 cmnData.pdata = texture;
261 TsmSetWSAttri( view->WsId, WSBgTexture, &cmnData );
265 /*----------------------------------------------------------------------*/