Thread: drawing a rectangle!

  1. #1
    Registered User
    Join Date
    Apr 2008
    Posts
    6

    drawing a rectangle!

    Hi!
    I`m trying to draw a rectangle in c++ but it doesnt run!
    it compiles successfully! but when i run it ,it doesnt show anything on the screen
    plz guys! what should i do?
    this is my code:
    Code:
    void box(int startx, int starty, int endx, int endy, int color)
       {
           line(startx , starty , endx , starty , color) ;
           line(startx , starty , startx , endy , color) ;
           line(startx , endy , endx , endy , color) ;
           line(endx , starty , endx , endy , color) ;
       }
    void line(int startx, int starty, int endx, int endy, int color)
        {
           register int t , distance ;
           int xerr = 0 , yerr = 0 , deltax , deltay ;
           int incx , incy ;
           deltax = endx - startx ;
           deltay = endy - starty ;
           if(deltax > 0)
    	  incx = 1 ;
           else if(deltax == 0)
    	  incx = 0 ;
           else
    	  incx =- 1 ;
           if(deltay > 0)
    	  incy = 1 ;
           else if(deltay == 0)
    	  incy = 0 ;
           else
    	  incy =- 1 ;
           deltax = abs(deltax) ;
           deltay = abs(deltay) ;
           if(deltax > deltay)
    	    distance = deltax ;
           else
    	    distance = deltay ;
           for(t = 0 ; t < distance + 1 ; t++)  {
    	  mempoint(startx , starty , color) ;
    	  xerr += deltax ;
    	  yerr += deltay ;
    	  if(xerr > distance) {
    	     xerr -= distance ;
    	     startx+=incx ;
    	  }
    	  if(yerr > distance) {
    	      yerr -= distance ;
    	      starty+=incy ;
    	  }
           }
     }

  2. #2
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Are you capable of running that sort of DOS code on your current operating system?

  3. #3
    Registered User
    Join Date
    Apr 2008
    Posts
    6
    yes and also i use <windows.h> but still shows nothing

  4. #4
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Looking at that, I would imagine its some sort of DOS point plotting function, correct? I am more than acquainted with the Win32 API and mempoint() is not how you'd do this in windows. If I had more info as to what sort of graphics API you are using I could help you more.

  5. #5
    Registered User
    Join Date
    Apr 2008
    Posts
    6
    I use Dev-c++ .i check its include`s file and it does have the dos.h.
    it doesnt have any error but it shows nothing in the console.

  6. #6
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Ok, thats why bud. You need a DOS compiler to do what you are attempting to do (I knew mempoint() sounded familiar for some reason). Try downloading Allegro or something similar for basic graphics. Dev-C++ ships with that dos.h header for reasons not entirely known to me since it doesn't include a DOS compiler. What is your level of experience in programming?

  7. #7
    Registered User
    Join Date
    Apr 2008
    Posts
    6
    well this is my first time doing graphics.Im a freshman in computer science but I`m pretty good at programming c/c++. do u have any idea how to draw a rectangle in a windows compiler?thanks

  8. #8
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Well to be honest, you will be disappointed if you enjoy programming in the functions for lines, or elated if you happen to dislike tedious code such as that. Since I think you first need to get familiar with how to create a window in windows, you would benefit from reading a tutorial.

    http://www.winprog.org/tutorial/

    Is very good, so read this, mess with the code a bit, and feel free to ask further questions from that. This will of course bring you over to the dark side and you will be able to ask more questions in the windows board. If you are familiar with C++ at all I know some very good platform independent libraries so that you can write code that is portable.

  9. #9
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Hmmm this is on the C++ board, so I will go out on a limb and say you do know C++.

    http://irrlicht.sourceforge.net

    I may be a little off base here, but I think this is library is more the direction you are going with your line of questions here. Also, if you are quickly feeling overwhelmed, rest assure you can program 2d graphics (easily) using this library too. If this is satisfactory you can disregard the last link I posted for now, but I still think its beneficial for you to be able to actually write OS specific code at some point in your life. But that doesn't have to be today

  10. #10
    Registered User
    Join Date
    Apr 2008
    Posts
    6
    thanks a lot for your help.:X

  11. #11
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    No problem.

  12. #12
    Registered User
    Join Date
    Apr 2008
    Posts
    890
    Quote Originally Posted by 3pid View Post
    well this is my first time doing graphics.Im a freshman in computer science but I`m pretty good at programming c/c++. do u have any idea how to draw a rectangle in a windows compiler?thanks
    http://nehe.gamedev.net

    Dozens of OpenGL tutorials, starting with just popping up an empty window. Source code is downloadable for several compilers/languages. If you're using Visual Studio, download, open project, and build it. From there, you can play around with it and learn.
    Last edited by medievalelks; 04-24-2008 at 04:45 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Drawing a rectangle in a control
    By Joelito in forum Windows Programming
    Replies: 6
    Last Post: 12-15-2006, 07:51 PM
  2. Drawing a rectangle
    By maxorator in forum Windows Programming
    Replies: 2
    Last Post: 08-01-2006, 08:37 AM
  3. Drawing rectangle in a web page
    By alphaoide in forum Tech Board
    Replies: 3
    Last Post: 02-20-2005, 07:40 PM
  4. Point passed rectangle...
    By Hunter2 in forum Game Programming
    Replies: 15
    Last Post: 10-10-2003, 09:57 AM
  5. Drawing a grid on a plain rectangle
    By kamikazeecows in forum Windows Programming
    Replies: 1
    Last Post: 04-01-2002, 06:51 PM