mirror of
https://github.com/NGSolve/netgen.git
synced 2024-12-24 04:50:34 +05:00
cleanup in Snapshot()
This commit is contained in:
parent
a06189ac4e
commit
c8901ba46b
@ -47,12 +47,10 @@ extern void (*glBindFramebuffer) (GLenum target, GLuint framebuffer);
|
||||
extern void (*glBindRenderbuffer) (GLenum target, GLuint renderbuffer);
|
||||
extern void (*glDeleteFramebuffers) (GLsizei n, const GLuint *framebuffers);
|
||||
extern void (*glDeleteRenderbuffers) (GLsizei n, const GLuint *renderbuffers);
|
||||
extern void (*glFramebufferTexture) (GLenum target, GLenum attachment, GLuint texture, GLint level);
|
||||
extern void (*glGenFramebuffers) (GLsizei n, GLuint *framebuffers);
|
||||
extern void (*glGenRenderbuffers) (GLsizei n, GLuint *renderbuffers);
|
||||
extern void (*glRenderbufferStorage) (GLenum target, GLenum internalformat, GLsizei width, GLsizei height);
|
||||
extern void (*glFramebufferRenderbuffer) (GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer);
|
||||
extern void (*glNamedFramebufferReadBuffer) ( GLuint framebuffer, GLenum mode);
|
||||
#endif
|
||||
DLL_HEADER void LoadOpenGLFunctionPointers();
|
||||
#endif // INCOPENGL_HPP___
|
||||
|
@ -783,7 +783,12 @@ namespace netgen
|
||||
|
||||
std::vector<unsigned char> Snapshot( int w, int h )
|
||||
{
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
// save current settings
|
||||
GLint viewport[4];
|
||||
glGetIntegerv (GL_VIEWPORT, viewport);
|
||||
|
||||
glMatrixMode (GL_PROJECTION);
|
||||
glPushMatrix();
|
||||
glLoadIdentity();
|
||||
|
||||
double pnear = 0.1;
|
||||
@ -791,50 +796,48 @@ namespace netgen
|
||||
|
||||
gluPerspective(20.0f, double(w) / h, pnear, pfar);
|
||||
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glMatrixMode (GL_MODELVIEW);
|
||||
glPushMatrix();
|
||||
glLoadIdentity();
|
||||
glViewport(0,0,w,h);
|
||||
|
||||
GLuint fb = 0;
|
||||
glGenFramebuffers(1, &fb);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, fb);
|
||||
|
||||
GLuint tex;
|
||||
glGenTextures(1, &tex);
|
||||
// create, reserve and attach color and depth renderbuffer
|
||||
GLuint rbs[2];
|
||||
glGenRenderbuffers(2, rbs);
|
||||
glBindRenderbuffer(GL_RENDERBUFFER, rbs[0]);
|
||||
glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, w, h);
|
||||
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, rbs[0]);
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, tex);
|
||||
|
||||
glTexImage2D(GL_TEXTURE_2D, 0,GL_RGBA, w, h, 0,GL_RGBA, GL_UNSIGNED_BYTE, 0);
|
||||
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
|
||||
GLuint depthrenderbuffer;
|
||||
glGenRenderbuffers(1, &depthrenderbuffer);
|
||||
glBindRenderbuffer(GL_RENDERBUFFER, depthrenderbuffer);
|
||||
glBindRenderbuffer(GL_RENDERBUFFER, rbs[1]);
|
||||
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, w, h);
|
||||
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depthrenderbuffer);
|
||||
|
||||
glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, tex, 0);
|
||||
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, rbs[1]);
|
||||
|
||||
// check if framebuffer status is complete
|
||||
if(int fbstatus; (fbstatus = glCheckFramebufferStatus(GL_FRAMEBUFFER)) != GL_FRAMEBUFFER_COMPLETE)
|
||||
cerr << "no frame buffer " << fbstatus << endl;
|
||||
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, fb);
|
||||
glViewport(0,0,w,h);
|
||||
|
||||
glPushMatrix();
|
||||
visual_scene->DrawScene();
|
||||
glFinish();
|
||||
glPopMatrix();
|
||||
|
||||
std::vector<unsigned char> buffer(w*h*3);
|
||||
glPixelStorei(GL_UNPACK_ALIGNMENT,1);
|
||||
glPixelStorei(GL_PACK_ALIGNMENT,1);
|
||||
glReadPixels (0, 0, w, h, GL_RGB, GL_UNSIGNED_BYTE, &buffer[0]);
|
||||
|
||||
glDeleteRenderbuffers(1, &depthrenderbuffer);
|
||||
glDeleteTextures(1, &tex);
|
||||
glDeleteRenderbuffers(2, rbs);
|
||||
glDeleteFramebuffers(1, &fb);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
|
||||
// restore previous settings
|
||||
glViewport(viewport[0], viewport[1], viewport[2], viewport[3]);
|
||||
glMatrixMode (GL_PROJECTION);
|
||||
glPopMatrix();
|
||||
glMatrixMode (GL_MODELVIEW);
|
||||
glPopMatrix();
|
||||
return buffer;
|
||||
}
|
||||
|
||||
|
@ -4896,12 +4896,10 @@ void (*glBindFramebuffer) (GLenum target, GLuint framebuffer);
|
||||
void (*glBindRenderbuffer) (GLenum target, GLuint renderbuffer);
|
||||
void (*glDeleteFramebuffers) (GLsizei n, const GLuint *framebuffers);
|
||||
void (*glDeleteRenderbuffers) (GLsizei n, const GLuint *renderbuffers);
|
||||
void (*glFramebufferTexture) (GLenum target, GLenum attachment, GLuint texture, GLint level);
|
||||
void (*glGenFramebuffers) (GLsizei n, GLuint *framebuffers);
|
||||
void (*glGenRenderbuffers) (GLsizei n, GLuint *renderbuffers);
|
||||
void (*glRenderbufferStorage) (GLenum target, GLenum internalformat, GLsizei width, GLsizei height);
|
||||
void (*glFramebufferRenderbuffer) (GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer);
|
||||
void (*glNamedFramebufferReadBuffer) ( GLuint framebuffer, GLenum mode);
|
||||
|
||||
DLL_HEADER void LoadOpenGLFunctionPointers() {
|
||||
#ifdef USE_BUFFERS
|
||||
@ -4918,12 +4916,10 @@ DLL_HEADER void LoadOpenGLFunctionPointers() {
|
||||
glBindRenderbuffer = (decltype(glBindRenderbuffer )) wglGetProcAddress("glBindRenderbuffer");
|
||||
glDeleteFramebuffers = (decltype(glDeleteFramebuffers )) wglGetProcAddress("glDeleteFramebuffers");
|
||||
glDeleteRenderbuffers = (decltype(glDeleteRenderbuffers )) wglGetProcAddress("glDeleteRenderbuffers");
|
||||
glFramebufferTexture = (decltype(glFramebufferTexture )) wglGetProcAddress("glFramebufferTexture");
|
||||
glGenFramebuffers = (decltype(glGenFramebuffers )) wglGetProcAddress("glGenFramebuffers");
|
||||
glGenRenderbuffers = (decltype(glGenRenderbuffers )) wglGetProcAddress("glGenRenderbuffers");
|
||||
glRenderbufferStorage = (decltype(glRenderbufferStorage )) wglGetProcAddress("glRenderbufferStorage");
|
||||
glFramebufferRenderbuffer = (decltype(glFramebufferRenderbuffer )) wglGetProcAddress("glFramebufferRenderbuffer");
|
||||
glNamedFramebufferReadBuffer = (decltype(glNamedFramebufferReadBuffer )) wglGetProcAddress("glNamedFramebufferReadBuffer");
|
||||
}
|
||||
#else // WIN32
|
||||
DLL_HEADER void LoadOpenGLFunctionPointers() { }
|
||||
|
Loading…
Reference in New Issue
Block a user