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.
Need Help. Graphics in C
Started by Julia008, Oct 30 2008 05:12 AM
10 replies to this topic
#1
Posted 30 October 2008 - 05:12 AM
|
|
|
#2
Posted 30 October 2008 - 08:15 AM
The first question anyone will ask: Which operating system? Graphic programming is inherently system depending.
#3
Posted 30 October 2008 - 10:23 AM
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
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
Posted 30 October 2008 - 11:08 AM
I'm guessing that means Windows.
If you post what you have here, you are more likely to get assistance.
If you post what you have here, you are more likely to get assistance.
#5
Posted 30 October 2008 - 11:36 AM
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
Posted 30 October 2008 - 06:39 PM
It also highly depends on what graphics library your teacher is using. What #includes do they have?
#7
Posted 30 October 2008 - 11:15 PM
Thanks for replies so far.
You're right WingedPanther, it is for windows.
Here is the code for first program that teacher wrote:
(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>
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
Posted 31 October 2008 - 12:42 AM
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
Posted 31 October 2008 - 12:48 AM
I found this somewhere:
Borland C - graphics.h
/* 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
Posted 31 October 2008 - 08:52 AM
graphics.h isn't standard, so make sure you have it...
#11
Posted 31 October 2008 - 09:15 AM
It used to come with older Borland compilers, so Julia008 probably has it. What version of Turbo C++ are you using, Julia008?


Sign In
Create Account

Back to top









