57 #include <OpenGL/gl.h> 58 #include <OpenGL/glu.h> 59 #include <OpenGL/glext.h> 84 static PFNGLGENBUFFERSARBPROC glGenBuffers = 0;
85 static PFNGLBINDBUFFERARBPROC glBindBuffer = 0;
86 static PFNGLBUFFERDATAARBPROC glBufferData = 0;
88 static PFNGLUNMAPBUFFERARBPROC glUnmapBuffer = 0;
145 glMatrixMode(GL_PROJECTION);
153 glMatrixMode(GL_MODELVIEW);
155 glRotatef(180, 1, 0, 0);
176 const float w_factor =
width / 640.0f;
177 const float h_factor =
height / 480.0f;
178 Math3d::SetMat(K, 580 * w_factor, 0, 320 * w_factor, 0, 580 * h_factor, 240 * h_factor, 0, 0, 1);
181 glMatrixMode(GL_PROJECTION);
189 glMatrixMode(GL_MODELVIEW);
191 glRotatef(180, 1, 0, 0);
196 if (bActivateShading)
198 glBlendFunc(GL_SRC_ALPHA, GL_ONE);
199 glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
201 glDepthFunc(GL_LESS);
202 glEnable(GL_DEPTH_TEST);
203 glShadeModel(GL_SMOOTH);
204 glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
205 glEnable(GL_LIGHTING);
207 glEnable(GL_NORMALIZE);
208 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
213 glDisable(GL_LIGHTING);
214 glDisable(GL_DEPTH_TEST);
215 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
225 glViewport(0, 0, nWidth, nHeight);
273 printf(
"error: destination image does not match current mode\n");
286 glReadPixels(0, 0,
width,
height, GL_RGB, GL_UNSIGNED_BYTE, 0);
288 glReadPixels(0, 0,
width,
height, GL_LUMINANCE, GL_UNSIGNED_BYTE, 0);
291 memcpy(pDestinationImage->
pixels, pData, nBytes);
300 glReadPixels(0, 0,
width,
height, GL_RGB, GL_UNSIGNED_BYTE, pDestinationImage->
pixels);
302 glReadPixels(0, 0,
width,
height, GL_LUMINANCE, GL_UNSIGNED_BYTE, pDestinationImage->
pixels);
312 printf(
"error: destination matrix does not match current mode\n");
316 glReadPixels(0, 0,
width,
height, GL_DEPTH_COMPONENT, GL_FLOAT, pDestinationMatrix->
data);
323 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
328 glMatrixMode(GL_MODELVIEW);
344 glDisable(GL_LIGHTING);
350 glEnable(GL_LIGHTING);
358 glDisable(GL_LIGHTING);
362 const int c = (int) points.size();
363 for (
int i = 0; i <
c; i++)
365 const Vec3d &
v = points.at(i);
366 glVertex3f(v.
x, v.
y, v.
z);
377 glEnable(GL_LIGHTING);
384 glTranslated(point.
x, point.
y, point.
z);
385 if (pColor) glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, pColor);
406 glTranslated(point1.
x, point1.
y, point1.
z);
407 glRotatef(acosf(u.
z) * 180.0f /
FLOAT_PI, -u.
y, u.
x, 0.0f);
408 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, color);
409 gluCylinder(
m_pQuadric, radius1, radius2, length, 20, 20);
426 resultMatrix[10] = transformation.
rotation.
r9;
427 resultMatrix[11] = 0;
431 resultMatrix[15] = 1;
436 const int nTriangles = pMatrix->
rows / 3;
445 for (
int i = 0,
offset = 0; i < nTriangles; i++,
offset += 18)
447 glBegin(GL_TRIANGLES);
448 glNormal3f(data[offset], data[offset + 1], data[offset + 2]);
449 glVertex3f(data[offset + 3], data[offset + 4], data[offset + 5]);
450 glNormal3f(data[offset + 6], data[offset + 7], data[offset + 8]);
451 glVertex3f(data[offset + 9], data[offset + 10], data[offset + 11]);
452 glNormal3f(data[offset + 12], data[offset + 13], data[offset + 14]);
453 glVertex3f(data[offset + 15], data[offset + 16], data[offset + 17]);
472 m[8] = -((2.0f * K.
r3 /
width) - 1.0f);
473 m[9] = ((2.0f * K.
r6 /
height) - 1.0f);
474 m[10] = -(gfar + gnear) / (gfar - gnear);
478 m[14] = -2.0f * gfar * gnear / (gfar - gnear);
495 m[10] = -(gfar + gnear) / (gfar - gnear);
499 m[14] = -2.0f * gfar * gnear / (gfar - gnear);
509 glGenBuffers = (PFNGLGENBUFFERSARBPROC) wglGetProcAddress(
"glGenBuffersARB");
510 glBindBuffer = (PFNGLBINDBUFFERARBPROC) wglGetProcAddress(
"glBindBufferARB");
511 glBufferData = (PFNGLBUFFERDATAARBPROC) wglGetProcAddress(
"glBufferDataARB");
513 glUnmapBuffer = (PFNGLUNMAPBUFFERARBPROC) wglGetProcAddress(
"glUnmapBufferARB");
514 bExtensionInitialized = glGenBuffers && glBindBuffer && glBufferData && glMapBuffer && glUnmapBuffer;
bool GetImage(CByteImage *pDestinationImage)
void ActivateShading(bool bActivateShading)
GLvoid *APIENTRYP PFNGLMAPBUFFERARBPROC(GLenum target, GLenum access)
bool GetDepthMatrix(CFloatMatrix *pDestinationMatrix)
static void ConvertToOpenGLMatrix(const Transformation3d &transformation, float resultMatrix[16])
static const float green[3]
int width
The width of the image in pixels.
bool InitByCalibration(const CCalibration *pCalibration, bool bActivateShading=true)
Data structure for the representation of a 3D vector.
Data structure for the representation of 8-bit grayscale images and 24-bit RGB (or HSV) color images ...
float Length(const Vec3d &vec)
void DrawObject(const CFloatMatrix *pMatrix, const Transformation3d &transformation)
unsigned char * pixels
The pointer to the the pixels.
GLsizei const GLfloat * points
std::vector< Vec3d > Vec3dList
void GetCalibrationMatrix(Mat3d &K) const
Sets up the calibration matrix K.
static const float yellow[3]
const CCameraParameters & GetCameraParameters() const
Gives access to the camera parameters.
void SetVec(Vec3d &vec, float x, float y, float z)
void MulVecScalar(const Vec3d &vec, float scalar, Vec3d &result)
Data structure for the representation of a matrix of values of the data type float.
void DrawPoint(float x, float y, float z, const float *pColor=0)
GLsizei GLsizei GLenum GLenum const GLvoid * data
void AddToVec(Vec3d &vec, const Vec3d &vectorToAdd)
int height
The height of the image in pixels.
void DrawPoints(Vec3dList &points, const float *pColor=0)
static const float blue[3]
int bytesPerPixel
The number of bytes used for encoding one pixel.
static const float red[3]
static void CalculateOpenGLProjectionMatrix(const Mat3d &K, int width, int height, float gnear, float gfar, float *m)
GLenum GLsizei GLsizei height
bool Init(int width=640, int height=480, bool bActivateShading=true)
void SetProjectionMatrix(const CCalibration *pCalibration)
#define GL_PIXEL_PACK_BUFFER_ARB
ImageType type
The type of the image.
void NormalizeVec(Vec3d &vec)
Transformation3d m_ViewMatrix
GLuint GLsizei GLsizei * length
void SubtractVecVec(const Vec3d &vector1, const Vec3d &vector2, Vec3d &result)
static bool bExtensionInitialized
static void CalculateOpenGLProjectionMatrixDefaultPrincipalPoint(const Mat3d &K, int width, int height, float gnear, float gfar, float *m)
void SetMat(Mat3d &matrix, float r1, float r2, float r3, float r4, float r5, float r6, float r7, float r8, float r9)
Data structure for the representation of a 3x3 matrix.
Camera model parameters and functions for a single camera.
void DrawCylinder(const Vec3d &point1, const Vec3d &point2, float radius1, float radius2, const float color[3])
typedef GLuint(APIENTRYP PFNGLCREATEPROGRAMPROC)(void)
void DrawSphere(const Vec3d &point, float radius, const float *pColor=0)