Mode 7 Demonstration program

Started by ruckage, January 25, 2012, 03:00:28 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

ruckage

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.



//******* 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




FreeYourMind

Beautiful! Another demo with the use of map_block_copy to shake scenary (like you do in you pac man game) is welcome!  ;D

handsource-dyko

Very nice and detailed tutorial, especially because you generate graphics from code.

MisterN

:D raycasting!!! I shall test this on dc hardware when I get home tomorrow
werg

l1nk3rn3l


MisterN

i can see it in linux, but on windows i just get a black screen
werg

handsource-dyko

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?

ruckage

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.

ruckage

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?

handsource-dyko

I tried both. I use XP sp3. I use an bgdi version that's at least a few months old (from august??).

ruckage

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.

MisterN

werg

SplinterGU

nice, nice, nice... very nice... karma!

DoctorN & handsource-dyko, you need use last bennugd version... the olds versions don't support 16bits video mode.
Download Lastest BennuGD Release: http://www.bennugd.org/node/2

MisterN

I just installed bennupack like three weeks ago
werg

SplinterGU

I don't know what bennugd's version have bennupack.
Download Lastest BennuGD Release: http://www.bennugd.org/node/2