/******************************************************************************* * Copyright (c) 2000, 2005 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * Sebastian Davids - initial implementation * IBM Corporation * Port to the D programming language: * Bill Baxter *******************************************************************************/ module opengl.Snippet174; /* * SWT OpenGL snippet: draw a square * * This snippet requires the experimental org.eclipse.swt.opengl plugin, which * is not included in SWT by default and should only be used with versions of * SWT prior to 3.2. For information on using OpenGL in SWT see * http://www.eclipse.org/swt/opengl/ . * * For a list of all SWT example snippets see * http://www.eclipse.org/swt/snippets/ * * @since 3.2 */ import dwt.DWT; import dwt.dwthelper.Runnable; import dwt.widgets.Display; import dwt.widgets.Shell; import dwt.graphics.Rectangle; import dwt.events.ControlEvent; import dwt.events.ControlAdapter; import dwt.layout.FillLayout; import dwt.opengl.GLCanvas; import dwt.opengl.GLData; import dwt.widgets.Menu; import dwt.custom.CTabFolder; import dwt.custom.CTabItem; import derelict.opengl.gl; import derelict.opengl.glu; import Math = tango.math.Math; static this() { DerelictGL.load(); DerelictGLU.load(); } public static void main() { Display display = new Display(); Shell shell = new Shell(display); auto menubar = new Menu (shell, DWT.BAR); shell.setMenuBar(menubar); shell.setText("OpenGL in DWT"); shell.setLayout(new FillLayout()); auto tabs = new CTabFolder(shell, DWT.BORDER); auto titem = new CTabItem(tabs, DWT.CLOSE); GLData data = new GLData(); data.doubleBuffer = true; data.alphaSize = 8; // want an alpha channel for readback of framebuffer w/ mask. final GLCanvas canvas = new GLCanvas(tabs, DWT.NO_BACKGROUND, data); titem.setText("Canvas"); titem.setControl(canvas); canvas.addControlListener(new class ControlAdapter { public void controlResized(ControlEvent e) { resize(canvas); } }); shell.open(); init(canvas); auto x = (new class Runnable { public void run() { if (canvas.isDisposed()) return; render(); canvas.swapBuffers(); //canvas.getDisplay().timerExec(15, this); canvas.getDisplay().asyncExec(this); } });//.run(); display.asyncExec(x); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); } static void init(GLCanvas canvas) { canvas.setCurrent(); resize(canvas); glClearColor(1.0f, 1.0f, 1.0f, 0.0f); glColor3f(0.0f, 0.0f, 0.0f); glClearDepth(1.0f); glEnable(GL_DEPTH_TEST); glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); } float[] VERTS = [ 690.9538574219f, 377.6475524902, 0.0000000000, 661.3722534180, 378.3741760254, 0.0000000000, 652.0711669922, 377.6440734863, 0.0000000000, 616.4154052734, 378.6957702637, 0.0000000000, 601.0469360352, 378.1477050781, 0.0000000000, 519.8452758789, 379.6033630371, 0.0000000000, 510.5403137207, 378.8886108398, 0.0000000000, 306.2986145020, 385.1033935547, 0.0000000000, 301.1472167969, 386.2604675293, 0.0000000000, 161.2397003174, 390.3570556641, 0.0000000000, 133.9701232910, 389.1464233398, 0.0000000000, 128.6894989014, 387.2933044434, 0.0000000000, 112.3644104004, 385.7574157715, 0.0000000000, 79.0550231934, 386.7090759277, 0.0000000000, 67.8775329590, 385.0262756348, 0.0000000000, 61.7555160522, 383.1997985840, 0.0000000000, 56.5992240906, 379.3455505371, 0.0000000000, 51.3713684082, 372.4927368164, 0.0000000000, 48.5440788269, 366.6260375977, 0.0000000000, 51.3315582275, 355.1126403809, 0.0000000000, 56.7459869385, 350.3296203613, 0.0000000000, 62.7004394531, 347.1584472656, 0.0000000000, 95.8904037476, 346.2054443359, 0.0000000000, 103.0741043091, 348.0034179687, 0.0000000000, 146.9219665527, 350.7581481934, 0.0000000000, 167.1355590820, 352.1657714844, 0.0000000000, 175.3862457275, 352.9344787598, 0.0000000000, 200.5960693359, 352.1897583008, 0.0000000000, 205.8051300049, 353.0477600098, 0.0000000000, 305.2078552246, 350.1216430664, 0.0000000000, 312.3376159668, 350.9098815918, 0.0000000000, 343.7265319824, 349.9681396484, 0.0000000000, 392.5693054199, 350.4998474121, 0.0000000000, 399.7329711914, 351.2836914063, 0.0000000000, 480.0851135254, 348.8063964844, 0.0000000000, 488.2645263672, 349.5570678711, 0.0000000000, 493.4353637695, 350.4048156738, 0.0000000000, 534.1507568359, 349.1542968750, 0.0000000000, 630.9298706055, 351.2209472656, 0.0000000000, 660.4690551758, 352.3482360840, 0.0000000000, 674.8284301758, 353.9633789062, 0.0000000000, 704.4393310547, 352.8170471191, 0.0000000000, 718.7716674805, 356.4224853516, 0.0000000000, 729.3302612305, 362.7715454102, 0.0000000000, 736.8713378906, 371.9180603027, 0.0000000000, 736.3243408203, 377.1490783691, 0.0000000000, 731.4189453125, 380.2991333008, 0.0000000000, 721.5765991211, 384.6006164551, 0.0000000000, 708.5802612305, 384.9941101074, 0.0000000000, 703.4055786133, 384.2879638672, 0.0000000000, 408.3373413086, 382.0314636230, 0.0000000000, 231.2896728516, 388.3195800781, 0.0000000000, 136.3497009277, 374.6004333496, 0.0000000000, 300.6252441406, 372.2983398437, 0.0000000000, 459.5397033691, 380.4599304199, 0.0000000000, 708.0001220703, 371.0000305176, 0.0000000000, 68.0816650391, 364.6632080078, 0.0000000000, 67.5692367554, 374.8342590332, 0.0000000000, 58.3679466248, 365.5113830566, 0.0000000000, 94.6459655762, 366.1101379395, 0.0000000000, 357.2982177734, 383.5811157227, 0.0000000000, 307.4392089844, 362.1219787598, 0.0000000000, 169.4194793701, 372.0480041504, 0.0000000000, 524.1634521484, 355.7439270020, 0.0000000000, 657.7414550781, 365.4545898437, 0.0000000000, 81.1344451904, 370.6846618652, 0.0000000000, 719.0360107422, 367.9528808594, 0.0000000000, 328.0108032227, 350.4360961914, 0.0000000000, 645.6716918945, 351.7830810547, 0.0000000000, 676.1614990234, 378.0109252930, 0.0000000000, 666.5232543945, 360.4021606445, 0.0000000000, 634.2650756836, 378.1698608398, 0.0000000000, 582.3549804687, 350.1740417480, 0.0000000000, 196.2421722412, 389.3411560059, 0.0000000000, 121.6876373291, 374.6354370117, 0.0000000000, 147.8392333984, 383.9989929199, 0.0000000000, 107.4716949463, 372.4533386230, 0.0000000000, 709.9764404297, 361.2198791504, 0.0000000000, 506.9657897949, 369.2537536621, 0.0000000000, 87.0702972412, 352.6917114258, 0.0000000000, 95.6887359619, 386.2334289551, 0.0000000000, 76.0956954956, 378.1528320312, 0.0000000000, 677.6817016602, 365.8806762695, 0.0000000000, 689.6696777344, 353.3911132812, 0.0000000000, 698.4622802734, 371.9500122070, 0.0000000000, 382.6808471680, 382.8146057129, 0.0000000000, 638.0601806641, 357.7739562988, 0.0000000000, 606.6776733398, 350.6967773438, 0.0000000000, 649.9667968750, 360.0816955566, 0.0000000000, 200.9212036133, 366.1638488770, 0.0000000000, 124.9845352173, 349.3820800781, 0.0000000000, 152.2534332275, 367.2493591309, 0.0000000000, 266.2088012695, 387.2901306152, 0.0000000000, 513.8664550781, 349.7803344727, 0.0000000000, 485.1404113770, 379.6701660156, 0.0000000000, 85.8082962036, 362.3975524902, 0.0000000000, 668.2974243164, 370.5976867676, 0.0000000000, 178.7297821045, 389.8505554199, 0.0000000000, 642.0346069336, 369.0135803223, 0.0000000000, 177.7317962646, 364.1024780273, 0.0000000000, 188.2353973389, 359.3736267090, 0.0000000000, 158.8253021240, 378.3785705566, 0.0000000000, 105.6723022461, 360.1603088379, 0.0000000000, 96.3039016724, 356.2254333496, 0.0000000000, 114.0137710571, 348.6926269531, 0.0000000000, 146.0717163086, 374.6031799316, 0.0000000000, 255.4949951172, 351.5887145996, 0.0000000000, 488.5319213867, 363.5254516602, 0.0000000000, 90.7189407349, 376.3840332031, 0.0000000000, 103.8522033691, 381.2678833008, 0.0000000000, 697.4807739258, 361.1519470215, 0.0000000000, 331.7729797363, 384.3422241211, 0.0000000000, 368.1316528320, 350.2389831543, 0.0000000000, 283.7028198242, 386.7753601074, 0.0000000000, 625.2406616211, 374.7086181641, 0.0000000000, 128.9859771729, 362.7300415039, 0.0000000000, 497.5812377930, 373.8551635742, 0.0000000000, 336.4058227539, 365.8068237305, 0.0000000000, 614.6967773437, 363.6383361816, 0.0000000000, 631.6736450195, 366.2301940918, 0.0000000000, 292.2514038086, 379.6540527344, 0.0000000000, 191.8813018799, 367.6455688477, 0.0000000000, 117.0544281006, 363.7831726074, 0.0000000000, 135.9657440186, 350.0707702637, 0.0000000000, 140.9032440186, 363.7415161133, 0.0000000000, 336.0783691406, 356.0819091797, 0.0000000000, 608.9524536133, 371.8975830078, 0.0000000000, 560.3912963867, 378.8688964844, 0.0000000000, 618.8122558594, 350.9588012695, 0.0000000000, 624.0856323242, 359.5575866699, 0.0000000000, 230.7288055420, 352.3232727051, 0.0000000000, 604.8795166016, 360.5899658203, 0.0000000000, 218.6849060059, 365.1121215820, 0.0000000000, 209.5718841553, 361.8345031738, 0.0000000000, 79.2876205444, 346.6827697754, 0.0000000000, 62.1013984680, 357.4278869629, 0.0000000000, 355.3643493652, 364.8428955078, 0.0000000000, 394.2804870605, 367.3722839355, 0.0000000000, 156.6546936035, 356.7655944824, 0.0000000000, 165.5103607178, 362.4091491699, 0.0000000000, 440.0574340820, 350.0566406250, 0.0000000000, 688.5184936523, 367.2420654297, 0.0000000000, 199.3011169434, 377.8952636719, 0.0000000000, 213.7344512939, 388.8321228027, 0.0000000000, 204.8822326660, 385.4697570801, 0.0000000000, 211.3859863281, 375.0526733398, 0.0000000000, 224.6568603516, 376.8747558594, 0.0000000000, 232.3437805176, 365.7042236328, 0.0000000000, 222.5299224854, 388.5756225586, 0.0000000000, 243.2980194092, 357.6328125000, 0.0000000000, 257.4571228027, 370.4457702637, 0.0000000000, 252.8502044678, 361.3779602051, 0.0000000000, 248.7210235596, 387.8070983887, 0.0000000000, 244.2908325195, 371.2858581543, 0.0000000000, 251.3246307373, 378.2643737793, 0.0000000000, 235.7355194092, 378.2623901367, 0.0000000000, 186.3040618896, 379.3092651367, 0.0000000000, 175.9517669678, 379.9983520508, 0.0000000000, 167.0326232910, 382.9804687500, 0.0000000000, 322.0046386719, 363.5238952637, 0.0000000000, 320.2741394043, 354.8612670898, 0.0000000000, 327.7446594238, 373.5367736816, 0.0000000000, 319.0436096191, 384.7225036621, 0.0000000000, 313.4376525879, 373.3330383301, 0.0000000000, 280.4284667969, 350.8613281250, 0.0000000000, 282.7143249512, 377.0660400391, 0.0000000000, 292.8526306152, 350.4942626953, 0.0000000000, 290.1433105469, 369.0072937012, 0.0000000000, 276.7496337891, 364.3874816895, 0.0000000000, 267.9826965332, 351.2263488770, 0.0000000000, 286.9102478027, 359.1040344238, 0.0000000000, 270.0423889160, 375.1976013184, 0.0000000000, 274.8703918457, 383.2939758301, 0.0000000000, 265.3986511230, 362.2763671875, 0.0000000000, 594.5412597656, 350.4367980957, 0.0000000000, 580.7216186523, 378.5053710938, 0.0000000000, 595.1227416992, 359.9672546387, 0.0000000000, 218.2351837158, 352.6833496094, 0.0000000000, 76.1634826660, 357.1221313477, 0.0000000000, 380.3492431641, 350.3702392578, 0.0000000000, 386.3853149414, 359.6268310547, 0.0000000000, 382.7831115723, 370.9495849609, 0.0000000000, 369.8338012695, 376.8807983398, 0.0000000000, 373.5392150879, 361.9072570801, 0.0000000000, 355.9301757812, 350.1066589355, 0.0000000000, 363.7604064941, 359.2219543457, 0.0000000000, 360.0443115234, 373.8751525879, 0.0000000000, 344.4988098145, 383.9629821777, 0.0000000000, 337.8890686035, 375.9974975586, 0.0000000000, 348.8322448730, 373.7321472168, 0.0000000000, 581.4237060547, 364.3327331543, 0.0000000000, 591.2672729492, 371.2042846680, 0.0000000000, 600.2229614258, 368.5706176758, 0.0000000000, 570.4110717773, 370.9067687988, 0.0000000000, 569.5931396484, 357.3530578613, 0.0000000000, 558.2332153320, 349.6605834961, 0.0000000000, 540.1094970703, 379.2347717285, 0.0000000000, 556.2592773437, 364.4868774414, 0.0000000000, 550.1554565430, 373.9718017578, 0.0000000000, 538.3665161133, 363.9564208984, 0.0000000000, 529.8266601562, 372.6647949219, 0.0000000000, 516.3999633789, 364.7693176270, 0.0000000000, 546.1030883789, 353.8229064941, 0.0000000000, 419.8537597656, 350.6700134277, 0.0000000000, 472.3565063477, 380.0633239746, 0.0000000000, 404.4012145996, 371.8473205566, 0.0000000000, 395.5185546875, 382.4231262207, 0.0000000000, 402.5361022949, 361.1419677734, 0.0000000000, 430.2126770020, 361.3924865723, 0.0000000000, 409.7489013672, 350.9736022949, 0.0000000000, 433.8596191406, 381.2512207031, 0.0000000000, 415.1461486816, 361.7757873535, 0.0000000000, 429.9626770020, 350.3653564453, 0.0000000000, 447.9985656738, 366.3408508301, 0.0000000000, 421.0926818848, 381.6416320801, 0.0000000000, 440.2565612793, 359.9640502930, 0.0000000000, 437.5816955566, 370.7555541992, 0.0000000000, 446.6603393555, 380.8584594727, 0.0000000000, 426.3158264160, 371.8077697754, 0.0000000000, 415.3088073730, 372.5253601074, 0.0000000000, 481.6419067383, 370.5180969238, 0.0000000000, 460.0617980957, 349.4275207520, 0.0000000000, 450.1786804199, 354.7160034180, 0.0000000000, 465.9175720215, 364.8489379883, 0.0000000000, 472.4896850586, 371.0797119141, 0.0000000000, 456.6925354004, 361.8943786621, 0.0000000000, 470.2969665527, 354.4648437500, 0.0000000000, 499.7976684570, 360.1168518066, 0.0000000000, 503.6401977539, 350.0924072266, 0.0000000000, 509.3629760742, 358.2491760254, 0.0000000000, ]; static void render() { static int rot = 0; glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); glTranslatef(0.0f, 0.0f, -6.0f); glScalef(.005,.005,.005); glRotatef(rot++, 0,0,1); rot %= 360; glDisable(GL_DEPTH_TEST); glEnable(GL_COLOR_MATERIAL); glDisable(GL_LIGHTING); glColor3f(0,0,1); glPointSize(5); glEnableClientState(GL_VERTEX_ARRAY); //glVertexPointer(3, GL_FLOAT, 0, mesh_.points().ptr); glVertexPointer(3, GL_FLOAT, 0, VERTS.ptr); glBegin(GL_POINTS); //foreach(vh; mesh_.vertices_begin()) { for(int i; i