September 27, 2019
On Friday, 27 September 2019 at 22:40:14 UTC, Adam D. Ruppe wrote:
> On Friday, 27 September 2019 at 22:13:43 UTC, matheus wrote:
>> https://github.com/adamdruppe/arsd/blob/b0d21de148ef0b23ea845be322af5e6931ca4cb6/screen.d
>
> I really should just remove that file as it is no longer well maintained. I haven't used it for anything in years and doubt anyone else is either.
>
> He's using the simpledisplay.d lib which DOES NOT SUPPORT transparency in its drawImage function. It does NOT use opengl functions and are not compatible with them.
>
> To do opengl stuff with simpledisplay, there is a separate flow. You use opengl functions on a redraw scene delegate instead of using any of the Image or Painter objects. It is quite different and there is no easy fix on that end.
>
> but the gdi+ functions in sdpy MIGHT be able to be ported to alpha blend on Windows easily enough. I just haven't gotten around to it yet.

Ahhh, that clears everything up. I will then leave the program without the transparency and wait until you get around to implement the fixes to it, I am not a developer, I am a scientist, I only use libraries, I don't know how to make them properly.
September 28, 2019
On Friday, 27 September 2019 at 22:55:22 UTC, Murilo wrote:

> Ahhh, that clears everything up. I will then leave the program without the transparency and wait until you get around to implement the fixes to it, I am not a developer, I am a scientist, I only use libraries, I don't know how to make them properly.

You might consider using SDL and SDL_image:

https://libsdl.org/download-2.0.php
https://www.libsdl.org/projects/SDL_image/

D bindings for both are available here:

https://code.dlang.org/packages/bindbc-sdl

You don't actually *need* SDL_image, as core SDL can load images in the BITMAP format, and you can then use the API to create transparency from a specific color. But if you want to load PNG files with alpha, you'll want SDL_image.

There are numerous tutorials online for SDL, though if you're searching, make sure to look for SDL 2 tutorials and ignore anything for SDL 1.x.

The tutorials will all be in either C or C++, but the SDL API using the D bindings is the same. The Lazy Foo tutorials are often recommended:

https://lazyfoo.net/tutorials/SDL/

But again, these are C++, so you have to consider the differences in D and C++ when porting the code over. For example, he uses class destructors to free resources. Do that in D and you'll run into trouble. So just ignore how he structures his programs and focus on the main concepts of using SDL: how to acquire/release resources, how to render, etc. You can adapt that to any architecture you want. There's no need for classes at all, for example.

Some tutorials out there will show you how to use SDL with OpenGL. Please ignore those. SDL's 2D Rendering API is what you want when you're learning, so focus on tutorials tat show you how to use it.

The SDL Wiki has API documentation:

http://wiki.libsdl.org/APIByCategory




September 28, 2019
On Friday, 27 September 2019 at 11:32:53 UTC, Adam D. Ruppe wrote:
> On Friday, 27 September 2019 at 11:28:35 UTC, matheus wrote:
>> Sorry this is a bit vague. I suppose you're using engine.d or screen.d directly right?
>
> those two are obsolete, new stuff should use simpledisplay
>
> but with simpledisplay you need to use opengl for transparency since the xlib/gdi+ impl doesn't support it (though they probably could if someone wanted to write some code)
>
> i just am doing 4 other things at once right now and can't do it myself at the moment





The last time I try this library on windows 10 it throws errors. Have you try it recently on windows

I want to know can the windows be customized and does it support styling like JavaFX
September 28, 2019
Ok, I took a look over my old projects and I found exactly what you want, by the way it's from 2012.

It uses Derelict 2.0 bindings and will draw a PNG image where you can move around with cursor keys.

If you want I can send you the whole project (Makefile, DLL's) and everything else to build it.

Code:

/* 02/10/2012 */
import std.stdio;
import derelict.sdl.sdl;
import derelict.sdl.image;

pragma(lib, "DerelictSDL.lib");
pragma(lib, "DerelictUtil.lib");
pragma(lib, "DerelictSDLImage.lib");

void main(){
	// Screen width, height and bit per pixel AKA color
	int width = 600, height = 480, bpp = 24;
	short xPos, yPos;

	// Load Derelict SDL bindings
	DerelictSDL.load();
	DerelictSDLImage.load();

	SDL_Surface* screen;
	SDL_Rect rScreen;

	// Pointing to an Array of the current key state
	Uint8 *keystate = SDL_GetKeyState(null);
		
	// Try initiate SDL
    	if (SDL_Init(SDL_INIT_VIDEO) < 0){
		throw new Exception("Failed: Can not initialize SDL!");
    	}

	screen = SDL_SetVideoMode(width, height, bpp, SDL_ANYFORMAT);// SDL_HWSURFACE);

	IMG_Init(IMG_INIT_PNG);
	auto img = IMG_Load("caco.png");
	if(img is null){
		throw new Exception("Image not found!");
	}

	writeln(" - w: ",img.w, " - h: ", img.h, " - bpp:", img.format.BitsPerPixel);

	if (screen is null){
		throw new Exception("Failed: Can not set video! ");
    	}

	SDL_WM_SetCaption("Simple Example", null);

	xPos = cast(short)(width   / 2 - 128);
	yPos = cast(short)(height  / 2 - 128);

	// Game loop
	while(!keystate[SDLK_ESCAPE]){
		SDL_Delay(2); // To not stress CPU

		// Fill screen with RED
		SDL_FillRect(screen, null, 0xFF0000);

		// Update key state array
		SDL_PumpEvents();

		// User's control
		yPos += keystate[SDLK_DOWN]-keystate[SDLK_UP];
		xPos += keystate[SDLK_RIGHT]-keystate[SDLK_LEFT];

                // Where to plot the image on the screen
		rScreen.x = xPos;
		rScreen.y = yPos;
		rScreen.w = rScreen.h = 256;
		
		SDL_BlitSurface(img,null,screen,&rScreen); // Draw Image
		SDL_Flip(screen); // Update Screen
	}
	IMG_Quit();
	SDL_FreeSurface(img);
	SDL_Quit();
}


Matheus.
September 28, 2019
On Saturday, 28 September 2019 at 13:41:24 UTC, matheus wrote:
> Ok, I took a look over my old projects and I found exactly what you want, by the way it's from 2012.
>
> It uses Derelict 2.0 bindings and will draw a PNG image where you can move around with cursor keys.

Murilo, if you do decide to use this example as a basis for your project, please don't use DerelictSDL2. I'm not maintaining it anymore. bindbc-sdl, which I linked in my previous post, is what you should prefer. The API to load the library and handle errors is different, but the SDL API calls will all be the same.
September 28, 2019
On Saturday, 28 September 2019 at 08:06:02 UTC, GreatSam4sure wrote:
> The last time I try this library on windows 10 it throws errors. Have you try it recently on windows

What errors? I sometimes break it with careless pushes to master but it usually works for me.

> I want to know can the windows be customized and does it support styling like JavaFX

simpledisplay creates a blank window, what goes in it is entirely up to you (you can even do a flag to skip the titlebar if you want, though I recommend against that generally as I find it user-hostile). There's three ways to draw in it:

1) the basic functions ScreenPainter provides (drawImage, drawRectangle, drawLine, etc), none of which do alpha blending and probably never will (though they might do mask-based single-color transparent pixels at some point when I get around to it or if someone sends me a PR). Nothing fancy here.

