PDA

View Full Version : Need help on migrationg part of code from Windows to Linux



juanito
09-24-2012, 02:57 PM
Hi all,
I have to start working on a code that contains some fragments of OpenGL and which compiles without problems on Windows.
The problem is that I need to compile this code on Linux. The last time I used OpenGL was more than 10 years ago, so I'm not sure what changes I have to do in order to have it running on this system.
The following is the relevant part of the code


OGLDisplayWidget.h

#ifndef __OGLDisplayWidget_H
#define __OGLDisplayWidget_H

#define GL_GLEXT_PROTOTYPES

#include <QtGui/QtGui>
#include <QtGui/QMainWindow>

#if defined(WIN32) || defined(WIN64)
#include <QGLWidget>
#else //linux
#include <QtOpenGL/QGLWidget>
#include </home/Qt/4.8.1/gcc/include/QtOpenGL/QGLPixelBuffer>
#endif

class nc_demonstrator;
class ImageAcquisition;

#define BUFFER_OFFSET(bytes) ((GLubyte*) NULL + (bytes))


class OGLDisplayWidget : public QGLWidget, protected Ui_ImageDisplay
{
Q_OBJECT

public:

OGLDisplayWidget(QWidget *parent = NULL, QWidget *demo = NULL);
~OGLDisplayWidget();

//Revoir son utilite car plusieurs parametres semblent deja passe
nc_demonstrator *NcDemonstrator;
ImageAcquisition *test;


NcImage* CreateStaticImage(NcImage *MyVunuImage, int width, int height);
void FreeStaticImage(NcImage* MyVunuImage);
void ClearImage() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); }

DeviceImage ImageToDisplay;
float ZoomXScale, ZoomYScale, ZoomXRefPoint, ZoomYRefPoint;
int GotImage;

QReadWriteLock DisplayLock;

QColor colorTable[256];
unsigned int *lut;
unsigned int *ColoredImage;
int ColorEnable;
int ColorStatusChanged;

void ColorPalette();

void ImageOnDisplay(DeviceImage ImageObject) {DisplayLock.lockForWrite(); ImageToDisplay = ImageObject; DisplayLock.unlock();}

void UpdateHisto();

protected:
void initializeGL();
void paintGL();
void leaveEvent(QEvent *event){ emit LeaveWidget(); }
void mouseMoveEvent(QMouseEvent *mouseEvent);

private:
int elapsed;
QGLPixelBuffer *AltOnBoardBuffer;
unsigned short *VunuMap;
unsigned int *VunuMapColor;
QImage *ImageReceived;
GLuint textureId;
GLuint pboId;
};


#endif



OGLDisplayWidget.cpp


#include "OGLDisplayWidget.h"

#include<ctime>
#include<time.h>

#ifdef WIN32
#include <GL/gl.h>
#include "glext.h"
PFNGLGENBUFFERSPROC VunuglGenBuffers;
PFNGLBINDBUFFERPROC VunuglBindBuffer;
PFNGLDELETEBUFFERSPROC VunuglDeleteBuffers;
PFNGLBUFFERDATAPROC VunuglBufferData;
#endif

void OGLDisplayWidget::initializeGL()
{

#ifdef WIN32 // get the pointer to the GL functions
VunuglGenBuffers = (PFNGLGENBUFFERSPROC)wglGetProcAddress("glGenBuffersARB");
VunuglBindBuffer = (PFNGLBINDBUFFERPROC) wglGetProcAddress("glBindBuffer");
VunuglDeleteBuffers = (PFNGLDELETEBUFFERSPROC) wglGetProcAddress("glDeleteBuffers");
VunuglBufferData = (PFNGLBUFFERDATAPROC) wglGetProcAddress("glBufferData");
#endif

QGLFormat glFmt;
glFmt.setSwapInterval(1); // 1= vsync on
QGLFormat::setDefaultFormat(glFmt);

VunuglGenBuffers(1, &pboId);

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
}


