Using OpenGL

pineapple via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Sep 3 02:55:22 PDT 2016


On Saturday, 3 September 2016 at 09:30:58 UTC, Darren wrote:
> Thanks for the information.  The errors for the tutorial I 
> _was_ trying to make work are as follows:
>
> source\app.d(9,5): Error: undefined identifier 'Window', did 
> you mean variable 'window'?
> source\app.d(98,12): Error: undefined identifier 'Window', did 
> you mean variable 'window'?
> source\app.d(101,14): Error: undefined identifier 'GLBuffer'
> source\app.d(104,14): Error: undefined identifier 'Shader'
> source\app.d(107,13): Error: undefined identifier 'Program', 
> did you mean variable 'program'?
> source\app.d(110,15): Error: undefined identifier 'Attribute'
>
> I thought I might have needed another package for these, and 
> gfm seemed to contain what I need in the form of the opengl 
> sub-package.  But even after importing that, it only gets rid 
> of the GLBuffer error.
>
> I tried to follow another tutorial.  Link to source code: 
> http://www.learnopengl.com/code_viewer.php?code=getting-started/hellotriangle
>
> I'm having more success with this one.  I pretty much hacked 
> away at this and did my best to convert from C-style code to D.
>  The window gets made and it has the green-ish background, but 
> it's not drawing any triangles.  Should I copy/paste the code 
> I'm using in case I made a mistake?

It's not quite in a practically-usable state yet, but the SDL2 & 
OpenGL wrapper I'm working on may interest you as an example 
implementation if nothing else. 
https://github.com/pineapplemachine/mach.d/tree/master/mach/sdl

Here's an example of a functioning program using the package. At 
the moment I'm working on exposing SDL2's event and other input 
systems.

     import std.datetime;
     import mach.math.vector2;
     import mach.sdl.window;
     import mach.sdl.texture;
     import mach.sdl.color;
     import mach.sdl.primitives;

     void main(){
         // Create a window
         auto win = new Window(300, 300);
         win.position = Vector2!int(200, 200);
         // Load a texture
         auto tex = Texture("pineapple.png");
         // Loop for 5 seconds
         StopWatch sw;
         sw.start();
         auto maxms = 5000f;
         while(true){
             auto ms = sw.peek().msecs;
             if(ms >= maxms) break;
             // Fill with green
             win.clear(0, ms / maxms / 2, 0);
             // Draw centered image
             tex.draw((win.size - tex.size) / 2);
             // Draw red lines at top and bottom
             lines(Color!ubyte.Red,
                 Vector2!int(8, 8), Vector2!int(292, 8),
                 Vector2!int(292, 292), Vector2!int(8, 292)
             );
             // Display changes
             win.swap();
         }
     }



More information about the Digitalmars-d-learn mailing list