GithubHelp home page GithubHelp logo

dgame / dgame Goto Github PK

View Code? Open in Web Editor NEW
85.0 16.0 73.0 12.47 MB

A 2D framework for the D programming Language

Home Page: http://dgame-dev.de/

License: Other

D 17.52% HTML 82.48%
dgame 2d-framework d dlang sdl opengl

dgame's Introduction

Dgame

A 2D framework for the D programming Language

What is Dgame?

Dgame is a 2D framework which is based on the SDL and OpenGL, and is designed for the D programming language. The design rests upon Pygame and as well on the SFML from the C++ programming language.

Why Dgame?

Currently D has only few frameworks for games and window programming, and most of them are C/C++ bindings. Of those Derelict is probaly the most famous and provides support for multiple C/C++ libraries. Dgame also uses Derelict to access the functionality of the SDL and OpenGL. However, unlike the other bindings, Dgame is object-oriented (like the SFML) and is the only one which is completely written in D.

Installation

See here

Further tutorials

See here

Official Website

http://dgame-dev.de/

dgame's People

Contributors

dgame avatar growlercab avatar kr41 avatar leotada avatar vl-01 avatar windspar avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

dgame's Issues

General errors

[1] - see bottom

C:\jpro\dpro2\OtherPeoples\Dgame>dub
Building dgame 0.5.0-beta.2+commit.1.gd66bf03 configuration "lib", build type de
bug.
Running dmd...
4u
16u
64u
72u
4u
20u
8u
8u
32u
source\Dgame\Graphic\Surface.d(180): Error: @nogc function 'Dgame.Graphic.Surfac
e.Surface.loadFromFile' cannot call non-@nogc function 'std.file.exists'
source\Dgame\Graphic\Surface.d(180): Error: 'std.file.exists' is not nothrow
source\Dgame\Graphic\Surface.d(177): Error: function 'Dgame.Graphic.Surface.Surf
ace.loadFromFile' is nothrow yet may throw
source\Dgame\Graphic\Surface.d(608): Error: function Dgame.Math.Rect._transfer i
s not accessible from module Surface
source\Dgame\Graphic\Surface.d(609): Error: function Dgame.Math.Rect._transfer i
s not accessible from module Surface
source\Dgame\Graphic\Surface.d(633): Error: function Dgame.Math.Rect._transfer i
s not accessible from module Surface
source\Dgame\Graphic\Surface.d(634): Error: function Dgame.Math.Rect._transfer i
s not accessible from module Surface
source\Dgame\System\Font.d(170): Error: module Dgame.System.Font function Dgame.
Graphic.Color._transfer is private
source\Dgame\System\Font.d(170): Error: function Dgame.Graphic.Color._transfer i
s not accessible from module Font
source\Dgame\System\Font.d(171): Error: module Dgame.System.Font function Dgame.
Graphic.Color._transfer is private
source\Dgame\System\Font.d(171): Error: function Dgame.Graphic.Color._transfer i
s not accessible from module Font
source\Dgame\Graphic\Text.d(67): Error: template instance Dgame.System.Font.Font
.render!() error instantiating
source\Dgame\Window\Window.d(145): Error: module Dgame.Window.Window function Dg
ame.Window.Internal.Init._initSDL is private
source\Dgame\Window\Window.d(145): Error: function Dgame.Window.Internal.Init._i
nitSDL is not accessible from module Window
source\Dgame\Window\Window.d(148): Error: module Dgame.Window.Window function Dg
ame.Window.Internal.Init._initGLAttr is private
source\Dgame\Window\Window.d(148): Error: function Dgame.Window.Internal.Init._i
nitGLAttr is not accessible from module Window
source\Dgame\Window\Window.d(159): Error: module Dgame.Window.Window function Dg
ame.Window.Internal.Init._initGL is private
source\Dgame\Window\Window.d(159): Error: function Dgame.Window.Internal.Init._i
nitGL is not accessible from module Window
source\Dgame\Window\Window.d(125): Error: template instance Dgame.Window.Window.
Window.__ctor!() error instantiating
FAIL .dub\build\lib-debug-windows-x86-dmd_2066-7A96EE8F0A68A2410292AA6D54ADEF4C
Dgame staticLibrary
Error executing command run: dmd failed with exit code 1.

