Jump to content

Need Help. Graphics in C

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
10 replies to this topic

#1
Julia008

Julia008

    Newbie

  • Members
  • Pip
  • 3 posts
Good day everyone,

We're having a subject by the name "Computer Graphics" in university and our teacher wrote 3 programs regarding drawing a line using "DDA algorithm", using "Bresenham's line algorithm" as well as a program for drawing a circle using "Mid-Point Circle Generating Algorithm".

He gave those codes to us. But we need to add graphics mode (initialize the program to graphics mode...) in order to get them working.

I am pretty weak in programming and have no idea how it is done.

Please, if you're expert in graphics for C programming, leave me a message in private message so that I can contact you either in private message or yahoo/MSN. I have many questions that I want to ask.

Best regards,
Julia.

#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
The first question anyone will ask: Which operating system? Graphic programming is inherently system depending.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#3
Julia008

Julia008

    Newbie

  • Members
  • Pip
  • 3 posts
Sorry I may get your question wrong (I am a rookie). I think the answer will be console application. Graphics using Turbo C++.

I am able to understand the program logic that teacher given to us. And I am aware of how to initialize the graphics in C. What I don't know is where to initialize the graphics and how to solve the errors generated uring compiling. I tried the whole day but still have one error.

Shall I send you the codes WingedPanther?

Regards,
Julia

#4
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
I'm guessing that means Windows.

If you post what you have here, you are more likely to get assistance.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#5
Steve.L

Steve.L

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 444 posts

Quote

The first question anyone will ask: Which operating system? Graphic programming is inherently system depending.

Quote

Sorry I may get your question wrong (I am a rookie). I think the answer will be console application. Graphics using Turbo C++.

Epic FAIL.

#6
dargueta

dargueta

    Writes binary right handed and hex left handed

  • Moderators
  • 4,709 posts
It also highly depends on what graphics library your teacher is using. What #includes do they have?

#7
Julia008

Julia008

    Newbie

  • Members
  • Pip
  • 3 posts
Thanks for replies so far.

You're right WingedPanther, it is for windows.
Here is the code for first program that teacher wrote:
void lineDDA(int x1,int y1,int x2,int y2)
{ int dx = x2 – x1;
  int dy = y2 – y1;
  int steps, k;
  float xIncrmnt, yIncrmnt,
    x = x1, y = y1;
   if (abs (dx) > abs (dy))
       steps = abs (dx);
  else 
       steps = abs (dy);
  xIncrmnt = dx / (float) steps;
  yIncrmnt = dy / (float) steps;
  putPixel (ROUND(x), ROUND(y));
  for (k=0; k<steps; k++) {
    x += xIncrmnt;
    y += yIncrmnt;
    putPixel (ROUND(x), ROUND(y));
  }
}

(As you can see, it is just the logic for generating a line, there is no graphics added to this code. I don't know where to add the code to make it work.)

for #incluedes, I guess it will be:
#include <math.h>
#include <graphics.h>
#include <conio.h>
#include <stdio.h>

Edited by WingedPanther, 31 October 2008 - 04:55 AM.
add code tages (the # button)


#8
dargueta

dargueta

    Writes binary right handed and hex left handed

  • Moderators
  • 4,709 posts
Whooo, boy. That's an old library. The code to draw the lines is there ( see the putPixel() call?) but the library is so old it doesn't--or at least shouldn't--work anymore. Unless you're running an old version of Windows.

#9
dargueta

dargueta

    Writes binary right handed and hex left handed

  • Moderators
  • 4,709 posts
I found this somewhere:

 /* request auto detection */
   int gdriver = DETECT, gmode, errorcode;
   int midx, midy, i;
   /* initialize graphics and local
      variables */A
   initgraph(&gdriver, &gmode, "");
   /* read result of initialization */
   errorcode = graphresult();
   if (errorcode != grOk)  /* an error
       occurred */

    //do your thing here

    //clean up
    closegraph();

Borland C - graphics.h

#10
Steve.L

Steve.L

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 444 posts
graphics.h isn't standard, so make sure you have it...

#11
dargueta

dargueta

    Writes binary right handed and hex left handed

  • Moderators
  • 4,709 posts
It used to come with older Borland compilers, so Julia008 probably has it. What version of Turbo C++ are you using, Julia008?