framework2

Форк
0
315 строк · 9.3 Кб
1
#include "ofAppNoWindow.h"
2
#include "ofGraphics.h"
3
#include "ofPath.h"
4
#include "of3dGraphics.h"
5
#include <memory>
6

7

8
#if defined TARGET_OSX || defined TARGET_LINUX
9
#include <stdlib.h>
10
#include <string.h>
11
#include <sys/select.h>
12
#include <termios.h>
13
#include <signal.h>
14

15
struct termios orig_termios;
16
struct sigaction act_open;
17

18
void reset_terminal_mode()
19
{
20
    tcsetattr(0, TCSANOW, &orig_termios);
21
}
22

23

24
void set_conio_terminal_mode()
25
{
26
    struct termios new_termios;
27

28
    /* take two copies - one for now, one for later */
29
    tcgetattr(0, &orig_termios);
30
    memcpy(&new_termios, &orig_termios, sizeof(new_termios));
31

32
    /* register cleanup handler, and set the new terminal mode */
33
    atexit(reset_terminal_mode);
34
	// setup new_termios for raw keyboard input
35
    cfmakeraw(&new_termios);
36
	// handle "\n" properly
37
	new_termios.c_oflag |= OPOST;
38
	//new_termios.c_oflag |= ONLCR;
39
	// set the new_termios
40
    tcsetattr(0, TCSANOW, &new_termios);
41
}
42

43
int kbhit()
44
{
45
	return 0;
46
//    struct timeval tv = { 0L, 0L };
47
//    fd_set fds;
48
//    FD_SET(0, &fds);
49
//    return select(1, &fds, nullptr, nullptr, &tv);
50
}
51

52
int getch()
53
{
54
    int r;
55
    unsigned char c;
56
    if ((r = read(0, &c, sizeof(c))) < 0) {
57
        return r;
58
    } else {
59
        return c;
60
    }
61
}
62

63
#endif
64