2) OpenGL functions. The simplewindow constructor can create a context for you for various opengl versions. Old style glBegin/glEnd is the default and has prototypes included inline. Newer style stuff is opt-in and you may need to load functions via an additional library (for example, the nanovega.d lib in there does this and includes its own vector graphics API, including alpha blending btw) or by dynamically loading them yourself (all the pieces are in simpledisplay it just doesn't do it all by default). These can get as fancy as you want.

3) Operating system functions. You can get at the window id/handle via the impl member of the window and hook the native event loop, call native functions, etc. to your heart's desire. If you do something that is generally useful and can be done at reasonable cost on X11 (Windows and Macintosh are both quite capable, it is usually X that ends up being the lowest common denominator), send me a PR and I might add it to screenpainter's api.


If you're looking for UI widgets like buttons and such, again you can DIY or my minigui.d contains a bunch of them. But they only contain the ones I have personally used so far and only do the styles I personally like and can implement cheaply and easily. There's no fancy CSS or animations or anything like that. I sometimes consider it but I'm personally pretty meh on them so don't expect it any time soon.


But if you all want that, on your schedule, smash that like button, comment, subscribe, and be sure to ring that bell so you get a notification every time I parrot what people say on Youtube at the end of their videos. Then head on over my patreon page and give me all your money today. If everyone who downloaded my libraries contributed just $3 / month, I'd be able to devote myself to expanding these libraries to support more use cases.

But until then, I write these for myself (or, in rare cases, someone else writes them for me and contributes it like with nanovega) so the functionality tend to focus on what I have used myself in the past. Then I post them online since it is easy to do so... then if you find them useful, great, and if you don't, oh well, there's always SDL or gtkD or html5 in electron (LOL) to cover more cases.
September 28, 2019
On Saturday, 28 September 2019 at 05:57:55 UTC, Mike Parker wrote:
> On Friday, 27 September 2019 at 22:55:22 UTC, Murilo wrote:
> You might consider using SDL and SDL_image:

Thank you very much. But I want to use only the arsd library.
September 30, 2019
On Saturday, 28 September 2019 at 13:41:24 UTC, matheus wrote:
> Ok, I took a look over my old projects and I found exactly what you want, by the way it's from 2012.
>
> It uses Derelict 2.0 bindings and will draw a PNG image where you can move around with cursor keys.
>
> If you want I can send you the whole project (Makefile, DLL's) and everything else to build it.
>
> Code:
>
> /* 02/10/2012 */
> import std.stdio;
> import derelict.sdl.sdl;
> import derelict.sdl.image;
> Matheus.

Thank you very much.
September 30, 2019
On Saturday, 28 September 2019 at 14:33:03 UTC, Adam D. Ruppe wrote:
>
> But if you all want that, on your schedule, smash that like button, comment, subscribe, and be sure to ring that bell so you get a notification every time I parrot what people say on Youtube at the end of their videos. Then head on over my patreon page and give me all your money today. If everyone who downloaded my libraries contributed just $3 / month, I'd be able to devote myself to expanding these libraries to support more use cases.
>

What are your pages that you want people subscribing to? And what is your patreon page? I may buy your book "D cookbook" next year, that will probably be a good contribution.

September 30, 2019
Hi everyone, I tried creating a program which simply shows the image of the ship near the corner of the screen, just for testing sake. Here it is:

import arsd.gamehelpers, arsd.image;
​
void main()​
{​
    SimpleWindow window = create2dWindow("Space Invaders", 1000, 400);​
    OpenGlTexture ship = new OpenGlTexture(loadImageFromFile("images/ship_normal.png").getAsTrueColorImage());​
    window.eventLoop(40,​
    (/*no events*/)​
    {​
        window.redrawOpenGlSceneNow;​
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_ACCUM_BUFFER_BIT);​
        glLoadIdentity;​
        ship.draw(20, 20, 41, 47);​
    });​
}​

But the screen stays all white, nothing appears in it. Any ideas what needs to be changed?