Click here to Skip to main content
15,891,033 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need to perform pixel manipulation from images in glut OpenGL (I know it's old, but I'm bound by many other reasons). I need to change the image several times while showing them at the same time as well. I'm trying to use key event to perform that. Also, I'm using SOIL library to load my image.

What I have tried:

This is why I've been implementing :

static void         init(void);
static void         mainLoop(void);
static void         keyEvent( unsigned char key, int x, int y);

int main(int argc, char *argv[])
{
    init();
    image = SOIL_load_image("Images/img1.jpg", &width, &height, 0, SOIL_LOAD_RGBA);
    if(image == NULL) exit(0);
    
    argViewportSetImageSize(vp, width, height);
    argViewportSetPixFormat(vp, AR_PIXEL_FORMAT_RGBA);
    argViewportSetDispMode(vp, AR_GL_DISP_MODE_FIT_TO_VIEWPORT_KEEP_ACPECT_RATIO);

    argSetKeyFunc(keyEvent);
    glutIdleFunc(mainLoop);
    glutMainLoop(); 
}


key event :
static void keyEvent( unsigned char key, int x, int y)
{
    if( key == 'a' )
      {image = SOIL_load_image("Images/img2.jpg", &width, &height, 0, SOIL_LOAD_RGBA);
       if(image == NULL) exit(0);
       printf("%d x %d\n", width, height);
       genImages();
       }  
    //other key events
}



I notice how the key event works for any other command (manipulate pixel value for example), but doesn't work for changing image input. Is there any way I can achieve this ?
Posted
Updated 18-Jul-19 22:38pm
v2
Comments
Stefan_Lang 17-Jul-19 3:04am    
Can't help you about glut specifics, but you're loading the image before setting the key event function and before entering the glut main loop - how do you expect keyEvent could be called in that case?

P.S.: maybe I didn't get your intent right: If you meant to change the image from the initial one to another one, after the first image is loaded, then the question is a different one: how do you get glut to display that image after the initialization is over? Obviously part of the initialization is responsible for assoziating the image data with the display - identify that part and repeat it in your keyEvent function.

1 solution

The only thing your event handler does is load an image. What handles display of the image? Usually, when you load an image you have to invalidate the display window so that it is redrawn. I see no code that does that so that is probably what you lack to make it work.
 
Share this answer
 
Comments
lock&_lock 19-Jul-19 4:39am    
Hi, thanks ! I've updated my code. Now it's showing tearing image, black and white noise image like on TV. I will check on my code again and update it again.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900