2 ===========================================================================
3 Copyright (C) 1997-2006 Id Software, Inc.
5 This file is part of Quake 2 Tools source code.
7 Quake 2 Tools source code is free software; you can redistribute it
8 and/or modify it under the terms of the GNU General Public License as
9 published by the Free Software Foundation; either version 2 of the License,
10 or (at your option) any later version.
12 Quake 2 Tools source code is distributed in the hope that it will be
13 useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with Quake 2 Tools source code; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 ===========================================================================
28 int skinwidth, skinheight;
29 int picwidth, picheight;
32 int width2, height2; // padded to ^2
34 float tmcoords[10000][3][2];
37 unsigned rgb[1024*512];
40 float s_scale, t_scale;
43 char picfilename[1024];
53 void BoundFaces (void)
65 for (i=0 ; i<numfaces ; i++)
81 mins[i] = floor(mins[i]);
82 maxs[i] = ceil(maxs[i]);
85 width = maxs[0] - mins[0];
86 height = maxs[2] - mins[2];
88 printf ("width: %i height: %i\n",width, height);
93 if (width*scale >= 150)
94 scale = 150.0 / width;
95 if (height*scale >= 190)
96 scale = 190.0 / height;
97 s_scale = t_scale = scale;
98 iwidth = ceil(width*scale) + 4;
99 iheight = ceil(height*scale) + 4;
103 s_scale = (skinwidth/2-4)/(float)width;
104 t_scale = (skinheight-4)/(float)height;
105 iwidth = skinwidth/2;
106 iheight = skinheight;
109 printf ("scale: %f\n",scale);
110 printf ("iwidth: %i iheight: %i\n",iwidth, iheight);
120 void AddFace (int facenum, triangle_t *f)
122 vec3_t v1, v2, normal;
128 // determine which side to map the teture to
130 VectorSubtract (f->verts[0], f->verts[1], v1);
131 VectorSubtract (f->verts[2], f->verts[1], v2);
132 CrossProduct (v1, v2, normal);
140 for (i=0 ; i<3 ; i++)
142 coords[i][0] = Q_rint((f->verts[i][0] - mins[0])*s_scale + basex);
143 coords[i][1] = Q_rint( (maxs[2] - f->verts[i][2])*t_scale + basey);
144 tmcoords[facenum][i][0] = coords[i][0]/(float)width2;
145 tmcoords[facenum][i][1] = coords[i][1]/(float)height2;
151 void CalcTmCoords (void)
157 for (j=0 ; j<numfaces ; j++)
158 AddFace (j, &faces[j]);
160 printf ("numfaces: %i\n",numfaces);
163 //===============================================================================
167 #define MAX_NUM_ARGVS 32
169 char *argv[MAX_NUM_ARGVS];
176 void ParseCommandLine (char *lpCmdLine)
179 argv[0] = "programname";
181 while (*lpCmdLine && (argc < MAX_NUM_ARGVS))
183 while (*lpCmdLine && ((*lpCmdLine <= 32) || (*lpCmdLine > 126)))
188 argv[argc] = lpCmdLine;
191 while (*lpCmdLine && ((*lpCmdLine > 32) && (*lpCmdLine <= 126)))
209 void LoadTriFile (char *name)
211 strcpy (tri_filename, name);
212 SetWindowText (camerawindow, tri_filename);
214 LoadTriangleList (tri_filename, &faces, &numfaces);
215 InvalidateRect (camerawindow, NULL, false);
224 int CALLBACK TimerProc(
225 HWND hwnd, // handle of window for timer messages
226 UINT uMsg, // WM_TIMER message
227 UINT idEvent, // timer identifier
228 DWORD dwTime // current system time
234 if (!skin_filename[0])
237 if (!modified_past_autosave)
246 return 0; // save every five minutes
248 strcpy (name, skin_filename);
249 StripExtension (name);
250 strcat (name, "_autosave.lbm");
251 Skin_SaveFile (name);
253 modified_past_autosave = false;
265 int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance
266 ,LPSTR lpCmdLine, int nCmdShow)
271 main_instance = hInstance;
273 ParseCommandLine (lpCmdLine);
275 screen_width = GetSystemMetrics (SM_CXFULLSCREEN);
276 screen_height = GetSystemMetrics (SM_CYFULLSCREEN);
278 // hack for broken NT 4.0 dual screen
279 if (screen_width > 2*screen_height)
282 accelerators = LoadAccelerators (hInstance
283 , MAKEINTRESOURCE(IDR_ACCELERATOR1));
285 Sys_Error ("LoadAccelerators failed");
287 Main_Create (hInstance);
288 WCam_Create (hInstance);
289 WPal_Create (hInstance);
290 WSkin_Create (hInstance);
293 Skin_LoadFile (argv[1]);
295 SetTimer ( mainwindow, 1, 1000*20, TimerProc );
299 if (!GetMessage (&msg, mainwindow, 0, 0))
301 if (!TranslateAccelerator(mainwindow, accelerators, &msg) )
303 TranslateMessage (&msg);
304 DispatchMessage (&msg);
308 /* return success of application */