Taking Requests
Dustin Dettmer

I've decided, in order to spice up my motivation, I'm going to take requests for demo applications to create.

I'll make either another A.cc javascript extension or an example application for the Thing library (a D3D/OpenGL/Allegro wrapper in C++).

Ideally your request / idea:

  • Has a good ratio of time put in to coolness coming out, or

  • Showcases something cool (about the Thing library), or

  • Would be really cool

Paul whoknows

Most people here uses AGL or OpenLayer to create 2D games, and it would be nice if you can write an easy tutorial basically explaining how to convert our sprites into textured polygons using your library.
In other words, a little tutorial explaining how to get a little animated sprite moving around the screen.
Obviously I am talking about your Allegro D3D/OGL wrapper A.K.A. Thing.

Dustin Dettmer

I'll throw something together :)

Alright, here we go. The Sprite Thing example is now complete. Download Sprite Thing Example.

Heres a preview of the source code:

1#include <vector>
2#include <cmath>
3#include <allegro.h>
4#include "conf.h"
5#include "log.h"
6#include "bitmap.h"
7using namespace std;
8 
9int main()
10{
11 try {
12
13 if(0 != allegro_init())
14 throw "Unable to intialise allegro.";
15
16 Conf conf(Conf::WINDOWED, Conf::HARDWARE);
17
18 Bitmap star(load_bitmap("star.tga", 0));
19
20 clear_keybuf();
21
22 out << "Regular blit.\n";
23
24 conf.beginScene();
25 conf.clearScreen();
26
27 star.blitToScreen(0, 0);
28
29 conf.flip();
30
31 readkey();
32 clear_keybuf();
33
34 out << "Circle (scaled) blit.\n";
35
36 int i = 0;
37
38 while(++i <= 360)
39 {
40 conf.beginScene();
41 conf.clearScreen();
42
43 star.circleBlitToScreen(320, 240, 240, 0, i * M_PI / 180);
44
45 conf.flip();
46
47 rest(15);
48 }
49
50 readkey();
51 clear_keybuf();
52
53 out << "Tiled blit.\n";
54
55 conf.beginScene();
56 conf.clearScreen();
57
58 star.tileBlitToScreen(0, 0, 640, 480);
59
60 conf.flip();
61
62 readkey();
63 clear_keybuf();
64
65 out << "Rotated blit.\n";
66
67 i = 0;
68
69 while(++i <= 360)
70 {
71 conf.beginScene();
72 conf.clearScreen();
73
74 star.specialBlitToScreen(0, 0, 1, 1, i / 360.0f);
75
76 conf.flip();
77
78 rest(15);
79 }
80
81 readkey();
82 clear_keybuf();
83
84 out << "Pivoted blit.\n";
85
86 i = 0;
87
88 while(++i <= 360)
89 {
90 conf.beginScene();
91 conf.clearScreen();
92
93 star.pivotBlitToScreen(320, 240, -150, -150, i / 360.0f);
94
95 conf.flip();
96
97 rest(15);
98 }
99
100 readkey();
101 clear_keybuf();
102
103 } catch(const char *err)
104 {
105 Conf::handleCaughtError(err);
106 }
107}
108END_OF_MAIN()

Paul whoknows

Woooow thanks!
Unexpectedly I compiled your previous example and this one without problems.

I have some questions:

1 - What is aldumb.h? it's #included in conf.cpp, I have had to remove it to make it work.

2 - In the sprite example, SOFTWARE and HARDWARE modes works fine, but D3D mode does not work, I get an "Error creating Direct3D Object"

//I replaced this
Conf conf(Conf::WINDOWED, Conf::HARDWARE);
//whith this
Conf conf(Conf::WINDOWED, Conf::D3D);

3 - I get a 4MB executable when I compile the sprite example! and it needs the d3d9.dll to work.
How can I statically compile the example?
How can I reduce the file size?

4 - Is there a function to use additive and alpha blending?

I really liked this example! needless to say that I need to spend more time looking at the headers.

Dustin Dettmer
Quote:

1 - What is aldumb.h? it's #included in conf.cpp, I have had to remove it to make it work.