65
class ofNoopRenderer: public ofBaseRenderer{
66
public:
67
	ofNoopRenderer():graphics3d(this){}
68
private:
69
	static const std::string TYPE;
70
	const std::string & getType(){return TYPE;}
71

72
	void startRender(){}
73
	void finishRender(){}
74
	void update(){}
75

76
	void draw(const ofPolyline & poly) const{}
77
	void draw(const ofPath & shape) const{}
78
	void draw(const of3dPrimitive&, ofPolyRenderMode) const{}
79
	void draw(const ofNode&) const{}
80
	void draw(const ofMesh & vertexData, ofPolyRenderMode renderType, bool useColors, bool useTextures, bool useNormals) const{}
81
	void draw(const ofImage & image, float x, float y, float z, float w, float h, float sx, float sy, float sw, float sh) const{}
82
	void draw(const ofFloatImage & image, float x, float y, float z, float w, float h, float sx, float sy, float sw, float sh) const{}
83
	void draw(const ofShortImage & image, float x, float y, float z, float w, float h, float sx, float sy, float sw, float sh) const{}
84
	void draw(const ofBaseVideoDraws & video, float x, float y, float w, float h) const{}
85

86
	//--------------------------------------------
87
	// transformations
88
	void pushView(){};
89
	void popView(){};
90

91
	// setup matrices and viewport (upto you to push and pop view before and after)
92
	// if width or height are 0, assume windows dimensions (ofGetWidth(), ofGetHeight())
93
	// if nearDist or farDist are 0 assume defaults (calculated based on width / height)
94
	void viewport(ofRectangle viewport){};
95
	void viewport(float x = 0, float y = 0, float width = 0, float height = 0, bool invertY = true){};
96
	void setupScreenPerspective(float width = 0, float height = 0, float fov = 60, float nearDist = 0, float farDist = 0){}
97
	void setupScreenOrtho(float width = 0, float height = 0, float nearDist = -1, float farDist = 1){};
98
	ofRectangle getCurrentViewport() const{return ofRectangle();};
99
	ofRectangle getNativeViewport() const{return ofRectangle();};
100
	int getViewportWidth() const{return 0;};
101
	int getViewportHeight() const{return 0;};
102

103
	void setCoordHandedness(ofHandednessType handedness){};
104
	ofHandednessType getCoordHandedness() const{return OF_LEFT_HANDED;};
105

106
	//our openGL wrappers
107
	void pushMatrix(){};
108
	void popMatrix(){};
109
	void translate(float x, float y, float z = 0){};
110
	void translate(const glm::vec3 & p){};
111
	void scale(float xAmnt, float yAmnt, float zAmnt = 1){};
112
	void rotateRad(float radians, float vecX, float vecY, float vecZ){};
113
	void rotateXRad(float radians){};
114
	void rotateYRad(float radians){};
115
	void rotateZRad(float radians){};
116
	void rotateRad(float radians){};
117

118
	// screen coordinate things / default gl values
119
	void setupGraphicDefaults(){};
120
	void setupScreen(){};
121

122
	void setOrientation(ofOrientation, bool){}
123
	bool isVFlipped() const{return true;}
124
	glm::mat4 getCurrentMatrix(ofMatrixMode) const{return glm::mat4(1.0);};
125
	glm::mat4 getCurrentOrientationMatrix() const{return glm::mat4(1.0);}
126
	void matrixMode(ofMatrixMode){}
127
	void loadIdentityMatrix(){}
128
	void loadMatrix(const glm::mat4&){}
129
	void loadMatrix(const float*){}
130
	void multMatrix(const glm::mat4&){}
131
	void multMatrix(const float*){}
132
	void loadViewMatrix(const glm::mat4&){}
133
	void multViewMatrix(const glm::mat4&){}
134
	glm::mat4 getCurrentViewMatrix() const{return glm::mat4(1.0);}
135
	glm::mat4 getCurrentNormalMatrix() const{return glm::mat4(1.0);}
136
	void enableAntiAliasing(){}
137
	void disableAntiAliasing(){}
138

139

140
	// drawing modes
141
	void setRectMode(ofRectMode mode){}
142
	ofRectMode getRectMode(){return OF_RECTMODE_CORNER;}
143
	void setFillMode(ofFillFlag fill){}
144
	ofFillFlag getFillMode(){return OF_FILLED;}
145
	void setLineWidth(float lineWidth){}
146
	void setBlendMode(ofBlendMode blendMode){}
147
	void setLineSmoothing(bool smooth){}
148
	void setCircleResolution(int res){};
149
	void enablePointSprites(){};
150
	void disablePointSprites(){};
151
	void setDepthTest(bool){};
152

153
	// color options
154
	void setColor(int r, int g, int b){}; // 0-255
155
	void setColor(int r, int g, int b, int a){}; // 0-255
156
	void setColor(const ofColor & color){};
157
	void setColor(const ofColor & color, int _a){};
158
	void setColor(int gray){}; // new set a color as grayscale with one argument
159
	void setHexColor( int hexColor ){}; // hex, like web 0xFF0033;
160

161
	// bg color
162
	ofColor getBackgroundColor(){return ofColor(200);}
163
	void setBackgroundColor(const ofColor & color){}
164
	bool getBackgroundAuto(){
165
		return true;
166
	}
167
	void background(const ofColor & c){};
168
	void background(float brightness){};
169
	void background(int hexColor, float _a=255.0f){};
170
	void background(int r, int g, int b, int a=255){};
171

172
	void setBackgroundAuto(bool bManual){};		// default is true
173

174
	void clear(){};
175
	void clear(float r, float g, float b, float a=0){};
176
	void clear(float brightness, float a=0){};
177
	void clearAlpha(){};
178

179
	// drawing
180
	void drawLine(float x1, float y1, float z1, float x2, float y2, float z2) const{}
181
	void drawRectangle(float x, float y, float z, float w, float h) const{}
182
	void drawTriangle(float x1, float y1, float z1, float x2, float y2, float z2, float x3, float y3, float z3) const{}
183
	void drawCircle(float x, float y, float z, float radius) const{}
184
	void drawSphere(float x, float y, float z, float radius) const{}
185
	void drawEllipse(float x, float y, float z, float width, float height) const{}
186
	void drawString(std::string text, float x, float y, float z) const{}
187
	void drawString(const ofTrueTypeFont & font, std::string text, float x, float y) const{}
188

189
	void setBitmapTextMode(ofDrawBitmapMode mode){}
190
	ofStyle getStyle() const{ return ofStyle(); }
191
	void pushStyle(){}
192
	void popStyle(){}
193
	void setStyle(const ofStyle & style){}
194
	void setCurveResolution(int res){}
195
	void setPolyMode(ofPolyWindingMode){}
196

197
	void bind(const ofCamera & camera, const ofRectangle & viewport){};
198
	void unbind(const ofCamera & camera){};
199
	ofPath & getPath(){ return path; }
200
	const of3dGraphics & get3dGraphics() const{
201
		return graphics3d;
202
	}
203

204
	of3dGraphics & get3dGraphics(){
205
		return graphics3d;
206
	}
207
	of3dGraphics graphics3d;
208
	ofPath path;
209
};
210

