473,473 Members | 1,825 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

displaying output from this program

My program is supposed to draw lines given from certain vertices that
are given to me. the colors from the lines are also defined. It should
display on a black screen. I am not sure how to do this at all. The
algorithm that I have created is bresenham's algorithm and the Color
class allows one to create different colors. Could someone show me how
to output or display my program. It would greatly be appreciated.

// -----------------------------------------------------
// Line.cpp
// -----------------------------------------------------

#include "line.h"

Line::Line(int xres, int yres): xres(xres), yres(yres)
{
image =new Color*[yres];
for (int i=0;i<yres;i++)
image[i] = new Color[xres];
gridCell.clear();
}
Line::~Line()
{
if(image)
{
for (int i=0;i<yres;i++)
delete[] image[i];

delete[] image;
}
}

void Line::save(char* filename)
{

}

void Line::draw(int x0, int y0, int x1, int y1, Color c)
{

int d, x, y, ax, ay, sx, sy, dx, dy;

dx = x1 - x0;
ax = abs(dx) << 1;
sx = sgn(dx);

dy = y1 - y0;
ay = abs(dy) << 1;
sy = sgn(dy);

x = x0;
y = y0;

if (ax > ay) {

d = ay - (ax >> 1);
while (x != x1) {
plot(x, y, c);
if (d >= 0) {
y += sy;
d -= ax;
}
x += sx;
d += ay;
}

} else {

d = ax - (ay >> 1);
while (y != y1) {
plot(x, y, c);
if (d >= 0) {
x += sx;
d -= ay;
}
y += sy;
d += ax;
}

}

plot(x1, y1, c);

}

void Line::plot(int x, int y, Color c)
{

GridCell gc;

gc.x = x;
gc.y = y;
gc.c = c;

gridCell.push_back(gc);

}

int main()
{
Color red=Color(1,0,0);
Color green=Color(0,1,0);
Color purple=Color(1,0,1);
Color blue=Color(0,0,1);
Color white=Color(0,0,0);
Color yellow=Color(1,1,0);
Color cyan=Color(0,1,1);
Color orange=Color(1,1/2,0);
return 0;
}

// -----------------------------------------------------
// Line.h
// -----------------------------------------------------

#ifndef __LINE_H__
#define __LINE_H__

#include <iostream>
#include <vector>
using namespace std;

/* A Color is a RGB float.
**
** R, G, and B are all in the range [0..1]
**
** This class allows you to add, subtract, and multiply colors,
** It also allows you to get the separate components (e.g.,
myColor.red() ),
** use constructions like "myColor += yourColor;"
*/
class Color
{
float r,g,b;
public:
inline Color(): r(0), g(0), b(0) {}
inline Color(float r, float g, float b) : r(r), g(g), b(b){}
inline ~Color() {}
inline Color operator*(const Color& c) const
{
return Color(r*c.r, g*c.g, b*c.b);
}
inline Color operator+(const Color& c) const
{
return Color(r+c.r, g+c.g, b+c.b);
}
inline Color operator-(const Color& c) const
{
return Color(r-c.r, g-c.g, b-c.b);
}
inline Color operator*(float s) const
{
return Color(r*s, g*s, b*s);
}
inline Color& operator+=(const Color& c)
{
r+=c.r;
g+=c.g;
b+=c.b;
return *this;
}
inline float red() const
{
return r;
}
inline float green() const
{
return g;
}
inline float blue() const
{
return b;
}
inline float luminance() const
{
return (float)(0.3*g + 0.6*r + 0.1*b);
}

inline float max_component() const
{
float temp = (g > r? g : r);
return (b > temp? b : temp);
}
};

typedef struct {

int x, y;
Color c;

} GridCell;

class Line
{

float* buf;
Color** image;
int xres, yres;

public:

Line(int xres, int yres);
~Line();
void draw(int, int, int, int, Color);
void save(char* file);
vector<GridCell> getGridCells(void);
inline int getXRes() const
{
return xres;
}
inline int getYRes() const
{
return yres;
}
inline Color& operator()(int x, int y)
{
return image[y][x];
}

private:

int abs(int);
int sgn(int);
void plot(int, int, Color);
vector<GridCell> gridCell;
};

inline int Line::abs(int a)
{

return (((a) < 0) ? -(a) : a);

}

inline int Line::sgn(int a)
{

return (((a) < 0) ? -1 : 1);

}

inline vector<GridCell> Line::getGridCells()
{

return gridCell;

}

#endif // __LINE_H__

Sep 5 '05 #1
2 1874
George wrote:
My program is supposed to draw lines given from certain vertices that
are given to me. the colors from the lines are also defined. It should
display on a black screen. I am not sure how to do this at all.

You are not going to like this answer but C++ does not have any way of
doing any kind of graphics at all.

If you want to do graphics in C++ you have to use a library that has the
graphics code built into it. So the first thing you need to decide is
which graphics library you are going to use to display the lines you
want to display. This is not a C++ question at all, and you shouldn't be
asking about it here.

The factors that will influence which library you choose are things like
what operating system are you programming on, what kind of graphics to
you want to do, how much are you prepared to pay, etc. etc. None of
these have anything to do with C++.

john
Sep 5 '05 #2

"George" <bu*******@hotmail.com> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...
My program is supposed to draw lines given from certain vertices that
are given to me. the colors from the lines are also defined. It should
display on a black screen. I am not sure how to do this at all. The
algorithm that I have created is bresenham's algorithm and the Color
class allows one to create different colors. Could someone show me how
to output or display my program. It would greatly be appreciated.


It totally depends on your OS and what graphics you decide to go with.

You'll need to research for your OS what type of graphics libraries you have
and which one you want to use.
Sep 7 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Joe Flynt | last post by:
I'm try to display the output of ipconfig.exe to the web browser using: Apache/2.0.48 (Win32) mod_python/3.1.2b Python/2.3.2 but when I view http://server/cgi-bin/test.py i get the following...
2
by: Joe Price | last post by:
Hi chaps I've got an XML file, within that file i've embedded html code using the <!]> tag I'm displaying that xml file through a browser using an xsl style sheet. However it is displaying...
18
by: Erik Arner | last post by:
Hi, I really need some help here. After upgrading to g++ 3.4 I have run into all sorts of troubles that I'm sure depends on my lack of proper understanding of C++. I would now like to get it right...
3
by: Double Echo | last post by:
Hi all, I'm using PHP 4.4.2, and use PHP on both the command-line and the web. I am running PHP on SuSE 10 Linux , in a VMware 5.5 workstation, using Apache 2.0.55 , on my Dell laptop. ...
13
by: David W. Fenton | last post by:
I've been struggling the last two days with something I thought was very easy, which is to open a web page with a form on it and populate the form with data passed in a query string (either POST or...
2
by: lifeshortlivitup | last post by:
I had to create a program that allows the user to input a temp and then click on either the convert to fahrenheit or convert to celsius button and then display that result within the textbox that...
9
by: Cogito | last post by:
My program builds several tables using inner HTML. All the tables are displayed only when the program terminates. How can I make it display one table at a time and then wait for a click before...
1
by: saipraveen | last post by:
Hi, I have FC7 with support for all languages. I wrote a java program to print some Katakana letters. import java.io.*; class charLiteral { public static void main(String args)...
0
by: kardon33 | last post by:
Hello All, Back Ground: I need to write a program that will display a bitmap image across the top of screen while the computer is running. The bitmap is a 800x30 image. After the image is on...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.