void OGLDisplayWidget::animate()
{
DisplayLock.lockForRead();
VunuglBindBuffer( GL_PIXEL_UNPACK_BUFFER, pboId);
VunuglBufferData(GL_PIXEL_UNPACK_BUFFER, 2*NcDemonstrator->imageWidth*NcDemonstrator->imageHeight, (unsigned short*)ImageToDisplay.constData(), GL_STREAM_DRAW);
DisplayLock.unlock();

if (GotImage == 1)
updateGL();
}





When I compile the error messages I get are:
On void OGLDisplayWidget::initializeGL() (first black line)
#error: 'VunuglGenBuffers' was not declared in this scope#

On void OGLDisplayWidget::animate() (second and third black line)
#error: 'VunuglGenBuffers' was not declared in this scope#

Any suggestion on how to solve this issue will be much appreciated.
cheers
Juanito

Dark Photon
09-24-2012, 04:33 PM
Look at your source code. You're defining these on WIN32 only, but then referencing them on both WIN32 and Linux.

juanito
09-24-2012, 08:14 PM
As it is, this code works on WIN64

mbentrup
09-25-2012, 12:33 AM
Win64 #defines the WIN32 macro, too, for backward compatibility.

juanito
09-25-2012, 06:39 AM
Thanks. Removing the preprocessor directives

OGLDisplayWidget.cpp


#include "OGLDisplayWidget.h"

#include<ctime>
#include<time.h>

//#ifdef WIN32
#include <GL/gl.h>
#include "glext.h"
PFNGLGENBUFFERSPROC VunuglGenBuffers;
PFNGLBINDBUFFERPROC VunuglBindBuffer;
PFNGLDELETEBUFFERSPROC VunuglDeleteBuffers;
PFNGLBUFFERDATAPROC VunuglBufferData;
//#endif

void OGLDisplayWidget::initializeGL()
{

//#ifdef WIN32 // get the pointer to the GL functions
VunuglGenBuffers = (PFNGLGENBUFFERSPROC)wglGetProcAddress("glGenBuffersARB");
VunuglBindBuffer = (PFNGLBINDBUFFERPROC) wglGetProcAddress("glBindBuffer");
VunuglDeleteBuffers = (PFNGLDELETEBUFFERSPROC) wglGetProcAddress("glDeleteBuffers");
VunuglBufferData = (PFNGLBUFFERDATAPROC) wglGetProcAddress("glBufferData");
//#endif

QGLFormat glFmt;
glFmt.setSwapInterval(1); // 1= vsync on
QGLFormat::setDefaultFormat(glFmt);

VunuglGenBuffers(1, &pboId);[/B]

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
}


void OGLDisplayWidget::animate()
{
DisplayLock.lockForRead();
VunuglBindBuffer( GL_PIXEL_UNPACK_BUFFER, pboId);[/B]
VunuglBufferData(GL_PIXEL_UNPACK_BUFFER, 2*NcDemonstrator->imageWidth*NcDemonstrator->imageHeight, (unsigned short*)ImageToDisplay.constData(), GL_STREAM_DRAW);[/B]
DisplayLock.unlock();

if (GotImage == 1)
updateGL();
}



I got an error message on line
VunuglGenBuffers = (PFNGLGENBUFFERSPROC)wglGetProcAddress("glGenBuffersARB"); that says error: 'wglGetProcAddress' was not declared in this scope

I tried replacing VunuglGenBuffers = (PFNGLGENBUFFERSPROC)wglGetProcAddress("glGenBuffersARB"); by VunuglGenBuffers = (PFNGLGENBUFFERSPROC)glxGetProcAddressARB("glGenBuffersARB");.
Same error.

GLpeon
09-25-2012, 11:40 AM
Is there a reason why you are doing it manually, and not using GLEW (or something like that) ? http://glew.sourceforge.net/