Jump to content
Sign in to follow this  
cppman

A2D v2

Recommended Posts

cppman

UPDATED

Now supported surfaces...

Well, I finally decided to stop being lazy, and I completely re-did that Direct3D experiment. I just decided to call this version 2.0 of my way old and dumb "graphics library" called A2D. Anyways, for those of you that don't know what this is, let me explain.

A2D is a simple 2D graphics library that supports: sprites, textures, alpha blending, scaling, and rotations. Here are some screenshots of the demos that come with the library.

Posted Image Posted Image

Posted Image Posted Image

-There are a total of 7 demos that come with the library ranging from Creating a Device to a Full Demo.

You can attach a device to any window you wish, whether it be your own, or a notepad window. The library has simple and easy to use functions that are all prefixed by "_A2D". You can initialize the library by calling, _A2DStartup and shutdown the engine by calling, _A2DShutdown. In order to see all of the functions, and how to use them I recommend looking at the A2D.au3 include file. The prototypes have a short description, a list of parameters, and information about the return value(s).

You can also choose specific options for the device you create such as: Hardware Acceleration, Software Renderer, the swap effect, and back buffer formats. Not all display formats work with windowed or fullscreen modes, so you need to check which ones you use. So far I have not had any problems with (A8R8G8B8) for both fullscreen and windowed modes. The way the format constants are named is that it contains a channel (e.g. r - red) and next to it, it contains how many bits that channel takes. So for example, A8R8G8B8 each color channel takes up 8 bits, and there are 4 channels, totalling 32 bits. Instead of having to use bitmap fonts, you can easily use true-type fonts such as arial and draw text to the screen using it! :)

Here is a list of display formats:

