forked from amey04/CS580
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApplication1.cpp
116 lines (86 loc) · 2.52 KB
/
Application1.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
/**
* Test application class member functions for homework assignment #1
* USC csci 580 *
*/
// Application1.cpp: implementation of the Application1 class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "CS580HW.h"
#include "Application1.h"
#include <stdio.h>
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
/* CS580 HW : I/O file definition */
#define INFILE1 "rects"
#define OUTFILE1 "output.ppm"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
Application1::Application1()
{
}
Application1::~Application1()
{
}
/*
- CS580 HW
- This is the routine to call your functions
- Check the code and modify it if needed.
*/
int Application1::Render()
{
int i, j;
int xRes, yRes, dispClass; /* display parameters */
int status;
status = 0;
/*
* initialize the display and the renderer
*/
m_nWidth = 512; // frame buffer and display width
m_nHeight = 512; // frame buffer and display height
status |= GzNewFrameBuffer(&m_pFrameBuffer, m_nWidth, m_nHeight);
status |= GzNewDisplay(&m_pDisplay, GZ_RGBAZ_DISPLAY, m_nWidth, m_nHeight);
status |= GzGetDisplayParams(m_pDisplay, &xRes, &yRes, &dispClass);
status |= GzInitDisplay(m_pDisplay); /* init for new frame */
if (status) exit(GZ_FAILURE);
// I/O File open
FILE *infile;
if( (infile = fopen( INFILE1 , "r" )) == NULL )
{
AfxMessageBox( "The input file was not opened\n" );
return GZ_FAILURE;
}
FILE *outfile;
if( (outfile = fopen( OUTFILE1 , "wb" )) == NULL )
{
AfxMessageBox( "The output file was not opened\n" );
return GZ_FAILURE;
}
int ulx, uly, lrx, lry, r, g, b;
while( fscanf(infile, "%d %d %d %d %d %d %d",
&ulx, &uly, &lrx, &lry, &r, &g, &b) == 7) {
for (j = uly; j <= lry; j++) {
for (i = ulx; i <= lrx; i++) {
GzPutDisplay(m_pDisplay, i, j, r, g, b, 1, 0);
}
}
}
GzFlushDisplay2File(outfile, m_pDisplay); /* write out or update display to file*/
GzFlushDisplay2FrameBuffer(m_pFrameBuffer, m_pDisplay); // write out or update display to frame buffer
/*
* Clean up and exit
*/
if( fclose( infile ) )
AfxMessageBox( "The input file was not closed\n" );
if( fclose( outfile ) )
AfxMessageBox( "The output file was not closed\n" );
status |= GzFreeDisplay(m_pDisplay);
if (status)
return(GZ_FAILURE);
else
return(GZ_SUCCESS);
}