A DirectX Hello World tutorial for Exotica/ExoticaX/Euphoria
A DirectX Hello World tutorial for Exotica/ExoticaX/Euphoria
_______________________________________________
by Mal'akh Harbonah malakh at nwlink.com
This is the first in a set of tutorials I will be writing for ExoticaX
and eventualy plain old Exotica. ExoticaX by Chris Bensler is a set of
wrappers for Exotica. Exotica by Todd Riggins is a DirectX Library for
use with the programming language Euphoria. You can get the latest copy
of ExoticaX at http://www.members.xoom.com/Third_Eye13/exoticax.zip and
Exotica at http://exotecha.amhosting.com/exotica.shtml. If you have any
comments or feedback about this tutorial I would love to hear them, you
can email me at malakh at nwlink.com
This first tutorial will walk you step by step through writing your
first DirectX program using the three resources listed above. It is assumed
that you have at least some understanding of the Euphoria programing
language
in this tutorial. In the tradition of all programing tutorials we will
start
with a Hello World program. By the time you are done you will have a
program
which is very similar to the Hello.exw demo that comes with ExoticaX. I was
going to make this tutorial do an exact copy but I did not like the way some
of this demo was layed out and felt alot of the stuff made it more
complicated
then need be for this tutorial.
Ok lets get started. First open up your Euphoria editor of choice. The
first thing we need to do is add the include files we will need. For this
example we will need the following,
_______________________
include exoticaX.ew
include ddrawx.ew
_______________________
Go ahead and add those to the beginning of your file. Now ExoticaX
has two basic sections of code the Init section and the Main Section. These
are not official sections but Chris splits his demo's up this way and I
think
it helps, not just in making the code more readable but it also helps in
understanding how Exotica works by itself if you read the corresponding
Demo's
from that. So lets add in the following line to split things up a little.
_______________________
----------------------------------------------------------------------------
-
-- Init
_______________________
Ok easy enough. Now onto the good stuff. Next we will create a sequence
to store the name of the font we are going to use and an atom to hold the
font
once we create it. Add the following to the end of your code,
_______________________
sequence font
atom font1
_______________________
Now lets add in the name of the font we want. For this tutorial we are
going to use "Times New Roman".
_______________________
font = "Times New Roman"
_______________________
Ok pretty easy stuff so far. Now it gets a little more complicated.
Exotica has a feature built in for reporting a log of events to a file.
So to set this up using ExoticaX we do,
_______________________
report_mode("E_Report",1)
_______________________
This will write the log file to a file called E_Report.txt to the
directory in which you run the program. Now the next thing we need to do is
initialize Exotica. Now first off I should mention that most of ExoticaX
functions you access you will do from inside an if statement. This is
because
if the function fails it will return a 1 or True. So we write all our calls
to
ExoticaX like so
if some_exoticax_func(blah, blah, blah) then exotica_abort(1) end if
Pretty straight forward I think. So on with our code. Lets tell Exotica to
get
its butt in gear.
_______________________
app_title = Hello Demo Tutorial for ExoticaXv1.1"
exotica_init()
_______________________
Now that we have told ExoticaX to start up Exotica we can not start the
DirectX components we need. For this tutorial all we need is DirectDraw so
we
add the following,
_______________________
if ddraw_init() then exotica_abort(1) end if
_______________________
Now that we have DirectDraw started the next thing to do is set our video
mode. We do this using the ExoticaX call set_video_mode().
set_video_mode()
takes three parameters which correspond nicely the the standard format for
writting
video modes. So for example if we want to use 640x480x8 we make the call
like
set_video_mode(640, 480, 8) so lets do this.
_______________________
if set_video_mode(640, 480, 8) then exotica_abort(1) end if
_______________________
And then do the following to set our pallette to the plain old windows
system
palette like so.
_______________________
set_system_palette()
_______________________
Now the next thing we are going to do is create are font. To do this we
use
the call createfont(). createfont() takes several parameters which I will
not go
into. If you really must know I would pick up a book on Windows API
programing or
look on www.microsoft.com.
_______________________
font1 = createfont( 24, 16, 0, 0, FW_NORMAL, 0, 0, 0, ANSI_CHARSET,
OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
FF_ROMAN, font)
_______________________
Well thats it for our Init section now lets put another comment to split
things up.
_______________________
----------------------------------------------------------------------------
-
-- Main
_______________________
Now all the demo's for Exotica use a infinite loop that exits when the Esc
key
is pressed. So lets go ahead and add the code for this now.
_______________________
while 1 do
if aActive = 2 then
_______________________
Next we want to make the screen black since we are not going to be filling
the
screen with much in the way of graphics. We do this using the call
clear_surface().
clear_surface() only takes one parameter which is the color you want to set
the screen
to. For this tutorial we are only using 8bit color so this value is just
the value
of the palette color you want. So since we want black we will be using
clear_surface(0).
Lets plop that baby in there.
_______________________
if clear_surface(0) then exotica_abort(1) end if
_______________________
Now we finaly get to the point were we can write something to the screen!
first
off we need to tell DirectDraw what font to use. To do this we will be
using the call
use_font(). use_font() only takes one parameter which is the atom that you
assigned
the createfont() return value to. We did this earlier so we have an atom
font1 which
holds our font value.
_______________________
use_font(font1)
_______________________
Now lets send our text to the screen. To do this we will use
gdi_textout_center(). gdi_textout_center() takes five parameters like so
gdi_textout_center(xPos, yPos, string, color, trans). xPos and yPos are the
x and y
location that you want the text to be centered at. string is the text
string to send.
Color is, well, the color you want the text to be. And last but not least,
trans is
wiether or not you want the area around each letter to be transparent or
not. 1 is for
transparent fonts and 0 is for non-transparent fonts. Ok so now that we
understand
that lets do it!
_______________________
if gdi_textout_center(320, 250, "Hello World!!!", 255, 1) then
exotica_abort(1) end if
_______________________
Exotica by defualt uses a double buffer system, everything you send to the
screen is actualy send to memory. Once its in memory you need to send that
memory
to the screen. This sounds pretty complicated and in most cases it would be
but
with ExoticaX it's as easy as pie! Check it out,
_______________________
if surface_flip() then exotica_abort(1) end if
_______________________
Ok so thats pretty much it all we need to do now is end our loop and
shutdown
Exotica. We do this with the following.
_______________________
end if
-- This polls for windows messages and any errors that might've occurred.
-- **NOTE** THIS SHOULD ALWAYS BE CALLED
if exotica_error() then exotica_abort(1) end if
end while
exotica_exit()
_______________________
Note that that line with the two comments above it is for catching the
exotica
errors. And like it says it should always look like that. I think this
should more
correctly stat that you should always end your main program loop with that.
Or
something along those lines. And of course you always need to end with
exotica_exit()
or at least when your done with Exotica.
And your done! If you did everything correct your code should look like
this
_______________________
include exoticaX.ew
include ddrawX.ew
----------------------------------------------------------------------------
-
-- Init
sequence font
atom font1
font = "Times New Roman"
report_mode("E_Report",1)
app_title = "HELLO Demo for ExoticaXv1.1"
exotica_init()
if ddraw_init() then exotica_abort(1) end if
if set_video_mode(640, 480, 8) then exotica_abort(1) end if
set_system_palette()
font1 = createfont( 24, 16, 0, 0, FW_NORMAL, 0, 0, 0, ANSI_CHARSET,
OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
FF_ROMAN, font)
----------------------------------------------------------------------------
-
-- Main
while 1 do
if aActive = 2 then
if clear_surface(0) then exotica_abort(1) end if
use_font(font1)
if gdi_textout_center(320,250,"Hello World!!!",255,1) then
exotica_abort(1) end if
if surface_flip() then exotica_abort(1) end if
end if
-- This polls for windows messages and any errors that might've occurred.
-- **NOTE** THIS SHOULD ALWAYS BE CALLED
if exotica_error() then exotica_abort(1) end if
end while
exotica_exit()
_______________________
Go ahead and run it and you should have a nice blank screen with a white
Hello World!!!
-- Copyright (C) 2000 Mal'akh Harbonah
|
Not Categorized, Please Help
|
|