-
Notifications
You must be signed in to change notification settings - Fork 0
/
pixmap.cpp
129 lines (107 loc) · 2.14 KB
/
pixmap.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/*****************************************************************************
Pixmap Class
NAME:pixmap.cpp
DATE:10/11/1996
AUTHOR: Z.A. Nolan
******************************************************************************/
// include the header
#include "pixmap.h"
#include <GL/gl.h>
#include <GL/glu.h>
#include "aux.h"
// Constructor
TPixmap::TPixmap()
{
_Width=-1 ;
_Height=-1 ;
_Pixmap=NULL ;
}
// Constructor
TPixmap::TPixmap(int Width,int Height)
{
_Width=Width ;
_Height=Height ;
_Pixmap=new TColour[_Height*_Width] ;
(*this).Clear() ;
}
// Destructor
TPixmap::~TPixmap()
{
// delete the pixmap
delete _Pixmap ;
}
// return the colour at pixel X,Y
TColour TPixmap::operator() (int Width,int Height) const
{
return (_Pixmap[Width+(_Width*(_Height-Height-1))]) ;
}
// set the colour at pixel X,Y
TColour &TPixmap::operator() (int Width,int Height)
{
return (_Pixmap[Width+(_Width*(_Height-Height-1))]) ;
}
// clear the screen to black
TPixmap::Clear()
{
int I,J ; // loop counters
TColour Black(0.0,0.0,0.0) ; // Black for the clear loop
// clear the screen
for (I=0;I<_Height;I++)
{
for (J=0;J<_Width;J++)
{
_Pixmap[J+I*_Width]=Black ;
}
}
}
// clear the screen to the colour given
TPixmap::Clear(TColour Colour)
{
int I,J ; // loop counters
// clear the screen
for (I=0;I<_Height;I++)
{
for (J=0;J<_Width;J++)
{
_Pixmap[J+I*_Width]=Colour ;
}
}
}
// output a ppm file
ostream &TPixmap::StreamPPMOut (ostream &Out)
{
int X,Y ; // loop counters
//write header
Out<<"P3\n"<<_Width<<' '<<_Height<<' '<<255<<'\n' ;
// save image
for ( Y = 0 ; Y < _Height ; Y++ )
{
for ( X = 0; X < _Width; X++ )
{
Out<<(*this)(X,Y).Red()*255<<' '
<<(*this)(X,Y).Green()*255<<' '
<<(*this)(X,Y).Blue()*255<<'\n' ;
}
}
// return the stream
return Out ;
}
TPixmap::SetSize(int X,int Y)
{
delete _Pixmap ;
_Height=Y ;
_Width=X ;
_Pixmap=new TColour[_Height*_Width] ;
}
TPixmap::Display()
{
glDrawPixels(_Width,_Height,GL_RGB,GL_UNSIGNED_BYTE,_Pixmap) ;
}
int TPixmap::Width()
{
return _Width ;
}
int TPixmap::Height()
{
return _Height ;
}