Global Const $A2DFORMAT_R8G8B8      = 20
Global Const $A2DFORMAT_A8R8G8B8    = 21
Global Const $A2DFORMAT_X8R8G8B8    = 22
Global Const $A2DFORMAT_R5G6B5      = 23
Global Const $A2DFORMAT_X1R5G5B5    = 24
Global Const $A2DFORMAT_A1R5G5B5    = 25
Global Const $A2DFORMAT_A4R4G4V4    = 26
Global Const $A2DFORMAT_X4R4G4B4    = 30
Global Const $A2DFORMAT_A2B10G10R10 = 31
Global Const $A2DFORMAT_A2R10G10B10 = 35
Global Const $A2DFORMAT_A16B16G16R16= 36
oÝ÷ Øw«z++-¡÷^¾'·*^±«­¢+Ø)±½°
½¹ÍÐÀÌØíÉYQeA}!I]I$ôÄ$í!ÉÝɱÉÑ¥½¸)±½°
½¹ÍÐÀÌØíÉYQeA}9U11I$ôÐí9Õ±°Iɹ)±½°
½¹ÍÐÀÌØíÉYQeA}II9
$ôÈíIɹ)±½°
½¹ÍÐÀÌØíÉYQeA}M=Q]I$ôÌíM½ÑÝÉI¹É¥¹oÝ÷ Ù©ÝêÞÆ¥Ëh~Ì¥çßyËljëh×6
Global Const $A2DSWAPEFFECT_DISCARD = 1
Global Const $A2DSWAPEFFECT_FLIP    = 2
Global Const $A2DSWAPEFFECT_COPY    = 3
oÝ÷ Ù©Ýj[(~íéÞÂË«}§~éܶ*'²«z++-¡ûazf®¶­s`¥ô$D7&VFU7W&f6R¥ô$E&VæFW%7W&f6R¥ô$E&VæFW%7W&f6TW¥ô$E6WE7W&f6UFWGW&R¥ô$E&VÆV6U7W&f6R

To use the library in any of your projects you will need 2 files: A2D.dll and A2D.au3; A2D.dll doesn't have to be in the application directory, but you will need to specify where it is at when you call _A2DStartup().

Using it may be a little difficult at first if you have never programmed using Direct3D before.

The demos are meant to be in the form of a tutorial.. meaning, they go from easier to more difficult.

A2D.zip

~Enjoy!

*note: you may need to update your version of DirectX to the latest(April 2007):

(URL to update DirectX)

http://www.microsoft.com/downloads/details...;displaylang=en

(If you get an error about missing a file.. download this, and place it with your script)

http://www.dll-files.com/dllindex/download...nload0UJkQEVDlO

Edited by chris95219

Share this post


Link to post
Share on other sites
CoderDunn

wow ... thank you so much! Could you post a few steps about compiling a plugin with visual C++ 8? I don't know what to do and I want to learn how to compile a AutoIt plugin. Thanks! Hallman

Edited by Hallman

Share this post


Link to post
Share on other sites
cppman

wow ... thank you so much! Could you post a few steps about compiling a plugin with visual C++ 8? I don't know what to do and I want to learn how to compile a AutoIt plugin. Thanks! Hallman

hmm.. I'm not very good at explaining things but here's a shot:

First you need to create a new DLL project.

Posted Image

Then you need to add the plugin sdk files to your project(header file, and c file)

Posted Image

Then you can add your plugin's code like the following:

//main.cpp - main plugin file.
#include "au3plugin.h"

//The list of functions in the plugin
AU3_PLUGIN_FUNC g_AU3_Funcs[] =
{
    //{Function Name", Minimum number of parameters, Maximum number of parameters
    {"SayHelloWorld", 0, 0}
};


AU3_PLUGINAPI int AU3_GetPluginDetails(int *n_AU3_NumFuncs, AU3_PLUGIN_FUNC **p_AU3_Func)
{
    /* Pass back the number of functions that this DLL supports */
    *n_AU3_NumFuncs = sizeof(g_AU3_Funcs)/sizeof(AU3_PLUGIN_FUNC);

    /* Pack back the address of the global function table */
    *p_AU3_Func = g_AU3_Funcs;

    return AU3_PLUGIN_OK;
}


//define the function
AU3_PLUGIN_DEFINE(SayHelloWorld)
{
    //return value
    AU3_PLUGIN_VAR *pResult = AU3_AllocVar();
    //plugin code
    char* szString = "Hello World";
    MessageBox(NULL, szString, "My Plugin Function", MB_OK);
    AU3_SetInt32(pResult, 0);

    *p_AU3_Result       = pMyResult;
    *n_AU3_ErrorCode    = 0;
    *n_AU3_ExtCode      = 0;

    return AU3_PLUGIN_OK;
}

*note: I haven't tested that, but that is the general idea of how to create a plugin.

Dunno if this helps any.. but there ya go. If want the source to this plugin, to see how I did it, or change things around.. lemme know.

Share this post


Link to post
Share on other sites
CoderDunn

Dunno if this helps any.. but there ya go. If want the source to this plugin, to see how I did it, or change things around.. lemme know.

This helps alot thanks. I don't need the source for A2D. It's more complicated than I want to mess with. If it works why change it? :)

Hallman

Edited by Hallman

Share this post


Link to post
Share on other sites
pdaughe

Very impressive -- thanks for posting! I had to make a couple of corrections (missing comma, incorrect function name) in the demo, but after that it worked great.

Impressive -- you must have worked very hard at that.

Thanks again, very much.

Paul

Share this post


Link to post
Share on other sites
smashly

Thank You chris95219 nice work.

I enjoyed your last version of this plugin, it rocked. :)

Look forward to playing with this new one over the next few days.

Cheers.

Share this post


Link to post
Share on other sites
CoderDunn

The _A2DDrawSpriteEx() function doesn't work correctly ... it cuts a few pixels off the right of the sprite. The exact same coordinates work perfectly on the first version of your plugin but doesn't work with this version.

Here is an example:

Hallman

Edited by Hallman

Share this post


Link to post
Share on other sites
cppman

The _A2DDrawSpriteEx() function doesn't work correctly ... it cuts a few pixels off the right of the sprite. The exact same coordinates work perfectly on the first version of your plugin but doesn't work with this version.

Here is an example:

Hallman

Ahh.. yeah. I saw that a little while ago, but am not sure why it is doing that. But I suppose you can work around it.. *for now*.

Just change your line of code to something like that..

_A2DDrawSpriteEx($Sprite2,0,0, 40, 32,300, 250, $SpriteTexture, 0xFFFFFFFF, 0, 100, 100)

Sorry about that..

Btw, thanks everyone for the nice comments :).

Share this post


