gazebosim / gazebosim/gz-rendering

Adding glutReshapeFunc to examples cause incorrect rendering.

Open
#589 5 comments 0 reactions 0 assignees View on GitHub
bug help wanted
Dominant language
C++
Stars
81
Forks
90
Avg merge
1d 13h
Merged PRs (30d)
10

Description

I noticed that none of the glut examples support resizing. I attempted to updated the mesh viewer example to allow resizing but ended up with incorrect rendering as show below. I assume since none of the examples have a reshape implementation this might be a known issue, but not sure. Am I doing something incorrect?

reshape function
``` c++
void reshapeCB(int w, int h)
{
imgw = w;
imgh = h;
glViewport (0, 0, (GLsizei) w, (GLsizei) h);
}
```

updated display callback
``` c++
void displayCB()
{
#if __APPLE__
CGLSetCurrentContext(g_context);
#elif _WIN32
#else
if (g_display)
{
glXMakeCurrent(g_display, g_drawable, g_context);
}
#endif

// Resize camera
auto camera = g_cameras[g_cameraIndex];
camera->SetImageHeight(imgh);
camera->SetImageWidth(imgw);
camera->SetAspectRatio(static_cast(imgw) / static_cast(imgh));
ir::Image image = camera->CreateImage();
g_image = std::make_shared(image);
camera->Capture(*g_image);

// g_cameras[g_cameraIndex]->Capture(*g_image);
handleMouse();

#if __APPLE__
CGLSetCurrentContext(g_glutContext);
#elif _WIN32
#else
glXMakeCurrent(g_glutDisplay, g_glutDrawable, g_glutContext);
#endif

unsigned char *data = g_image->Data();

glClearColor(0.5, 0.5, 0.5, 1);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPixelZoom(1, -1);
glRasterPos2f(-1, 1);
glDrawPixels(imgw, imgh, GL_RGB, GL_UNSIGNED_BYTE, data);

glutSwapBuffers();
}
```

![image](https://user-images.githubusercontent.com/9803128/159178431-acc299d0-7e5a-43af-ab7d-7744dff8dcc8.png)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.