Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9141057
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:35:48+00:00 2026-06-17T09:35:48+00:00

I’m currently building a plug-in in C++ for the program Igor Pro. This plug-in

  • 0

I’m currently building a plug-in in C++ for the program Igor Pro. This plug-in takes three arrays of points (X, Y, Z) and returns a matrix with the pixel values of the data (float array[windowsize][windowsize]).

I’ve already developed a solution in OpenGL (glew) by using VBOs but I feel that it’s not the optimal solution.

1) Do you think I should use offscreen rendering with FBOs or PBOs? I would like to make it run as fast as possible.

2) Also, I’d like to run glutMainLoop only once. Should I change to FreeGLUT?

/*  
        RenderTriangle.c
*/
#include "VC10\triangulation.h"
#include "XOPStandardHeaders.h"         // Include ANSI headers, Mac headers, IgorXOP.h, XOP.h and XOPSupport.h
#include "glui.h"

// Prototypes
HOST_IMPORT int main(IORecHandle ioRecHandle);

// Global Variables
const int windowSize = 512;
GLuint ID;
int size,el_size;
float* waveX=NULL;
float* waveY=NULL;
float* waveZ=NULL;
waveHndl waveH;

// Custom error codes
#define OLD_IGOR 1 + FIRST_XOP_ERR
#define NON_EXISTENT_WAVE 2 + FIRST_XOP_ERR
#define REQUIRES_SP_OR_DP_WAVE 3 + FIRST_XOP_ERR

#pragma pack(2)     // All structures passed to Igor are two-byte aligned.
typedef struct FitParams {
    waveHndl waveX; 
    waveHndl waveY;
    waveHndl waveZ;
    double result;
} FitParams, *FitParamsPtr;
#pragma pack()      // Restore default structure alignment

// Prototypes of the OpenGL callbacks
void init(void);
void display(void);
void idle(void);

void init(void){

    float z_val=0;
    int point=0;

    //Loading data from the text files and applying the Delaunay algorithm
    triangulateio tri_data=triangulationWave(waveX,waveY,waveZ);
    vector<float>data_vector(tri_data.numberoftriangles*3*6); //3 points with 6 coordinates (position and color)

    size=data_vector.size();

    double zMin=tri_data.pointattributelist[N_ELEMENTS],zMax=tri_data.pointattributelist[N_ELEMENTS+1];
    for (int i_tri = 0; i_tri < tri_data.numberoftriangles; i_tri++) {

        for (int i_point = 0; i_point < 3; i_point++) {

            z_val=tri_data.pointattributelist[tri_data.trianglelist[i_tri * 3 + i_point]];
            z_val=1-((z_val-zMin)/(zMax-zMin)); //normalize and invertion

            point=6*(i_tri *3 + i_point);

            data_vector[point+0]=tri_data.pointlist[2*tri_data.trianglelist[i_tri * 3 + i_point]];
            data_vector[point+1]=tri_data.pointlist[2*tri_data.trianglelist[i_tri * 3 + i_point]+1];
            data_vector[point+2]=z_val;
            data_vector[point+3]=z_val;
            data_vector[point+4]=z_val;
            data_vector[point+5]=z_val;
        }
    }

    glewInit();

    glEnable(GL_DEPTH_TEST);
    glDepthMask(GL_TRUE);
    glDepthFunc(GL_LEQUAL);
    glDepthRange(-2.0f, 2.0f);
    glClearColor(0.0f, 1.0f, 0.0f, 0.0f);
    glShadeModel(GL_SMOOTH);
    glEnableClientState(GL_VERTEX_ARRAY);
    glGenBuffers(1,&ID);
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ID);
    glBufferData(GL_ELEMENT_ARRAY_BUFFER,size*sizeof(float), &data_vector[0], GL_STATIC_DRAW);

    el_size=6*sizeof(float);
}
void display(void){

    int zoom = 1;
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(-2*zoom, 2*zoom,2*zoom,-2*zoom, -5.0f, 5.0f);
    glPushMatrix ();
    glBindBuffer(GL_ARRAY_BUFFER, ID);

    // Pointer for the position of the points
    glEnableClientState(GL_VERTEX_ARRAY);
    glVertexPointer(3, GL_FLOAT, el_size, 0);

    // Pointer for the color of the points
    glEnableClientState(GL_COLOR_ARRAY);
    glColorPointer(3,GL_FLOAT, el_size,(void*)(el_size/2));

    //Draw callback
    glDrawArrays(GL_TRIANGLES,0,size/6);

    glPopMatrix ();
    glFlush();
}