Link to post
Share on other sites
CoderDunn

Ahh.. yeah. I saw that a little while ago, but am not sure why it is doing that. But I suppose you can work around it.. *for now*.

Just change your line of code to something like that..

_A2DDrawSpriteEx($Sprite2,0,0, 40, 32,300, 250, $SpriteTexture, 0xFFFFFFFF, 0, 100, 100)

Sorry about that..

Btw, thanks everyone for the nice comments :).

ok. It has to be something with the rotation or scaling since those are the only things you changed in this function right? Also, I prefer the old way of scaling by inputing the destination size. It's easier to make it the size you want.

Hallman

Share this post


Link to post
Share on other sites
NELyon

No matter what i always get an "Unknown Function" error when i try to run it.

Share this post


Link to post
Share on other sites
cppman

ok. It has to be something with the rotation or scaling since those are the only things you changed in this function right? Also, I prefer the old way of scaling by inputing the destination size. It's easier to make it the size you want.

Hallman

Same here.. but I don't know how to rotate it unless I use the D3DXSprite class which uses scaling instead of "sizing" :)

Senton-Bomb: I have no idea why it doesn't work for you. Have other plugins worked?

Share this post


Link to post
Share on other sites
NELyon

No plugins have never worked for me.

Edited by Senton-Bomb

Share this post


Link to post
Share on other sites
zatorg
Really nice work here... Congrats and thanks for sharing! :)

Share this post


Link to post
Share on other sites
CoderDunn

what I think you should do is put the old draw sprite function in this plugin and name it DrawTile() and DrawTileEX() or the like. If you are using the sprite class, that shouldn't be used to draw a tiled background. This would add more compatibility.

Hallman

Edited by Hallman

Share this post


Link to post
Share on other sites
CoderDunn

Sure thing! :D

I'm working on it now.

ok thanks :)

Share this post


Link to post
Share on other sites
smashly

Hi , luvin the new plugin, so sweet.

I have a question or an ask , How do I use the _A2DReset function without crashing the plugin?

I'm trying to go from fullscreen to windowed mode , but using the _A2DReset function leaves me with a crash.

>Exit code: -1073741819

I know it's it's got to be because I'm calling it the wrong way, but I had no example to go by to use the functon.

Basically I called the function from a hotkey combination. Alt + Enter

Could someone please point me at an example of how to use the _A2DReset function to switch between fullscreen and windowed mode.

I can _A2DReleaseDevice and _A2DCreateDevice in the mode I want, but surely the _A2DReset would be quicker to use?

As a work around I'm currently using maximize and restore on $hWnd gui set as a popup at topmost and it seems to work fine even while flasing sprites as fast as my pc can draw em.

tyia for any input that may be given :)

Cheers

Edited by smashly

Share this post


Link to post
Share on other sites
Zedna

Some problems:

CreateDevice.au3 says errors in A2D.au3:

Func _A2DCreateRect($left, $right, $top, $bottom)
    Local $avRect[4] = [$left, $right, $top $bottom]
    return $avRect
EndFunc

--> undefined function _A2DIntersectionEx

--> probably missing #compiler_plugin_funcs = _A2DIntersectionEx

Edited by Zedna

Share this post


Link to post
Share on other sites
cppman

Hi everybody.. I know this is a VERY late reply.. but I updated A2D to support surfaces now. See the first post to read more about it..

I've been having problems with my kidneys, and apparently my doctor thinks I have kidney stones. - I have to go see a urologist sometime this month... :). So I haven't been to into programming lately.

Anyways,

Enjoy.

----------

@Zedna - Thanks alot for pointing those at, they are now fixed. _A2DIntersectionEx was meant to be _A2DRectangleIntersectionEx.

@Smashly - I'm not sure why it is crashing :), but i posted an example in the new download file. It is in the CreateDevice.au3 file, and it shows how to toggle it. Press the left mouse button to toggle between full and windowed modes.

Edited by chris95219

Share this post


Link to post
Share on other sites
BrettF

I've been having problems with my kidneys, and apparently my doctor thinks I have kidney stones. - I have to go see a urologist sometime this month...

As have I, but I've got a different problem. Hope you get better soon and your AutoIt addiction doesn't send you crazy.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.