Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 6 of 6

Thread: Need help on migrationg part of code from Windows to Linux

  1. #1
    Junior Member Newbie
    Join Date
    Sep 2012
    Posts
    9

    Need help on migrationg part of code from Windows to Linux

    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
    Code :
    #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
    Code :
    #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);
     
    [B]    	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(); 
    [B]        VunuglBindBuffer( GL_PIXEL_UNPACK_BUFFER, pboId);[/B]
    [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();
    }



    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
    Last edited by juanito; 09-24-2012 at 03:12 PM.

  2. #2
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Location
    Druidia
    Posts
    3,213
    Look at your source code. You're defining these on WIN32 only, but then referencing them on both WIN32 and Linux.

  3. #3
    Junior Member Newbie
    Join Date
    Sep 2012
    Posts
    9
    As it is, this code works on WIN64
    Last edited by juanito; 09-24-2012 at 09:48 PM.

  4. #4
    Junior Member Regular Contributor
    Join Date
    Dec 2009
    Posts
    211
    Win64 #defines the WIN32 macro, too, for backward compatibility.

  5. #5
    Junior Member Newbie
    Join Date
    Sep 2012
    Posts
    9
    Thanks. Removing the preprocessor directives

    OGLDisplayWidget.cpp
    Code :
    #include "OGLDisplayWidget.h"
     
    #include<ctime>
    #include<time.h>
     
    [B]//#ifdef WIN32[/B]
    	#include <GL/gl.h>    
    	#include "glext.h"  
    	PFNGLGENBUFFERSPROC VunuglGenBuffers;
    	PFNGLBINDBUFFERPROC VunuglBindBuffer;
    	PFNGLDELETEBUFFERSPROC VunuglDeleteBuffers;  
    	PFNGLBUFFERDATAPROC VunuglBufferData; 
    [B]//#endif[/B]
     
    void OGLDisplayWidget::initializeGL() 
    {	
     
    	[B]//#ifdef WIN32 // get the pointer to the GL functions[/B]
    [B]    		VunuglGenBuffers     = (PFNGLGENBUFFERSPROC)wglGetProcAddress("glGenBuffersARB");[/B]
        		VunuglBindBuffer      = (PFNGLBINDBUFFERPROC) wglGetProcAddress("glBindBuffer");  
        		VunuglDeleteBuffers  = (PFNGLDELETEBUFFERSPROC) wglGetProcAddress("glDeleteBuffers");
        		VunuglBufferData      = (PFNGLBUFFERDATAPROC) wglGetProcAddress("glBufferData");
    [B]	//#endif[/B]
     
    	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("glGenBuffe rsARB"); that says error: 'wglGetProcAddress' was not declared in this scope

    I tried replacing VunuglGenBuffers = (PFNGLGENBUFFERSPROC)wglGetProcAddress("glGenBuffe rsARB"); by VunuglGenBuffers = (PFNGLGENBUFFERSPROC)glxGetProcAddressARB("glGenBu ffersARB");.
    Same error.
    Last edited by juanito; 09-25-2012 at 07:06 AM.

  6. #6
    Junior Member Newbie GLpeon's Avatar
    Join Date
    Jan 2008
    Posts
    11
    Is there a reason why you are doing it manually, and not using GLEW (or something like that) ? http://glew.sourceforge.net/

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •