glutwin_ATBdark.h 4.33 KB
Newer Older
Pierre Kraemer's avatar
Pierre Kraemer committed
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
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps  *
* version 0.1                                                                  *
* Copyright (C) 2009, IGG Team, LSIIT, University of Strasbourg                *
*                                                                              *
* This library is free software; you can redistribute it and/or modify it      *
* under the terms of the GNU Lesser General Public License as published by the *
* Free Software Foundation; either version 2.1 of the License, or (at your     *
* option) any later version.                                                   *
*                                                                              *
* This library is distributed in the hope that it will be useful, but WITHOUT  *
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or        *
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License  *
* for more details.                                                            *
*                                                                              *
* You should have received a copy of the GNU Lesser General Public License     *
* along with this library; if not, write to the Free Software Foundation,      *
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA.           *
*                                                                              *
* Web site: https://iggservis.u-strasbg.fr/CGoGN/                              *
* Contact information: cgogn@unistra.fr                                        *
*                                                                              *
*******************************************************************************/

#ifndef __MYGLUTWIN_
#define __MYGLUTWIN_

#include <vector>
#include "Utils/os_spec.h"
#include "Utils/GLSLShader.h"

#define __X_GL_H
#define GLAPIENTRY
#include <GL/glut.h>

#include "Utils/trackball.h"

#include "AntTweakBar.h"
#include "Geometry/vector_gen.h"


namespace CGoGN {

namespace Utils {

/**
 * Glut window with Antweakbar support and enlightning disabled
 */
class GlutWin_ATBdark
{

protected:
	static GlutWin_ATBdark* instance ;

	// internal values used for the manipulation of object
	static int rotating ;
	static int scaling ;
	static int translating ;
	static int beginPos[2] ;
	static float curquat[4] ;
	static float lastquat[4] ;
	static bool newModel ;
	static float scalefactor ;
	static float focal ;
	static float trans[3] ;

	// width and height of windows
	static int W ;
	static int H ;

	// are shaders initialized ?
	bool shaderOk ;
	// table of shaders
	Utils::GLSLShader shaders[8] ;

	// internal callbacks
	static void redraw() ;
78
	static void idleFunc() ;
Pierre Kraemer's avatar
Pierre Kraemer committed
79
80
81
82
83
84
85
	static void recalcModelView() ;
	static void motion(int x, int y) ;
	static void mouse(int button, int state, int x, int y) ;
	static void passive_mouse(int x, int y) ;
	static void keyboard(unsigned char keycode, int x, int y) ;

protected:
86
	virtual void myIdleFunc()  {}
Pierre Kraemer's avatar
Pierre Kraemer committed
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
130
131
132
133
134
135
136
	virtual void myKeyboard(unsigned char, int, int) {}
	virtual void myMouse(int, int, int, int) {}
	virtual void myMotion(int, int) {}
	virtual void myRedraw() {}

public:
	GlutWin_ATBdark(int* argc, char **argv, int winX, int winY) ;
	~GlutWin_ATBdark() ;

	int mainLoop() ;
	static void reshape(int w, int h) ;

	static void setFocal(float df) { focal = df ; }
	static float getFocal() { return focal ; }
	static float getScale() { return scalefactor / focal ; }

	int getWinWidth() { return W ; }
	int getWinHeight() { return H ; }

	float* getSceneQuaternion() { return curquat ; }

	/**
	 * get an ray from A to B  deduce from screen coordinates x,y
	 * @param x x in screen coordinates (from glut)
	 * @param y y in screen coordinates (from glut)
	 * @param rayA begin point of ray (close to the screen)
	 * @param rayB end point of ray (far from the screen)
	 * @return the depth value from depth buffer
	 */
	GLfloat getOrthoScreenRay(int x, int y, Geom::Vec3f& rayA, Geom::Vec3f& rayB) ;

	/**
	 * capture the OpenGL viewport and save it into a png image
	 * in fact format of image is deduced from filename (thanks to DevIL)
	 */
//	void capturePNG(const char* filename) ;

	/**
	* callback called just before exiting (ESC pressed)
	*/
	virtual void exitCallback() {}
};


}

}


#endif