DepthmapRenderer::DepthmapRenderer(int resx, int resy) { //First of all: create opengl context: //res=glm::ivec2(resx,resy); res=Eigen::Vector2i(resx,resy); if(counter==0){ //BEGIN OF COPYCAT CODE static int visual_attribs[] = { None }; int context_attribs[] = { GLX_CONTEXT_MAJOR_VERSION_ARB, 3, GLX_CONTEXT_MINOR_VERSION_ARB, 0, None }; dpy = XOpenDisplay(0); int fbcount = 0; GLXFBConfig* fbc = NULL; GLXPbuffer pbuf; /* open display */ if ( ! (dpy = XOpenDisplay(0)) ){ fprintf(stderr, "Failed to open display\n"); exit(1); } /* get framebuffer configs, any is usable (might want to add proper attribs) */ if ( !(fbc = glXChooseFBConfig(dpy, DefaultScreen(dpy), visual_attribs, &fbcount) ) ){ fprintf(stderr, "Failed to get FBConfig\n"); exit(1); } /* get the required extensions */ glXCreateContextAttribsARB = (glXCreateContextAttribsARBProc)glXGetProcAddressARB( (const GLubyte *) "glXCreateContextAttribsARB"); glXMakeContextCurrentARB = (glXMakeContextCurrentARBProc)glXGetProcAddressARB( (const GLubyte *) "glXMakeContextCurrent"); if ( !(glXCreateContextAttribsARB && glXMakeContextCurrentARB) ){ fprintf(stderr, "missing support for GLX_ARB_create_context\n"); XFree(fbc); exit(1); } /* create a context using glXCreateContextAttribsARB */ if ( !( ctx = glXCreateContextAttribsARB(dpy, fbc[0], 0, True, context_attribs)) ){ fprintf(stderr, "Failed to create opengl context\n"); XFree(fbc); exit(1); } /* create temporary pbuffer */ int pbuffer_attribs[] = { GLX_PBUFFER_WIDTH, 800, GLX_PBUFFER_HEIGHT, 600, None }; pbuf = glXCreatePbuffer(dpy, fbc[0], pbuffer_attribs); XFree(fbc); XSync(dpy, False); /* try to make it the current context */ if ( !glXMakeContextCurrent(dpy, pbuf, pbuf, ctx) ){ /* some drivers does not support context without default framebuffer, so fallback on * using the default window. */ if ( !glXMakeContextCurrent(dpy, DefaultRootWindow(dpy), DefaultRootWindow(dpy), ctx) ){ fprintf(stderr, "failed to make current\n"); exit(1); } } /* try it out */ // printf("vendor: %s\n", (const char*)glGetString(GL_VENDOR)); //END OF COPYCATCODE } counter++; GLenum err=glewInit(); if(err!=GLEW_OK){ std::stringstream s; s << "glewInit failed, aborting. " << err; throw std::runtime_error(s.str()); } glGetError(); //create framebuffer: //Hardcoded shader: const char *vertex= "#version 450 \n\ in vec4 pos;\n\ out vec4 colorIn;\n\ void main(){\n\ gl_Position=vec4(pos.xyz,1);\n\ colorIn=unpackUnorm4x8(floatBitsToUint(pos.w));\n\ }";
void PacketData::write32f(float value) { write32(floatBitsToUint(value)); }