That was in by mistake :-[.

Quote:

2 - In the sprite example, SOFTWARE and HARDWARE modes works fine, but D3D mode does not work, I get an "Error creating Direct3D Object"

Hmm... Try installing direct X 9 maybe?

Quote:

//I replaced this
Conf conf(Conf::WINDOWED, Conf::HARDWARE);
//whith this
Conf conf(Conf::WINDOWED, Conf::D3D);

Yes this is the way to switch from OpenGL mode to D3D mode.

Quote:

How can I statically compile the example?

The d3dx9.dll dependency is stuck for now. In the future I plan to make the dll dynamically loaded and simply make the D3D driver fail if it is not found. For now the only way to remove the dependency is to compile with the NO_D3D macro defined.

Quote:

How can I reduce the file size?

I'm not sure why its so large for you... did you strip the executable?

Quote:

4 - Is there a function to use additive and alpha blending?

Yes this is supported by every drawing method. The parameter its controlled with is 'tint'. Heres the Tint class for reference:

struct Tint {
    
    float r, g, b, a;
    
    // True if the blit should be done with additive blending.
    bool additive;
    
    Tint(float red = 1, float green = 1, float blue = 1, float alpha = 1, bool add = false)
        : r(red), g(green), b(blue), a(alpha), additive(add)
    {
        
    }
};

Quote:

I really liked this example! needless to say that I need to spend more time looking at the headers.

:D:)

Paul whoknows

I was compiling adding debug information::), now I get a 0.9MB executable file!

I have DirectX 9.0b in my system , do I need to install DirectX 9.0c to make it work?
Could It be possible to provide D3D support for lower versions of DirectX?

Quote:

Yes this is supported by every drawing method. The parameter its controlled with is 'tint'. Heres the Tint class for reference:

As I said I need to spend more time looking at the headers:)
I'll try to write a little program.

Dustin Dettmer
Quote:

I have DirectX 9.0b in my system , do I need to install DirectX 9.0c to make it work?
Could It be possible to provide D3D support for lower versions of DirectX?

IIRC D3D was incorporated in DirectX 8. There was some good reason that made since way back when to just use version 9 instead of 8, though I don't remember it just now.

Any way you could get a back-trace on which line is failing in conf.cpp?

Mark Oates

I'm a big tower defense fan. :)

Paul whoknows

I play games using DirectX 9.0b without problems, I don't know what could be wrong?

It seems that this is the part of code that throws the error:

Quote:

g_pD3D = Direct3DCreate9(D3D_SDK_VERSION);

if(g_pD3D == NULL)
throw "Error creating Direct3D Object.";

Dustin Dettmer

Hmm.. Heres some insight from msdn

msdn said:

If this function fails, it indicates that the header file version does not match the runtime DLL version.

What version of the D3D devpack did you install?

http://msdn2.microsoft.com/en-us/library/bb173465.aspx

**

Quote:

I'm a big tower defense fan. :)

Hmmm... Any ideas on how to take that idea and make it less work / time? I don't want to start a full new project, just something small to get my fire going.
** edited in later

Paul whoknows

I installed DirectX 9.0c, and now the sample works with D3D:D
However the example looks different when D3D mode is used.

