adamdruppe: Drawing scaled image

Adam D. Ruppe via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Jun 3 08:47:16 PDT 2016


On Thursday, 2 June 2016 at 04:01:03 UTC, Pie? wrote:
> Thanks, I'll look into it. I have tried OpenGL with 
> simpledisplay but I cannot draw to the window. I assume other 
> drawing methods are required?

Yeah, you have to use the OpenGL functions instead of my painter 
functions.

> If so, I can use gamehelpers.d to do the drawing of the images?

Yeah, the OpenGlTexture class can help with it. You can construct 
it with a TrueColorImage (readPng gives MemoryImage which you can 
call .getAsTrueColorImage on to get one)

Then the OpenGlTexture has a draw method which you can call from 
inside the redrawOpenGlScene method. OpenGL coordinates are 
different than desktop, but the `create2dWindow` method in 
gamehelpers.d will create one with a matrix that matches out.

So the function might look like:

SimpleWindow window = create2dWindow("your title", width, height);

auto image = new 
OpenGlTexture(readPng(your_png_file).getAsTrueColorImage));

window.redrawOpenGlScene = {
    image.draw(x, y);
};

window.eventLoop(....);



Use window.redrawOpenGlSceneNow(); in the event loop to make it 
redraw.


More information about the Digitalmars-d-learn mailing list