211

212
const std::string ofNoopRenderer::TYPE="NOOP";
213

214
//----------------------------------------------------------
215
ofAppNoWindow::ofAppNoWindow()
216
:coreEvents(new ofCoreEvents)
217
,currentRenderer(new ofNoopRenderer){
218
	ofAppPtr = nullptr;
219
	width = 0;
220
	height = 0;
221
}
222

223

224
//----------------------------------------------------------
225
void ofAppNoWindow::setup(const ofWindowSettings & settings){
226
	width = settings.getWidth();
227
	height = settings.getHeight();
228
}
229

230
//----------------------------------------------------------
231
void ofAppNoWindow::update(){
232

233
    /// listen for escape
234
    #ifdef TARGET_WIN32
235
    if (GetAsyncKeyState(VK_ESCAPE))
236
    	events().notifyKeyPressed(OF_KEY_ESC);
237
    #endif
238

239
	#if defined TARGET_OSX || defined TARGET_LINUX
240
	while ( kbhit() )
241
	{
242
		int key = getch();
243
		if ( key == 27 )
244
		{
245
			events().notifyKeyPressed(OF_KEY_ESC);
246
		}
247
		else if ( key == /* ctrl-c */ 3 )
248
		{
249
			ofLogNotice("ofAppNoWindow") << "Ctrl-C pressed" << std::endl;
250
			break;
251
		}
252
		else
253
		{
254
			events().notifyKeyPressed(key);
255
		}
256
	}
257
	#endif
258

259

260
	events().notifyUpdate();
261
}
262

263
//----------------------------------------------------------
264
void ofAppNoWindow::draw(){
265
	events().notifyDraw();
266
}
267

268
//------------------------------------------------------------
269
void ofAppNoWindow::exitApp(){
270
	ofLogVerbose("ofAppNoWindow") << "terminating headless (no window) app!";
271

272

273
#if defined TARGET_OSX || defined TARGET_LINUX
274
    // this doesn't exist on windows and gives linking errors, so commented out.
275
	reset_terminal_mode();
276
#endif
277

278
	OF_EXIT_APP(0);
279
}
280

281
//----------------------------------------------------------
282
glm::vec2 ofAppNoWindow::getWindowPosition(){
283
	return {0.f, 0.f};
284
}
285

286
//----------------------------------------------------------
287
glm::vec2 ofAppNoWindow::getWindowSize(){
288
	return {width, height};
289
}
290

291
//----------------------------------------------------------
292
glm::vec2 ofAppNoWindow::getScreenSize(){
293
	return {width, height};
294
}
295

296

297
//----------------------------------------------------------
298
int	ofAppNoWindow::getWidth(){
299
	return width;
300
}
301

302
//----------------------------------------------------------
303
int	ofAppNoWindow::getHeight(){
304
	return height;
305
}
306

307

308
//----------------------------------------------------------
309
ofCoreEvents & ofAppNoWindow::events(){
310
	return *coreEvents;
311
}
312

313
std::shared_ptr<ofBaseRenderer> & ofAppNoWindow::renderer(){
314
	return currentRenderer;
315
}
316

317

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.