[1] After I've commented out the 3 similar lines in three eg "package(Dgame.Window):"

Make Rect a template to allow for floating point

When using Vector2f for positions and Rects for bounding boxes, you end up having a lot of expensive casts from floats to ints every where. Making Rect a template that could accept any numerical value type would fix this.

[bug] build on Linux - slashes in Derelict3 path

In build.d on Linux should be "/" instead of "".
If it is not, dgame builder will not find the path to the folder.

build.d

enum DerelictDirname = "/derelict";
    string derelictPath = args[0].absolutePath().dirName() ~ "/../.." ~ DerelictDirname;

[bug] Build - Sprite.d - line 40

../Graphics/Sprite.d(40): Error: function Dgame.Graphics.Texture.Texture.render (const(Render) render) const is not callable using argument types (Rect!(short), Rect!(short)_)

0.4.2 breaks sprite rendering on linux

Hi,

I just tried 0.4.2 on linux and I get a black screen with no sprites rendered. When I downgrade back to Dgame 0.4.1 the app works again.

My test app is the DInvaders demo on the Dgame website on linux.

Thanks,
stew

Setting OpenGL version needs to be before window creation

SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_FORWARD_COMPATIBLE_FLAG);

They are after window creation.

Not on DUB

Pretty important feature that would make this way more popular. (and easier to setup)

Rendering On A High DPI Screen Is Broken

I am on a retina Mac Book Pro, and when the window is rendered, the actual contents of the window are rendered in the bottom left hand side of the window and do not take up the actual space.

screen shot 2015-05-29 at 5 05 11 pm

The text object for the FPS counter is positioned at 0,0. The content is being rendered at its actual size rather than the scaled resolution.

Determine text size before drawing

In order to draw a dynamic text centered I would like to shift it by half its width to the left before drawing it.

However, currently the width of a text is only calculated upon drawing, hence, I will always receive the previous frame's text width as the "current" width of the text, even though I might have changed the contents and thus the text width.

A possible fix renders the text to a texture before returning the texture width, iff _redraw is true when the width is fetched. This should usually not lead to multiple render operations since the common order of updating text is

  • .setData
  • .width (render to texture!)
  • .setPosition
  • .draw (no re-render since _redraw == false)

Same goes for height, of course.

Incorrect tutorial guidance on limiting framerate.

The tutorial on limiting framerate suggests using the following:

if (sw.getTicks() >= TICKS_PER_FRAME) {
    // Do game logic
    // ...
    sw.reset();
}

I think this should actually be sw.getElapsedTicks, which would be zeroed out by sw.reset.
sw.getTicks will continue increasing, and after it reaches TICKS_PER_FRAME the first time will trigger the game logic on every pass.

Fails to compile on linux x86_64

System: Arch Linux x86_64
D-ver: dmd.2.065-rc1
Dgame-ver:

commit 557778b 1 parent 2a190f8
master
rswhite rswhite authored a day ago
Clean up and adapted version.

Window/MessageBox.d(148): Error: cannot implicitly convert expression (this.box_buttons.length) of type ulong to int.

I simply added a cast(int):
mdb.numbuttons = **cast(int)**this.box_buttons.length;

I'd submit a pull request but cannot get access while travelling with work, sorry.

Text display defect

//I'm using Windows 7 for this
//Text display is effected badly by drawing a quad with Fill.Line or Fill.Point.
// Also, Shape.Fill.Line effects at leased texture (or what ever). (not shown in the example)

import std.stdio;

import Dgame.Graphic;
import Dgame.Math;
import Dgame.Audio;
import Dgame.System;
import Dgame.Window;

Shape littleSquare;

void main() {
    Window wnd = Window(480, 640, "Dgame App - Test", Window.Style.Default, GLSettings(0, 0, 0));

    littleSquare = new Shape(Geometry.Quad, [Vertex(10,10), Vertex(20,10), Vertex(20,20), Vertex(10, 20)]);
    littleSquare.fill = Shape.Fill.Line; // 'Point' does it too, but not 'Full'

    Font fnt = Font("samples/font/arial.ttf", 22);
    Text curFps = new Text(fnt);
    curFps.setPosition(200, 10);

    StopWatch fps_sw;

    Event event;

    bool loop = true;
    while(loop) {
        curFps.format("Current FPS: %d.", fps_sw.getCurrentFPS());

        while (wnd.poll(&event)) {
            if (event.type == Event.Type.Quit) {
                loop = false;
            } else if (event.type == Event.Type.KeyDown) {
                if (event.keyboard.key == Keyboard.Code.Esc)
                    wnd.push(Event.Type.Quit);
            }
        }

        wnd.clear();

        wnd.draw(curFps);

        wnd.draw(littleSquare);

        wnd.display;
    } // while main loop
}

