Hello,
Here is a small program I've written to try and cover the basics of using mode 7. All assets are generated by the program so no need for external files.
I'm not a very tidy coder but I've tried to keep it readable and have commented everything relevant, hopefully it isn't too hard to follow. Attached is a zip with the prg file and a Windows executable. Use the arrow keys to move.
(http://i.imgur.com/6gi7q.png)
//******* Mode 7 Tutorial program by ruckage *******
program mode_7;
import "mod_m7"
//import "mod_screen"
import "mod_proc"
import "mod_video"
import "mod_text"
import "mod_map"
import "mod_draw"
import "mod_math"
import "mod_grproc"
import "mod_key"
import "mod_wm"
global
texture_1;
texture_2;
ball;
c; //used to store color values when generating the textures
begin
set_mode(320,240,16);
set_fps(60,0);
//// make some images to display folded on the mode_7 plane
texture_1=new_map(1024,1024,16); /// this will be the main image used
texture_2=new_map(128,128,16); /// this will be used to fill the plane outside the main image
ball=new_map(512,512,16); /// this will be used to create a ball sprite
for(x=0;x<1024;x++);
for(y=0;y<1024;y++);
c=(x^y)%256;
map_put_pixel(0,texture_1,x,y,rgb(128+(c%128),x/4,y/4)); /// This creates a pretty xor pattern
end
end
for(x=0;x<128;x++)
for(y=0;y<128;y++)
c=(x^y)*2;
map_put_pixel(0,texture_2,x,y,rgb(c,64,c%128)); /// This creates a another xor pattern
end
end
for(x=128;x>0;x-=16)
//// draw a ball sprite
drawing_map(0,ball);
drawing_color(rgb(128-x,255-x,255-x));
draw_fcircle(128,128,x);
end
//// the next section sets up a mode_7 window
//// I will setup 2 windows, 1 for use as the floor and 1 as a ceiling
/// syntax: start_mode7(m7_id,file,main_graph,external_graph,region,horizon)
start_mode7(0,0,texture_1,texture_2,0,0); /// this will be the floor
start_mode7(1,0,texture_1,texture_2,0,0); /// this will be the ceiling
m7[0].camera=player(); //// creates the player process and sets the m7[0].camera to it's id. Camera has to be set to a process ID for mode 7 to be seen.
m7[0].height=50; //// The height of the camera. Positive values above plane, negative values below plane.
m7[0].focus=240; //adjust this to fit various reolutions. 240 optimal for 320x240 display, 480 optimal for 640x480 display etc.
m7[0].distance=64; /// sets the distance the camera is placed behind the process previously set with m7.camera
//// second mode 7 plane used as ceiling - most values are set to match m7[0]
m7[1].camera=m7[0].camera;
m7[1].height=-50; /// negative height means the camera is placed below the plane - this gives us our ceiling
m7[1].focus=m7[0].focus;
m7[0].distance=m7[0].distance;
///populate the mode_7 plane with some objects
for(x=0;x<1024;x+=64)
for(y=0;y<1024;y+=64)
mode7_object(x,y);
end
end
loop
if(exit_status!=0)exit();end
frame;
end
end
//******* END OF MAIN PROGRAM *******
//***********************************
// **** Player process. The mode 7 camera is set to follow this process
process player()
begin
resolution=100;
loop
if(key(_up))advance(300);end // up key move forward
if(key(_down))advance(-300);end // down key move backward
if(key(_left))angle+=1000;end // left key turn left
if(key(_right))angle-=1000;end // right key turn right
frame;
end
end
// **** Process for Mode_7 objects
process mode7_object(x,y)
private
phase;
begin
ctype=c_m7; //// setting ctype to c_m7 tells the process that it's image is to be positioned and scaled within the mode 7 window
cnumber=1; //// this sets which mode 7 plane the process is rendered in. Set to 0 it will render duplicate copies on all active mode_7 planes at once. Especially useful for splitscreen multiplayer.
graph=ball;
phase=(x+y)*300;
loop
height=50+(sin(phase)*50);
phase+=1500;
frame;
end
end
Beautiful! Another demo with the use of map_block_copy to shake scenary (like you do in you pac man game) is welcome! ;D
Very nice and detailed tutorial, especially because you generate graphics from code.
:D raycasting!!! I shall test this on dc hardware when I get home tomorrow
;D
thx for share source code
i can see it in linux, but on windows i just get a black screen
Quote from: DoctorN on January 25, 2012, 09:52:50 PM
i can see it in linux, but on windows i just get a black screen
Same problem for me. Don't know what's wrong. Program seems fine. Maybe a windows specific issue?
Thanks for the replies everyone.
@DoctorN / handsource-dyko
Not sure what could be wrong, I'm actually using and coded this in windows so it seems really strange it wouldn't work on your machines. I'm using Window 7 but I have an old XP machine so I'll check to see if it works on that.
Okay, checked on my old pentium 4 xp machine and the code seems to be working fine. However the exe I included doesn't and complains about a missing dll so i'll look into that and reupload if needed.
Did you guys just try the exe on windows or did compiling it yourself also also just produce a black screen?
I tried both. I use XP sp3. I use an bgdi version that's at least a few months old (from august??).
Strange. My XP machine is also service pack 3, the only possible difference is I used the latest version of bennu though I can't imagine that would stop it working unless mode 7 itself was broken in that particular release. Though that still wouldn't explain the exe not working.
upload your mod_m7.dll
nice, nice, nice... very nice... karma!
DoctorN & handsource-dyko, you need use last bennugd version... the olds versions don't support 16bits video mode.
I just installed bennupack like three weeks ago
I don't know what bennugd's version have bennupack.
I added mode7 documentation and this example program as tutorial on the wiki. Could someone verify if the information about http://wiki.bennugd.org/index.php?title=Mode7_start (http://wiki.bennugd.org/index.php?title=Mode7_start) is correct. Especially the two last (optional) fields that do not exist in DIV. I think they allow a mode 7 window to be drawn on a graphic but I'm not sure and have not tested this. My information about mode 7 comes mostly from my DIV manual and some bennupack examples.
The lammer/troll InteractiveStation has copied and autoself put credits on your demo program:
(http://1.bp.blogspot.com/-62wpAFI3SDc/T2kZaKVLC6I/AAAAAAAAAp4/9a0Ped0w6nc/s320/Screen1.png)
You can find your demo adapted in his blog...
http://thegameapprentice.blogspot.com.es/search/label/Tutorial (http://thegameapprentice.blogspot.com.es/search/label/Tutorial)
I see, they copied it from the wiki. ;D I thought I was lazy. I had put ruckage's tutorial on the bennu wiki (for use with bennu of course). Funny to see that the Gemix community use bennu examples. Apperantly our wiki is usefull to them as well, eventhough gemix isn't fully compatible with bennu. ???
Is adapted, well on src he respect the credits, it's only on the web he forgot to put the autor: Rukage.
[Editado - Contactar con el administrador para más información]
:o Wow! That's a nasty thing, spying on the private messages of the users. Why would an admin do something like that? Out of paranoia? :-\ Or simply because he can? Or does he think he's facebook? You know mark zuckerburg get's away with spying people legally and earning millions with it. (I think zuckerburg is a creep, he's literally interesseted in about everything of his users who knows If he doesn't have CIA backdoor).