|
From: Brian P. <bri...@tu...> - 2008-10-20 14:21:36
|
David Eger wrote: > Dear Mesa Users, > > I have what I expect is a typical usage scenario, but I'm having a > hard time getting all of the pieces to fall into place. I would like > to use Mesa to load up many textures and models and then use them to > render images of various resolutions on user request. My first > attempt to order things was as follows: > > [A] context = OSMesaCreateContextExt(OSMESA_RGBA, 0, 0, 0, NULL); > > [B] glGenTextures(1, &tex_id1); glBindTexture(GL_TEXTURE_2D, tex_id1); ... > glGenTextures(1, &tex_id2); glBindTexture(GL_TEXTURE_2D, tex_id2); ... > > [C] OSMesaMakeCurrent( > context, render_buffer, GL_UNSIGNED_BYTE, > w, h), > > [D] glMatrixMode(GL_PROJECTION); > glLoadIdentity(); > gluOrtho2D(0.0, (GLfloat)w, 0.0, (GLfloat)h); > glMatrixMode(GL_MODELVIEW); > glLoadIdentity(); > glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); > glBegin(QUADS);...glEnd(); glFlush(); > glReadPixels().. > > However, I found that repeated calls to glGenTextures() all yielded > texture id's of 0. Correct, you must have a currently bound context before calling any gl function. > I then moved the ordering to the following: > > [A] context = OSMesaCreateContextExt(OSMESA_RGBA, 0, 0, 0, NULL); > > [C1] OSMesaMakeCurrent( > context, render_buffer, GL_UNSIGNED_BYTE, > 1, 1), > > [B] glGenTextures(1, &tex_id1); glBindTexture(GL_TEXTURE_2D, tex_id1); ... > glGenTextures(1, &tex_id2); glBindTexture(GL_TEXTURE_2D, tex_id2); ... > > [C2] OSMesaMakeCurrent( > context, render_buffer, GL_UNSIGNED_BYTE, > w, h), > > [D] glMatrixMode(GL_PROJECTION); > glLoadIdentity(); > gluOrtho2D(0.0, (GLfloat)w, 0.0, (GLfloat)h); > glMatrixMode(GL_MODELVIEW); > glLoadIdentity(); > glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); > glBegin(QUADS);...glEnd(); glFlush(); > glReadPixels().. > > This "fixed" the repeated calls to glGenTextures - they produce > distinct texture ids as advertised. However, C2 appears to have only > partially worked. The glClear() does indeed wipe all pixels in the > newly enlarged render buffer, but the output from glBegin()...glEnd() > is confined to the original 1 pixel! Is it intended that one cannot > re-bind a context created with OSMesaCreateContext(Ext) to multiple > buffers over time? The first time a rendering context is bound, the viewport and scissor bounds are set to the window/drawable size. So the first call to OSMesaMakeCurrent() is setting the viewport/scissor to 1x1. The second call to OSMesaMakeCurrent() does not change the viewport/scissor. The solution to your problem is to call glViewport(0,0,w,h) after the 2nd OSMesaMakeCurrent(). Or, pass w,h to the first call, instead of 1,1. -Brian |