QWT API (中文) 7.0.1
Qt绘图库 - 中文API文档
载入中...
搜索中...
未找到
qwt3d_openglhelper.h
1#ifndef __openglhelper__
2#define __openglhelper__
3
4#include "qglobal.h"
5
6#ifdef __APPLE__
7#include <OpenGL/glu.h>
8#else
9#ifdef Q_OS_WIN
10#include "windows.h"
11#endif
12#include <GL/glu.h>
13#endif
14
15namespace Qwt3D {
16
17#ifndef QWT3D_NOT_FOR_DOXYGEN
18
32{
33public:
34 GLStateBewarer(GLenum what, bool on, bool persist = false)
35 {
36 state_ = what;
37 stateval_ = glIsEnabled(what);
38 if (on)
39 turnOn(persist);
40 else
41 turnOff(persist);
42 }
43
45 {
46 if (stateval_)
47 glEnable(state_);
48 else
49 glDisable(state_);
50 }
51
52 void turnOn(bool persist = false)
53 {
54 glEnable(state_);
55 if (persist)
56 stateval_ = true;
57 }
58
59 void turnOff(bool persist = false)
60 {
61 glDisable(state_);
62 if (persist)
63 stateval_ = false;
64 }
65
66private:
67 GLenum state_;
68 bool stateval_;
69};
70
71// Returns OpenGL error string if an error occurred
72inline const GLubyte *gl_error()
73{
74 GLenum errcode;
75 const GLubyte *err = 0;
76
77 if ((errcode = glGetError()) != GL_NO_ERROR) {
78 err = gluErrorString(errcode);
79 }
80 return err;
81}
82
83// Safely deletes OpenGL display lists
84inline void SaveGlDeleteLists(GLuint &lstidx, GLsizei range)
85{
86 if (glIsList(lstidx))
87 glDeleteLists(lstidx, range);
88 lstidx = 0;
89}
90
102inline void getMatrices(GLdouble *modelMatrix, GLdouble *projMatrix, GLint *viewport)
103{
104 glGetIntegerv(GL_VIEWPORT, viewport);
105 glGetDoublev(GL_MODELVIEW_MATRIX, modelMatrix);
106 glGetDoublev(GL_PROJECTION_MATRIX, projMatrix);
107}
108
120inline bool ViewPort2World(double &objx, double &objy, double &objz, double winx, double winy,
121 double winz)
122{
123 GLdouble modelMatrix[16];
124 GLdouble projMatrix[16];
125 GLint viewport[4];
126
127 getMatrices(modelMatrix, projMatrix, viewport);
128 int res =
129 gluUnProject(winx, winy, winz, modelMatrix, projMatrix, viewport, &objx, &objy, &objz);
130
131 return (res == GL_FALSE) ? false : true;
132}
133
145inline bool World2ViewPort(double &winx, double &winy, double &winz, double objx, double objy,
146 double objz)
147{
148 GLdouble modelMatrix[16];
149 GLdouble projMatrix[16];
150 GLint viewport[4];
151
152 getMatrices(modelMatrix, projMatrix, viewport);
153 int res = gluProject(objx, objy, objz, modelMatrix, projMatrix, viewport, &winx, &winy, &winz);
154
155 return (res == GL_FALSE) ? false : true;
156}
157
158#endif // QWT3D_NOT_FOR_DOXYGEN
159
160} // ns
161
162#endif
管理 OpenGL 状态启用/禁用的辅助类
Definition qwt3d_openglhelper.h:32