Unicode support

I plan to use a lots of text (on russian, as example), but it doesn't renders correctly. Is it possible to draw non-latin characters with Dgame?

[Compiler bug?] Build - Internal error: eh.c 54

lunar@lunar-All-Series ~/Projects/_libs/dgame_1/Dgame/build $ ./build
Assume '/home/lunar/Projects/_libs/dgame_1/derelict' as derelict path.
Verify...

Building all packages.

Building Dgame/Audio

../Audio/VorbisFile.d
../Audio/all.d
../Audio/Listener.d
../Audio/SoundFile.d
../Audio/WaveFile.d
../Audio/Sound.d
../Audio/Core/core.d

dmd -lib -O -release -inline -wi -of../lib/Release/libDgameAudio.a  ../Audio/VorbisFile.d ../Audio/all.d ../Audio/Listener.d ../Audio/SoundFile.d ../Audio/WaveFile.d ../Audio/Sound.d ../Audio/Core/core.d -I/home/lunar/Projects/_libs/dgame_1
Build succeeded.

Building Dgame/Window

../Window/all.d
../Window/EventHandler.d
../Window/Window.d
../Window/Event.d
../Window/VideoMode.d

dmd -lib -O -release -inline -wi -of../lib/Release/libDgameWindow.a  ../Window/all.d ../Window/EventHandler.d ../Window/Window.d ../Window/Event.d ../Window/VideoMode.d -I/home/lunar/Projects/_libs/dgame_1
Internal error: eh.c 54

Build Failed!

[feature request] Sprite repeat.

I think one image worth 1000 words, so here it is:
repeat

Currently I don't see the easy way to implement this (quite common) effect with Dgame. Are there any plans on implementing it? I'm pretty new to D and OpenGL in general, so unfortunatenetly I can't make a proper PR at the moment.

Gamepad Support

Hi this is not really a bug report, more of a feature request. Gamepad support would be great when using DGame for platformer development :)

[derelict3] Failed to load OpenGL symbol [glTextureStorage1DEXT]

Hi, I got a runtime error. What am I doing wrong?
Console output:

derelict.util.exception.SymbolLoadException@..\import\derelict\util\exception.d(
38): Failed to load OpenGL symbol [glTextureStorage1DEXT]
----------------
0x0042EFC6
0x0042E417
0x0042A7A2
0x004020B2
0x00410044
0x00410017
0x0040FF2F
0x0040D154
0x004391A5
0x76DE33AA in BaseThreadInitThunk
0x77819EF2 in RtlInitializeExceptionChain
0x77819EC5 in RtlInitializeExceptionChain
----------------

CPU: Intel 4770k
GPU: Intel HD Graphics 4600
All necessary libs are linked:

pragma(lib, DerelictPath ~ "\\lib\\dmd\\DerelictSDL2.lib");
pragma(lib, DerelictPath ~ "\\lib\\dmd\\DerelictUtil.lib");
pragma(lib, DerelictPath ~ "\\lib\\dmd\\DerelictGL3.lib");
pragma(lib, DerelictPath ~ "\\lib\\dmd\\DerelictAL.lib");
pragma(lib, DerelictPath ~ "\\lib\\dmd\\DerelictOGG.lib");

pragma(lib, DgamePath ~ "\\lib\\Release\\DgameSystem.lib");
pragma(lib, DgamePath ~ "\\lib\\Release\\DgameWindow.lib");
pragma(lib, DgamePath ~ "\\lib\\Release\\DgameInternal.lib");
pragma(lib, DgamePath ~ "\\lib\\Release\\DgameMath.lib");
pragma(lib, DgamePath ~ "\\lib\\Release\\DgameGraphics.lib");
pragma(lib, DgamePath ~ "\\lib\\Release\\DgameAudio.lib");