The circle scaled blit code only works with HARDWARE(why don't you call it OPENGL?)
It does not work in SOFTWARE and D3D modes.
The star looks antialiased only with HARDWARE, I think it should look the same with D3D.

Quote:

What version of the D3D devpack did you install?

DirectX90C.DevPack

Dustin Dettmer
Quote:

The star looks antialiased only with HARDWARE, I think it should look the same with D3D.

This is a setting in your driver panel.

Quote:

The circle scaled blit code only works with HARDWARE

Never got around to implementing it for D3D, its on my todo list. Working for SOFTWARE is more work then its really worth.

Paul whoknows

I was doing some testings.(test.cpp and bitmap attached.)

I created a tint to set the opacity in 50%, it works in D3D, but it does not work in HARDWARE.
Additive = true

http://www.allegro.cc/files/attachment/591743

In FULLSCREEN and D3D after the program finishes, my desktop remains in 640x480, and the program continues resident in memory.

In FULLSCREEN and HARDWARE my monitor shows this message "238Hz frequency not supported"
I also have this problem with some OGL and OL games. Is there a way to force a standar refresh rate like 60, 85, or 100hz? In AllegroGL I use Allegro's request_refresh_rate(x) to solve it, but this time that did not work.

tileBlitToScreen works fine in HARDWARE but it shows something weird in D3D mode.

http://www.allegro.cc/files/attachment/591744

Quote:

This is a setting in your driver panel.

I set antialiasing to 8x but it looks aliased.
If I set antialias to Application controlled, can I control it with some lines of code from my application?

Dustin Dettmer
Tint blending(1, 1, 1, 127, true);

Should be

Tint blending(1, 1, 1, .5, true);

Quote:

In FULLSCREEN and HARDWARE my monitor shows this message "238Hz frequency not supported"
I also have this problem with some OGL and OL games. Is there a way to force a standar refresh rate like 60, 85, or 100hz? In AllegroGL I use Allegro's request_refresh_rate(x) to solve it, but this time that did not work.

Ah, you've found a bug :)

Try this new version of conf.cpp.

As far as requesting a specific refresh rate, thats a much bigger development challenge (just take a look at the amount of work allegroGL does to find the correct mode!)

**
Hm, the reason version 9 is the only supported version of DirectX is because thats the only version I could find a gcc converted library for. It looks as if that DevPack is using DirectX9.0c which sucks a lot...

I once tried to convert my own DirectX libraries over but that is no picnic. Does anybody know more on the subject of translating MSVC libraries for use with gcc?
** edited in afterwards

Paul whoknows
Quote:

Should be
Tint blending(1, 1, 1, .5, true);

It's my fault!, sorry.

Quote:

Ah, you've found a bug :)

And it is still there, I tried your new conf.cpp but I did not notice any difference.
In FULLSCREEN and HARDWARE I get the aforementioned message about the unsupported frequency.
But it's worse in FULLSCREEN and D3D. At first it works without problem, but when the application ends, it remains in memory and set my desktop to 640x480 and it changes my desktop wallpaper, not a nice thing at all.

I would like to use your Thing in my current project, I have found it extremely easy to use, however these little problems should be fixed first.
If I only knew something about D3D:'( I think I could fix those little problems.
Can you recomend me a tutorial for beginners?

Dustin Dettmer
Quote:

I would like to use your Thing in my current project, I have found it extremely easy to use, however these little problems should be fixed first.
If I only knew something about D3D:'( I think I could fix those little problems.

Yes these problems need to be fixed.

Can you tell me more about the opengl frequency problem? You cant do FULLSCREEN?

http://www.gamedev.net/reference/articles/article1943.asp

Paul whoknows

My monitor does not allow non-standar refresh rates, when that happens it goes black and it shows a message saying "132k/239Hz frequency out of range", well in this particular case it was 239Hz.

That's why I need to force a standar refresh rate like 60, 70, 72, 75, 85, 90, or 100Hz, I don't want my game running at a higher refresh rate, that only happens in FULLSCREEN and HARDWARE mode.

In FULLSCREEN and D3D mode it works, but it seems that there is something wrong in the D3Dshutdown(), because once the application ends, it remains in memory and it makes a mess in my desktop, it changes the resolution to 640x480, icons missed, really ugly.

Dustin Dettmer
Quote:

In FULLSCREEN and D3D mode it works, but it seems that there is something wrong in the D3Dshutdown(), because once the application ends, it remains in memory and it makes a mess in my desktop, it changes the resolution to 640x480, icons missed, really ugly.

Is this because its crashing? Theres a bug I'm currently working on where D3D crashes on close from fullscreen.

Quote:

That's why I need to force a standar refresh rate like 60, 70, 72, 75, 85, 90, or 100Hz, I don't want my game running at a higher refresh rate, that only happens in FULLSCREEN and HARDWARE mode.

This is interesting... allegroGL should be finding a refresh rate closest to the one requested. Do other allegroGL applications work on your machine?

Paul whoknows
Quote:

Is this because its crashing? Theres a bug I'm currently working on where D3D crashes on close from fullscreen.

In my PC when I try to close the application(in FULLSCREEN), it fails to close, and it reamins in memory and it makes a mess in my desktop, and I have to kill the application manually, yes I think this could be related.

Quote:

Do other allegroGL applications work on your machine?

Yes, I tried all AllegroGL examples and they work.
I also tried an old Nehe example modified to be compiled with AllegroGL(with a lot of deprecated AGL functions), but this one failed to find a supported refresh rate and my monitor displayed the message I already said, but I fixed this problem with Allegro's set_refresh_rate();
My video card is a FX5700LE with 128MB, it supports pixel/vertex shader 2.0+, I think it should not be problems with this card.

Thread #590842. Printed from Allegro.cc