Image Loading... Image Loading...
Click Here to Visit Our Sponsor

Home
News
Cartoon

Books
Reviews

SimTel
Compress
Database
Delphi
Desktop
Diskutl
Fileutl
Graphics
Inet
Mmedia
Prog
Scrsave
Util

C/C++
CodeBase!
Libraries
Tutorials
WebLinks

Pascal
Libraries
WebLinks



Home / C Tutorials
SciTech MGL 4.05
Step by step
Written by Ryan Wahle
Tuesday, May 25, 1999

In this tutorial, this will show you how to make a program that will display the words "Hi Dorks" on the screen. It was a program that I wrote for my friends about 2-3 weeks ago when I just started learning MGL. :)

Step 1
Include the header file. This header file will pretty much be needed in all your programs. I think this header file even calls stdio.h so you don't even need to call that if you want to use like printf or something like that.

    #include <mgraph.h>

Step 2
Now we need to put in the following code. This will setup our display, and our events, and ofcourse the void main().

    int
    main (void) {
        MGLDC   *dc;
        event_t evt;

Step 3
Now we need to register the video modes. This is the very basic video mode. This should work on all cards, and if it doesn't work on yours, you need a new one anyways. :) Acually, this was the only one that worked for me, and I thought I had a good video card (Permedia 2). Then I updated my bios on the video card from the video card manufacturer, and now I have TONS of video modes, and Kendall assures me when the Permedia 2 display doctor drivers get working, I will even have more. So, I am pretty set on video modes. :)

        int driver = grDETECT;
        int mode = grDETECT;

        MGL_registerDriver(MGL_VGA4NAME, VGA4_driver);
        MGL_init (&driver, &mode, ".");	

Step 4
We need to create the display now. Up on step 2, we only declared it, just like we would declare char whatever; now we need to set *dc to something. We will create it with one page, which is all we need right now. Don't worry about what it is right now, we will get on to that later in our tutorials. And after we create the display, we set the display active.

        dc = MGL_createDisplayDC(1);
        MGL_makeCurrentDC(dc);

Step 5
Now we will set our pixels to red. This means any pixel that gets plotted after this statement will be red, until we change it with another statement like this one but with a different color.

        MGL_setColorCI(MGL_RED);

Step 6
Okay, now we are read to do some real work. With the following command we can create lines. Here is the syntax for it.

        MGL_lineCoord(x1, y1, x2, y2);

Now the coord 0,0 starts in the upper left hand corner of your screen. If you have ever taken algebra, you will know about the graph system. There are essentially four parts to a 2D graph. We will be using quadrant 4 of the graph. (I may be wrong, but who cares). But there is only one problem. All points in quadrant 4 are negative. That's fine though. Just take the negative signs off and forget they were even there. :)

Step 7>
Now we are gonna do alot of the MGL_lineCoord statements, and make some letters. I made them on my home-made graph paper before I did this, so I knew what cords to put in. Here they are:

        // H
        MGL_lineCoord(20,20,20,40);
        MGL_lineCoord(20,30,30,30);
        MGL_lineCoord(30,20,30,40);

        // I
        MGL_lineCoord(40,20,40,40);

        // D
        MGL_lineCoord(25,60,25,80);
        MGL_lineCoord(25,60,35,60);
        MGL_lineCoord(35,60,40,70);
        MGL_lineCoord(40,70,35,80);
        MGL_lineCoord(35,80,25,80);

        // O
        MGL_lineCoord(50,60,60,60);
        MGL_lineCoord(60,60,60,80);
        MGL_lineCoord(60,80,50,80);
        MGL_lineCoord(50,80,50,60);

        // R
        MGL_lineCoord(70,60,70,80);
        MGL_lineCoord(70,60,80,60);
        MGL_lineCoord(80,60,80,70);
        MGL_lineCoord(80,70,70,70);
        MGL_lineCoord(70,70,80,80);

        // K
        MGL_lineCoord(90,60,90,80);
        MGL_lineCoord(100,60,90,70);
        MGL_lineCoord(90,70,100,80);

        // S
        MGL_lineCoord(120,60,110,65);
        MGL_lineCoord(110,65,120,75);
        MGL_lineCoord(120,75,110,80);

Step 8 Since we displayed the words "Hi Dorks", we want our friends to see this before it disappears so we can all get a good laugh. He we send this command to halt the program until an event of a keydown occurs. This will pretty much just wait until a key has been pressed. We will learn more on events later.

        EVT_halt (&evt, EVT_KEYDOWN);

Step 9
The remaining code just cleans up the graphics code, and puts you back to your console. Or "graphical shell" for your windows users. :) Also, this remaining } closes our program for us.

        MGL_exit();
        return 0;
}

Finishing Up
That's pretty much it. You can acually replace the MGL_lineCoord statements with your own. Just read the docs and find some functions that also print stuff to the screen. Have some fun and learn. It's the only way you can do it until I make more tutorials. :)

See ya


This Article
Installation
Configuration
Step by step
Move bitmaps
Troubleshooting

Downloads
MGL Documentation Programming Guide Reference Guide

See Also
MGL Libraries

NetLinks
SciTech Homepage
MGL Repository
MGL Newsgroup

Next:  Move bitmaps around the screen

   
Image Loading...