and drivers are installed.
Is it drivers/OpenGL error, and it's useless to do anything?

Build error: ../Window/Window.d(257): Error: not a property alloc

Building Dgame/Window

../Window/all.d
../Window/EventHandler.d
../Window/Window.d
../Window/Event.d
../Window/VideoMode.d

dmd -lib -O -release -inline -property -wi -oflib/Release/libDgameWindow.a ../Window/all.d ../Window/EventHandler.d ../Window/Window.d ../Window/Event.d ../Window/VideoMode.d -I/home/lunar/Projects/_libs/temp

../Window/Window.d(257): Error: not a property alloc

Build Failed!

rotate shape in vector direction

how is it possible to rotate shape in vector direction? currently i have angle between position and velocity. i need object to be aligned with velocity vector.

Loading Surface from file sometimes fails due to invalid file name string type

Loading Surface from file sometimes doesn't work.

    /**
     * Load from filename. If any data is already stored, the data will be freed.
     */
    @nogc
    bool loadFromFile(string filename) nothrow {
        import std.file : exists;

        immutable bool ex = exists(filename);
        if (!ex) {
            print_fmt("File %s does not exists.\n", filename.ptr);
            return false;
        }

        SDL_FreeSurface(_surface); // free old surface

        _surface = IMG_Load(filename.ptr);
        if (!_surface) {
            print_fmt("Could not load image %s. Error: %s.\n", filename.ptr, SDL_GetError());
            return false;
        }

        assert(_surface.pixels, "Invalid pixel data.");

        return true;
    }

Take note, that filename.ptr is passed to IMG_Load function. IMG_Load is C function, so it operates zero-terminated strings. But D string is not zero-terminated. So if memory for a D string is allocated without trailing zero, loadFromFile() will not work. Here is the test:

    string filenameWithTail = "samples/images/XS.png;trailing chars goes here";
    string cleanFilename = filenameWithTail[0..21];
    writefln("Clean filename is '%s'", cleanFilename);
    Surface invalidSurface = Surface(cleanFilename);

The output will be:

Clean filename is 'samples/images/XS.png'
Could not load image samples/images/XS.png;trailing chars goes here. Error: Couldn't open samples/images/XS.png;trailing chars goes here.

It usually works, because D compiler puts zero at the end of static strings. But if you get string from file, it won't. The fast fix is to use toStringz function from std.string module:

        _surface = IMG_Load(filename.toStringz);

But it doesn't work with @nogc declaration of loadFromFile(). So I don't know how to fix it and keep this declaration.

64-bit build broken on ~master

I'm on Arch x86-64 using dub 0.9.23 and encountered the error below trying to build Dgame after a dub upgrade:

Building dgame ~master configuration "lib", build type debug.
Running dmd...

../../../.dub/packages/dgame-master/source/Dgame/Graphic/Texture.d(314): Error: cannot implicitly convert expression (this.getByteSize()) of type ulong to immutable(uint)

FAIL ../../../.dub/packages/dgame-master/.dub/build/lib-debug-linux.posix-x86_64-dmd_2067-A10EA19733943F1D00C910E56DC7F2DC/ Dgame staticLibrary

Error executing command build:
dmd failed with exit code 1.

tutorial mistakes and window surface access

It would appear as if the tutorial on drawing shapes has a couple of small typo's, where "Geometry.Quad" should become "Geometry.Quads",analogous for "Geometry.Triangle".

Also, I'd really like to know how a simple paint application should be written. As far as I can see it is only possible to access single pixels in surface objects but to draw them I'd first need to create a new texture and from that a new sprite (and repeat this every time I update the surface).
Seems terribly inefficient. SDL seems to have "SDL_Getwindowsurface", could something analogous be added?
If not, what is the preferred way to have individual pixel access?

LDC Fails to Compile Dgame

Despite Dgame compiling just fine in dmd, ldc throws syntax errors. Here is the error log:

$ dub build --force --compiler=ldc                                                                                                                    
Building derelict-util 2.0.0 configuration "library", build type debug.
Running ldc...
Building derelict-sdl2 1.9.5 configuration "library", build type debug.
Running ldc...
Building derelict-gl3 1.0.13 configuration "library", build type debug.
Running ldc...
Building dgame 0.5.3 configuration "lib", build type debug.
Running ldc...
../../../../.dub/packages/dgame-0.5.3/source/Dgame/Graphic/Color.d(30): Error: Declaration expected, not '('
../../../../.dub/packages/dgame-0.5.3/source/Dgame/Graphic/Color.d(35): Error: no identifier for declarator dst.g
../../../../.dub/packages/dgame-0.5.3/source/Dgame/Graphic/Color.d(35): Error: Declaration expected, not '='
../../../../.dub/packages/dgame-0.5.3/source/Dgame/Graphic/Color.d(36): Error: no identifier for declarator dst.b
../../../../.dub/packages/dgame-0.5.3/source/Dgame/Graphic/Color.d(36): Error: Declaration expected, not '='
../../../../.dub/packages/dgame-0.5.3/source/Dgame/Graphic/Color.d(37): Error: no identifier for declarator dst.a
../../../../.dub/packages/dgame-0.5.3/source/Dgame/Graphic/Color.d(37): Error: Declaration expected, not '='
../../../../.dub/packages/dgame-0.5.3/source/Dgame/Graphic/Color.d(39): Error: Declaration expected, not 'return'
../../../../.dub/packages/dgame-0.5.3/source/Dgame/Graphic/Color.d(40): Error: unrecognized declaration
../../../../.dub/packages/dgame-0.5.3/source/Dgame/Graphic/Surface.d(701): Error: Declaration expected, not '('
../../../../.dub/packages/dgame-0.5.3/source/Dgame/Graphic/Surface.d(703): Error: Declaration expected, not 'assert'
../../../../.dub/packages/dgame-0.5.3/source/Dgame/Graphic/Surface.d(705): Error: function declaration without return type. (Note that constructors are always named 'this')
../../../../.dub/packages/dgame-0.5.3/source/Dgame/Graphic/Surface.d(705): Error: no identifier for declarator SDL_SetWindowIcon(wnd, _surface)
../../../../.dub/packages/dgame-0.5.3/source/Dgame/Graphic/Surface.d(709): Error: Declaration expected, not '('
../../../../.dub/packages/dgame-0.5.3/source/Dgame/Graphic/Surface.d(711): Error: unrecognized declaration
../../../../.dub/packages/dgame-0.5.3/source/Dgame/Internal/Error.d(3): Error: Declaration expected, not '('
../../../../.dub/packages/dgame-0.5.3/source/Dgame/Internal/Error.d(11): Error: function declaration without return type. (Note that constructors are always named 'this')
../../../../.dub/packages/dgame-0.5.3/source/Dgame/Internal/Error.d(11): Error: no identifier for declarator sprintf(buf.ptr, msg.ptr, args)
../../../../.dub/packages/dgame-0.5.3/source/Dgame/Internal/Error.d(12): Error: Declaration expected, not 'assert'
../../../../.dub/packages/dgame-0.5.3/source/Dgame/Internal/Error.d(13): Error: unrecognized declaration
../../../../.dub/packages/dgame-0.5.3/source/Dgame/Internal/m3.d(3): Error: Declaration expected, not '('
FAIL ../../../../.dub/packages/dgame-0.5.3/.dub/build/lib-debug-posix.osx-x86_64-ldc_0-B2CD737D321071211552448D5B4950B6/ Dgame staticLibrary
Error executing command build:
ldc failed with exit code 1.

Transparency fail

I set a colour for transparency, but it doesn't work on Dgame, (it works on other programs, like GIMP).

DerelictGL3 not able to find symbol ( glGetnTexImage )

The symbol glGetnTexImage was added with GL4.5. A while ago I had no issue with this, however recently (without even updating DGame, did a dependency change?) I suddenly get this error any time I create a Window.

Appearently the error is caused by my graphics cards max driver version for OpenGL being below 4.5. But apparently it's trying to use version 4.5 when I don't have said version for my system. The suggested solution is to use DerelictGL3.reload(GLVersion.None, GLVersion.GL44), however this is not possible to do before creating a new Window, because it requires an OpenGL context to exist, and if I do it after creating the window then I get the error before I have a chance to tell it to not try loading that version.

I'm not exactly sure what can be done about this issue, as it's really been infuriating me for a few months now. I've tried many times to figure this out myself and it's not working.

In the error log, the last trace within your code is:
AppData\Roaming\dub\packages\dgame-0.6.4\source\Dgame\Window\Internal\Init.d(192)

