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: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206: 207: 208: 209: 210: 211: 212: 213: 214: 215: 216: 217: 218: 219: 220: 221: 222: 223: 224: 225: 226: 227: 228: 229: 230: 231: 232: 233: 234: 235: 236: 237: 238: 239: 240: 241: 242: 243: 244: 245: 246: 247: 248: 249: 250: 251: 252: 253: 254: 255: 256: 257: 258: 259: 260: 261: 262: 263: 264: 265: 266: 267: 268: 269: 270: 271: 272: 273: 274: 275: 276: 277: 278: 279: 280: 281: 282: 283: 284: 285: 286: 287: 288: 289: 290: 291: 292: 293: 294: 295: 296: 297: 298: 299: 300: 301: 302: 303: 304: 305: 306: 307: 308: 309: 310: 311: 312: 313: 314: 315: 316: 317: 318: 319: 320: 321: 322: 323: 324: 325: 326: 327: 328: 329: 330: 331: 332: 333: 334: 335: 336: 337: 338: 339: 340: 341: 342: 343: 344: 345: 346: 347: 348: 349: 350: 351: 352: 353: 354: 355: 356: 357: 358: 359: 360: 361: 362: 363: 364: 365: 366: 367: 368: 369: 370: 371: 372: 373: 374: 375: 376: 377: 378: 379: 380: 381: 382: 383: 384: 385: 386: 387: 388: 389: 390: 391: 392: 393: 394: 395: 396: 397: 398: 399: 400: 401: 402: 403: 404: 405: 406: 407: 408: 409: 410: 411: 412: 413: 414: 415: 416: 417: 418: 419: 420: 421: 422: 423: 424: 425: 426: 427: 428: 429: 430: 431: 432: 433: 434: 435: 436: 437: 438: 439: 440: 441: 442: 443: 444: 445: 446: 447: 448: 449: 450: 451: 452: 453: 454: 455: 456: 457: 458: 459: 460: 461: 462: 463: 464: 465: 466: 467: 468: 469: 470: 471: 472:
| unit GlObjekt;
interface
uses OpenGL12, Math, Classes, SysUtils;
type PVertex=^TVertex; TVertex=record ints:Array of GLint; floats:Array of GLfloat; end;
TOpenGLObjekt=class private ints:Array of GLInt; floats:Array of GLfloat; public constructor Create; destructor Destroy; override; procedure Draw; end; TOpenGLObjektF=class(TOpenGLObjekt) private public procedure LoadFromFile(filename:String); procedure SaveToFile(filename:String); end; TOpenGLObjektE=class(TOpenGLObjektF) private public procedure Add(aints:Array of GLint;afloats:Array of GLfloat); procedure Clear; procedure Show(dest:TStrings); function GetVertices:TList; end;
implementation
constructor TOpenGLObjekt.Create; begin inherited Create; SetLength(ints,0); SetLength(floats,0); end;
destructor TOpenGLObjekt.Destroy; begin SetLength(ints,0); SetLength(floats,0); inherited Destroy; end;
procedure TOpenGLObjekt.Draw; var i,f:Integer; bufint1,bufint2,bufint3,bufint4:GLint; buffloat1,buffloat2,buffloat3,buffloat4:GLfloat; begin i:=0; f:=0; while i<Length(ints) do begin case ints[i] of 0:begin i:=i+1; case ints[i] of 0:glBegin(GL_POINTS); 1:glBegin(GL_LINES); 2:glBegin(GL_LINE_STRIP); 3:glBegin(GL_LINE_LOOP); 4:glBegin(GL_POLYGON); 5:glBegin(GL_TRIANGLES); 6:glBegin(GL_TRIANGLE_FAN); 7:glBegin(GL_TRIANGLE_STRIP); 8:glBegin(GL_QUADS); 9:glBegin(GL_QUAD_STRIP); end; end; 1:begin glEnd; end; 6:begin i:=i+1; bufint1:=ints[i]; i:=i+1; bufint2:=ints[i]; i:=i+1; bufint3:=ints[i]; glColor3i(bufint1,bufint2,bufint3); end; 8:begin buffloat1:=floats[f]; f:=f+1; buffloat2:=floats[f]; f:=f+1; buffloat3:=floats[f]; f:=f+1; glColor3f(buffloat1,buffloat2,buffloat3); end; 19:begin i:=i+1; bufint1:=ints[i]; i:=i+1; bufint2:=ints[i]; glTexCoord2i(bufint1,bufint2); end; 20:begin buffloat1:=floats[f]; f:=f+1; buffloat2:=floats[f]; f:=f+1; glTexCoord2f(buffloat1,buffloat2); end; 24:begin i:=i+1; bufint1:=ints[i]; i:=i+1; bufint2:=ints[i]; i:=i+1; bufint3:=ints[i]; glNormal3i(bufint1,bufint2,bufint3); end; 25:begin buffloat1:=floats[f]; f:=f+1; buffloat2:=floats[f]; f:=f+1; buffloat3:=floats[f]; f:=f+1; glNormal3f(buffloat1,buffloat2,buffloat3); end; 28:begin i:=i+1; bufint1:=ints[i]; i:=i+1; bufint2:=ints[i]; i:=i+1; bufint3:=ints[i]; glVertex3i(bufint1,bufint2,bufint3); end; 29:begin buffloat1:=floats[f]; f:=f+1; buffloat2:=floats[f]; f:=f+1; buffloat3:=floats[f]; f:=f+1; glVertex3f(buffloat1,buffloat2,buffloat3); end; end; i:=i+1; end; end;
procedure TOpenGLObjektF.LoadFromFile(filename:String); var data:File; floatsize:Byte; intsize:Byte; bufint:GLint; buffloat:GLfloat; numintsi,numfloatsi:Integer; i:Integer; begin AssignFile(data,filename); Reset(data,1); BlockRead(data,intsize,1); BlockRead(data,floatsize,1); BlockRead(data,numintsi,SizeOf(numintsi)); SetLength(ints,numintsi); BlockRead(data,numfloatsi,SizeOf(numfloatsi)); SetLength(floats,numfloatsi); for i:=0 to numintsi-1 do begin BlockRead(data,bufint,intsize); ints[i]:=bufint; end; for i:=0 to numfloatsi-1 do begin BlockRead(data,buffloat,floatsize); floats[i]:=buffloat; end; CloseFile(data); end;
procedure TOpenGLObjektF.SaveToFile(filename:String); var data:File; floatsize:Byte; intsize:Byte; numintsi,numfloatsi:Integer; i:Integer; begin floatsize:=SizeOf(GLfloat); intsize:=SizeOf(GLint); numintsi:=Length(ints); numfloatsi:=Length(floats); AssignFile(data,filename); Rewrite(data,1); BlockWrite(data,intsize,1); BlockWrite(data,floatsize,1); BlockWrite(data,numintsi,SizeOf(numintsi)); BlockWrite(data,numfloatsi,SizeOf(numfloatsi)); for i:=0 to numintsi-1 do begin BlockWrite(data,ints[i],intsize); end; for i:=0 to numfloatsi-1 do begin BlockWrite(data,floats[i],floatsize); end; CloseFile(data); end;
procedure TOpenGLObjektE.Add(aints:Array of GLint;afloats:Array of GLfloat); var oldleni,oldlenf,i:Integer; begin oldleni:=Length(ints); oldlenf:=Length(floats); SetLength(ints,oldleni+Length(aints)); SetLength(floats,oldlenf+Length(afloats)); for i:=oldleni to Length(ints)-1 do begin ints[i]:=aints[i-oldleni]; end; for i:=oldlenf to Length(floats)-1 do begin floats[i]:=afloats[i-oldlenf]; end; end;
procedure TOpenGLObjektE.Clear; begin SetLength(ints,0); SetLength(floats,0); end;
procedure TOpenGLObjektE.Show(dest:TStrings); var i,f:Integer; bufint1,bufint2,bufint3,bufint4:GLint; buffloat1,buffloat2,buffloat3,buffloat4:GLfloat; begin i:=0; f:=0; dest.Clear; while i<Length(ints) do begin case ints[i] of 0:begin i:=i+1; case ints[i] of 0:dest.Add('glBegin(GL_POINTS)'); 1:dest.Add('glBegin(GL_LINES)'); 2:dest.Add('glBegin(GL_LINE_STRIP)'); 3:dest.Add('glBegin(GL_LINE_LOOP)'); 4:dest.Add('glBegin(GL_POLYGON)'); 5:dest.Add('glBegin(GL_TRIANGLES)'); 6:dest.Add('glBegin(GL_TRIANGLE_FAN)'); 7:dest.Add('glBegin(GL_TRIANGLE_STRIP)'); 8:dest.Add('glBegin(GL_QUADS)'); 9:dest.Add('glBegin(GL_QUAD_STRIP)'); end; end; 1:dest.Add('glEnd'); 6:begin i:=i+1; bufint1:=ints[i]; i:=i+1; bufint2:=ints[i]; i:=i+1; bufint3:=ints[i]; dest.Add('glColor3i('+IntToStr(bufint1)+','+IntToStr(bufint2)+','+IntToStr(bufint3)+')'); end; 8:begin buffloat1:=floats[f]; f:=f+1; buffloat2:=floats[f]; f:=f+1; buffloat3:=floats[f]; f:=f+1; dest.Add('glColor3f('+FloatToStr(buffloat1)+','+FloatToStr(buffloat2)+','+FloatToStr(buffloat3)+')'); end; 19:begin i:=i+1; bufint1:=ints[i]; i:=i+1; bufint2:=ints[i]; dest.Add('glTexCoord2i('+IntToStr(bufint1)+','+IntToStr(bufint2)+')'); end; 20:begin buffloat1:=floats[f]; f:=f+1; buffloat2:=floats[f]; f:=f+1; dest.Add('glTexCoord2f('+FloatToStr(buffloat1)+','+FloatToStr(buffloat2)+')'); end; 24:begin i:=i+1; bufint1:=ints[i]; i:=i+1; bufint2:=ints[i]; i:=i+1; bufint3:=ints[i]; dest.Add('glNormal3i('+IntToStr(bufint1)+','+IntToStr(bufint2)+','+IntToStr(bufint3)+')'); end; 25:begin buffloat1:=floats[f]; f:=f+1; buffloat2:=floats[f]; f:=f+1; buffloat3:=floats[f]; f:=f+1; dest.Add('glNormal3f('+FloatToStr(buffloat1)+','+FloatToStr(buffloat2)+','+FloatToStr(buffloat3)+')'); end; 28:begin i:=i+1; bufint1:=ints[i]; i:=i+1; bufint2:=ints[i]; i:=i+1; bufint3:=ints[i]; dest.Add('glVertex3i('+IntToStr(bufint1)+','+IntToStr(bufint2)+','+IntToStr(bufint3)+')'); end; 29:begin buffloat1:=floats[f]; f:=f+1; buffloat2:=floats[f]; f:=f+1; buffloat3:=floats[f]; f:=f+1; dest.Add('glVertex3f('+FloatToStr(buffloat1)+','+FloatToStr(buffloat2)+','+FloatToStr(buffloat3)+')'); end; end; i:=i+1; end; end;
function TOpenGLObjektE.GetVertices:TList; var buf:TList; i,f:Integer; newitem:PVertex; begin i:=0; f:=0; buf:=TList.Create; while i<Length(ints) do begin case ints[i] of 0,1,6,8,19,20,24,25,28,29: begin New(newitem); end; end; case ints[i] of 0:begin SetLength(newitem^.ints,2); SetLength(newitem^.floats,0); newitem^.ints[0]:=ints[i]; i:=i+1; newitem^.ints[1]:=ints[i]; end; 1:begin SetLength(newitem^.ints,1); SetLength(newitem^.floats,0); newitem^.ints[0]:=ints[i]; end; 6,24,28:begin SetLength(newitem^.ints,4); SetLength(newitem^.floats,0); newitem^.ints[0]:=ints[i]; i:=i+1; newitem^.ints[1]:=ints[i]; i:=i+1; newitem^.ints[2]:=ints[i]; i:=i+1; newitem^.ints[3]:=ints[i]; end; 8,25,29:begin SetLength(newitem^.ints,1); SetLength(newitem^.floats,3); newitem^.ints[0]:=ints[i]; newitem^.floats[0]:=floats[f]; f:=f+1; newitem^.floats[1]:=floats[f]; f:=f+1; newitem^.floats[2]:=floats[f]; f:=f+1; end; 19:begin SetLength(newitem.ints,3); SetLength(newitem.floats,0); newitem.ints[0]:=ints[i]; i:=i+1; newitem.ints[1]:=ints[i]; i:=i+1; newitem.ints[2]:=ints[i]; end; 20:begin SetLength(newitem.ints,1); SetLength(newitem.floats,2); newitem.ints[0]:=ints[i]; newitem.floats[0]:=floats[f]; f:=f+1; newitem.floats[1]:=floats[f]; f:=f+1; end; end; i:=i+1; buf.Add(newitem); end; result:=buf; end;
end. |