// Idle callback function for OpenGL API
void idle(void){

    float* pixels = (float*)malloc(windowSize*windowSize*sizeof(float));
    glReadPixels(0, 0, windowSize, windowSize, GL_DEPTH_COMPONENT, GL_FLOAT, pixels);

    //
    //char waveName[MAX_OBJ_NAME+1]; 
    //CountInt dimensionSizes[MAX_DIMENSIONS+1]; 
    //float* wp;
    //strcpy(waveName, "wave0");
    //MemClear(dimensionSizes, sizeof(dimensionSizes));
    //dimensionSizes[ROWS] = windowSize*windowSize; // Make 1D wave 
    //wp = (float*)WaveData(waveH); // Get a pointer to the wave data 

    //for(int i = 0;i < windowSize*windowSize; i++){    
    //  *wp++ =pixels[i];                 
    //}

    //glDeleteBuffers(1,&ID);
}

// Main function for the XOP
extern "C" int
RenderTriangle(FitParamsPtr p)
{
    waveX=(float*)WaveData(p->waveX);
    waveY=(float*)WaveData(p->waveY);
    waveZ=(float*)WaveData(p->waveZ);

    char *myargv [1];
    int myargc=1;
    myargv [0]=strdup ("RenderTriangle");
    glutInit(&myargc,myargv);
    glutInitDisplayMode(GLUT_SINGLE | GLUT_DEPTH | GLUT_RGB);
    glutInitWindowSize(windowSize,windowSize);
    glutCreateWindow("OpenGL");
    init();
    glutDisplayFunc(display);
    glutIdleFunc(idle);
    glutMainLoop();
    p->result = 1;

    return 0;
}

static XOPIORecResult
RegisterFunction()
{
    int funcIndex;

    funcIndex = (int)GetXOPItem(0);         // Which function invoked ?
    switch (funcIndex) {
        case 0:                                 // y = RenderTriangle(w,x) (curve fitting function).
            return (XOPIORecResult)RenderTriangle;  // This function is called using the direct method.
            break;
    }
    return 0;
}

/*  XOPEntry()

    This is the entry point from the host application to the XOP for all
    messages after the INIT message.
*/
extern "C" void
XOPEntry(void)
{   
    XOPIORecResult result = 0;

    switch (GetXOPMessage()) {
        case FUNCADDRS:
            result = RegisterFunction();    // This tells Igor the address of our function.
            break;
    }
    SetXOPResult(result);
}

/*  main(ioRecHandle)

    This is the initial entry point at which the host application calls XOP.
    The message sent by the host must be INIT.
    main() does any necessary initialization and then sets the XOPEntry field of the
    ioRecHandle to the address to be called for future messages.
*/
HOST_IMPORT int
main(IORecHandle ioRecHandle)
{   
    XOPInit(ioRecHandle);                           // Do standard XOP initialization.
    SetXOPEntry(XOPEntry);                          // Set entry point for future calls.

    if (igorVersion < 600) {
        SetXOPResult(OLD_IGOR);
        return EXIT_FAILURE;
    }

    SetXOPResult(0);
    return EXIT_SUCCESS;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T09:35:48+00:00Added an answer on June 17, 2026 at 9:35 am
    • VBOs are for transferring vertex data.

    You’re transferring in your point cloud data via a VBO, it can’t get better than that.

    • PBOs are for transferring pixel data.

    You could use a PBO to asynchronously read the data from the OpenGL framebuffer.

    • FBOs can be drawn onto.

    You should use a FBO to isolate your target framebuffer from any window operations.

    2) Also, I’d like to run glutMainLoop only once. Should I change to FreeGLUT?

    You don’t have to run the mainloop at all. All you need is just a window created; it won’t show up until the mainloop is started. You need the window to get an OpenGL context, but you can safely omit the mainloop.

    Instead of registering any callbacks (they won’t be called), just execute your OpenGL commands in order. If your library gets called several times you don’t have to recreate the window, but it may be neccessary to call glutSetWindow to make the context current.

    1. setup a FBO to draw onto
    2. draw to FBO
    3. glReadPixels
      • either into a PBO and glMapBuffer and memcpy.
      • or directly into a buffer of apropriate size.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I want use html5's new tag to play a wav file (currently only supported
I have this code to decode numeric html entities to the UTF8 equivalent character.
We're building an app, our first using Rails 3, and we're having to build
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
This could be a duplicate question, but I have no idea what search terms

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.