immutable GLVersion glver = DerelictGL.reload();

Maybe allow some way to allow users to pass in maximum version to use in the reload command, or something?

Trying to modify const variables

source/Dgame/Window/Internal/Init.d(130): Error: cannot modify const expression gl_settings.majorVersion
source/Dgame/Window/Internal/Init.d(131): Error: cannot modify const expression gl_settings.minorVersion

I took the const out, and it all went through.

Error in dub.json on ~0.5.0 branch

When I try to build any app using Dgame 0.5.0 I get this error message:

Failed to parse package description for dgame ~0.5.0 in remote location.
Package dgame ~0.5.0 could not be loaded either locally, or from the configured package registries.
Fetching dgame ~0.5.0 (getting selected version)...
Placing dgame ~0.5.0 to $HOME/.dub/packages/...
Failed to parse package description for dgame ~0.5.0 in $HOME/.dub/packages/dgame-0.5.0.
Error executing command build:
TargetType does not have a member named 'lib'

Looking at the dub.json, the "targetType" needs to be either "sourceLibrary" or just "library" but not "lib".

Iterating over SpriteSheet starts at index 1 and ends at index 0

Hi, thanks for providing this excellent game library for D.
It seems to me, that iterating over a SpriteSheet using slideTextureRect() as described in the tutorial for the explosion starts with the rectangle at index 1 and ends with index 0. This can be seen when using a large timeout explosion.timeout = 1000; and explosion.numOfExecutions = 1; .
Kind regards,
Axel

Anti aliasing is crashing in Dgame 0.6.0-rc.1 on OSX

Continued from #46

Using the following code with 0.6.0-rc.1

import Dgame.Window;
import Dgame.System.StopWatch;

void main() {
    GLContextSettings gl_settings;
    gl_settings.antiAlias = GLContextSettings.AntiAlias.X4;

    Window window = Window(
        1280,
        720,
        "Dungeon Game",
        Window.Style.Default,
        gl_settings
    );
    window.clear();
    wnd.display();
    StopWatch.wait(2000);
}

I get the following result

$ dub
Target derelict-util 2.0.0 is up to date. Use --force to rebuild.
Target derelict-sdl2 1.9.5 is up to date. Use --force to rebuild.
Target derelict-gl3 1.0.13 is up to date. Use --force to rebuild.
Target dgame 0.6.0-rc.1 is up to date. Use --force to rebuild.
Building dungeon ~master configuration "application", build type debug.
Compiling using dmd...
Linking...
Running ./dungeon
SDL version: 2.0.3
OpenGL Context created in OpenGL version 2.1
Set 4 as anti alias level
Error executing command run:
Program exited with code -11

Dgame Does not render on multiple windows

Hello, so I've been experimenting with the framework and I tried to implement a game that has more than two windows.

The first window is the main game and the second window is a smaller one with the various commands you can select.

So I tried to render sprites onto the first window and the second window, and failed.


window_1.clear();
window_2.clear();
window_1.draw(sprite_1);
window_2.draw(sprite_2);
window_1.display();
window_2.display();

So far, when two windows are called to clear, draw and display, it didn't render anything. There was no error message, but once I commented out the window_2 calls, it rendered the first window without flaw.

So are multiple windows supported here?

Crashes when D string passed to C function using .ptr

There a number of places in Dgame where D strings are passed to D functions using some_string.ptr. I think the .ptr needs to be replaced with .toStringz. I'm not sure because the crashes are not on all calls to C functions taking a D string via .ptr so it could be a bug in my own code.

But I think it's work looking into because D strings are not 0-terminated and .ptr, as I understand it, doesn't append '\0'. That's what toStringz is for.

I see errors like the following...

E.g. in my code I have

auto s = Surface("my_image.png");

This results in a call to Surface.d::loadFrmoFile(string filename), which in turn calls _surface = IMG_Load(filename.ptr) with the following runtime result...

Could not load image my_img.png�PowerInfo.

The '�PowerInfo' part is where IMG_Load(filename.ptr); has run off the end of the string because it's missing the null terminator.

My workaround for now is to manually add an ugly \0 to the D strings like so:

auto s = Surface("my_image.png\0");

Math Vector2 linking error

Hi!
I got a linking error:

Symbol Undefined _D5Dgame4Math7Vector214__T7Vector2TfZ7Vector25opCmpMxFNaNbKxS5Dgame4Math7Vector214__T7Vector2TfZ7Vector2Zi

after adding this code (as example)

int x=5;
Shape healthbar = Shape.make(Shape.Type.Quad, [Vector2f(x, x)]);

All Dgame libraries was linked, but error is still here.

My Dgame version is: a20d6d5 (last build from github)
Compiler: DMD ver. 2.063.2
IDE: CodeBlocks 12.11

Regards, Alex.

Static Sprite Object

Hi, is there a class, which I can use instead of Sprite, if I already know the Object won't get changed/moved/modified etc. during the rest of the game session? I need it for a game, which loads in the map as a .png. The player has to draw his maps with paint or other stuff and can put this pic into the maps folder and directly is able to play it. So I want to have it as exchangeable as possible. Thats why a Tilemap isn't the best solution to my problem.

StopWatch Divide by 0 when trying to fill frame_ms

There's a bug in StopWatch. If you set frame_ms to a non-null value, to fill the frame_ms variable, you get a Divide by Zero error. The code below is from your GitHub source. I added some comments to show where the problem is.

@nogc
uint getCurrentFPS(uint* frame_ms = null) nothrow {
    immutable uint elapsed_ticks = this.getElapsedTicks();
    if (elapsed_ticks >= 1000) {
        _currentFps = _numFrames;
        _numFrames = 0;// When this if statement operates, _numFrames is set to 0
        this.reset();
    }

    if (frame_ms)
        *frame_ms = elapsed_ticks / _numFrames;// _numFrames was just set to 0 above
    _numFrames++;

    return _currentFps;
}

You could create a local variable and use that instead.

@nogc
uint getCurrentFPS(uint* frame_ms = null) nothrow {
    immutable uint elapsed_ticks = this.getElapsedTicks();
    uint _numFramesLocal = _numFrames;
    if (elapsed_ticks >= 1000) {
        _currentFps = _numFrames;
        _numFrames = 0;
        this.reset();
    }

    if (frame_ms)
        *frame_ms = elapsed_ticks / _numFramesLocal;// Still has the value from before the reset
    _numFrames++;

    return _currentFps;
}

_numFrames is not incremented during the point between the local variable create and use, so it always holds the same value that _numFrames would have if it hadn't been set to 0. There is another way to solve this issue, and that is to just rearrange the method a bit:

@nogc
uint getCurrentFPS(uint* frame_ms = null) nothrow {
    immutable uint elapsed_ticks = this.getElapsedTicks();

    if (frame_ms)
        *frame_ms = elapsed_ticks / _numFrames;

    if (elapsed_ticks >= 1000) {
        _currentFps = _numFrames;
        _numFrames = 0;
        this.reset();
    }
    _numFrames++;

    return _currentFps;
}

Sorry for so many frequent Issues, but I'm using your library extensively and am finding a lot of problems.

Shape color is being changed by unrelated objects

I create in the code below, 1 shape with Geometry.Quads, Then I create a Surface, Texture and a Sprite. The texture has a color of orange as it's base color.

I do not call setTexture() on the shape. The following occurs:

  • If I do not render the sprite, the shape becomes orange even though I set its color to Color4b.White
  • If I render the sprite before rendering the shape the shape renders white, as it should.
  • If I render the sprite after rendering the shape the shape also renders white

So it seems that for some reason, if I create a sprite and don't render it, it affects the other objects in the scene somehow.

void main() {
    Window wnd = Window(640, 480, "Dgame Test");

    wnd.setClearColor(Color4b.Black);

    Shape fightbox = new Shape(Geometry.Quads,
        [
            Vertex(50  , 50 ),
            Vertex(200 , 50 ),
            Vertex(200 , 200),
            Vertex(50  , 200)
        ]
    );
    fightbox.fill = Shape.Fill.Line;
    fightbox.setColor(Color4b.White);
    fightbox.lineWidth = 4;

    Surface test_surface = Surface("sprites/test_img");
    Texture test_texture = Texture(test_surface);

    test_sprite = new Sprite(test_texture);
    test_sprite.setPosition(50, 100);

    Event event;
    while (Status.isRunning) {
        wnd.clear();

        while (wnd.poll(&event)) {
            handleEvent(event);
        }
        if(Keys.isKeyDown(Keyboard.Key.Esc))
        {
            Status.isRunning = false;
        }
        auto vect = wnd.getPosition();

        if(Keys.isKeyDown(Keyboard.Key.F))
        {
            writeln("Window Position = x(",vect.x, "), y(",vect.y,")");
        }

        //wnd.draw(test_sprite); // #1
        wnd.draw(fightbox);// #2
        //wnd.draw(test_sprite); // #3

        wnd.display();
    }

With either #1 or #3 un-commented the shape displays white, if both are commented the shape appears orange (the color of the image). Nothing else besides commenting or un-commenting those 3 statements are changed.

Without rendering the sprite:
without_sprite_render

With rendering the sprite:
with_sprite_render

It should also be noted that this issue only occurs if the sprite has transparency, tested with a solid sprite without transparency and no issue at all.

Edit, additional information:

  • Dgame 0.6.3 from DUB

Edit 2, some more testing:

  • It I placed the wnd.draw(test_sprite) inside an if statement for if the G key is held down, then i got the following results:
    • At first, upon program loading, the shape appeared orange
    • While holding the "G" key the sprite appeared and the shape went white
    • After letting go of the "G" key the sprite disapeared, and the box did not return to orange, instead it remained white.
    • As soon as the sprite renders once the bug is gone.

Edit 3, Found some more info:

  • After some testing, I have confirmed that the color of the shape is the top-left pixel of the texture.

TTF_Init is not being called, formatting Text always errors "Font Invalid"

I have loaded a Font object and a text object with said Font. When i go to use text.format(Args...) I am presented with "Font is invalid".

After a little research i decided to manually import derelict.sdl2.ttf myself and call TTF_Init()

After doing so I no longer got the error. Maybe something as simple as a static boolean somewhere for if TTF has been initialized, and upon a new Font being instantiated check that boolean and call TTF_Init when the first font is created.

This is a minor issue, but it does make following the tutorial impossible (as the tutorial doesn't include manually calling TTF_Init() and thusly errors)

Dgame Version = 0.6.3

Error when running 0.5 beta test

../Audio/Sound.d(90): Error: @nogc function 'Dgame.Audio.Sound.Sound.loadFromFile' cannot call non-@nogc function 'derelict.sdl2.mixer.Mix_LoadWAV'
../System/Font.d(172): Error: @nogc function 'Dgame.System.Font.Font.render!().render' cannot call non-@nogc function pointer 'TTF_RenderUTF8_Solid'
../System/Font.d(175): Error: @nogc function 'Dgame.System.Font.Font.render!().render' cannot call non-@nogc function pointer 'TTF_RenderUTF8_Shaded'
../System/Font.d(178): Error: @nogc function 'Dgame.System.Font.Font.render!().render' cannot call non-@nogc function pointer 'TTF_RenderUTF8_Blended'
../Graphic/Text.d(68): Error: template instance Dgame.System.Font.Font.render!() error instantiating
../Graphic/Texture.d(469): Error: no property 'getFormat' for type 'const(Texture)'
../System/Font.d(105): Error: @nogc function 'Dgame.System.Font.Font.~this' cannot call non-@nogc function pointer 'TTF_CloseFont'
../System/Font.d(120): Error: @nogc function 'Dgame.System.Font.Font.loadFromFile' cannot call non-@nogc function pointer 'TTF_OpenFont'
../System/Font.d(137): Error: @nogc function 'Dgame.System.Font.Font.setStyle' cannot call non-@nogc function pointer 'TTF_SetFontStyle'
../System/Font.d(148): Error: @nogc function 'Dgame.System.Font.Font.getStyle' cannot call non-@nogc function pointer 'TTF_GetFontStyle'
../Window/Window.d(374): Error: @nogc function 'Dgame.Window.Window.Window.hasQuitEvent' cannot call non-@nogc function 'derelict.sdl2.functions.SDL_QuitRequested'
main.d(66): Error: no property 'getFormat' for type 'Texture'
FAIL .dub/build/main-debug-posix.osx-x86_64-dmd_2066-475D155ABBFA067E77BD70242FDF64AE/ dgame-example executable
Error executing command run: dmd failed with exit code 1.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.