offscreen rendering

Hi!

I have a problem with offscreen rendering:

I’ve been created a pBuffer, got a DC from this and created a RC.

I wanna get the framebuffer contents in:
GLubyte *imgout;

Well, in my render function, i do the following:

void Render(){
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glLoadIdentity();

glTranslatef(0,0,-5);

glBegin(GL_TRIANGLES);
glVertex3d(-1,0,0);
glVertex3d(1,0,0);
glVertex3f(0.0f,1.6f,0.0f);
glEnd();

//here i try to get the framebuffer content:
glReadPixels(
0,0,
screen_width,
screen_height,
GL_RGBA,
GL_UNSIGNED_BYTE,imgout
);

}

Well, all what i get is a GLubyte array filled with the color specified in glClearColor, pure blue.

I’d also tried with glCopyTexSubImage2D. I do the following:

GLuint tex;
ZeroMemory(imgout,sizeof(GLubyte)4screen_width*screen_height);
glGenTextures(1,&tex);
glBindTexture(GL_TEXTURE_2D, tex);

//i create an empty texture:
glTexImage2D(
GL_TEXTURE_2D, 0, 4,
screen_width, screen_height,
0, GL_RGBA,
GL_UNSIGNED_BYTE, imgout
);

glCopyTexSubImage2D(
GL_TEXTURE_2D,0,0,0,0,0,
screen_width,screen_height
);
glFlush();
glGetTexImage(
GL_TEXTURE_2D,0,GL_RGBA,
GL_UNSIGNED_BYTE,imgout);

But in this case i got an imgout array zero-filled.

sugestions??..

Bad english i wrote, i know… i’m spanish :rolleyes:

see ya!

I am not sure if this is the case but make sure your object is within visible are. Also, make sure the off-screen buffer is enabled before rendering. Are yo drawing in ortho mode ? maybe object is behind far plane ?

No, i’ve been rendered the same scene in a standard window and it runs ok.

I will explain you what i wanna do:

I need to render a scene in memory, but i don’t want to render previously in an active window. The steps i follow are:

  • I create a basic invisible window,

  • I get the window DC,

  • I call ChoosePixelFormat, SetPixelFormat --> OK

  • I get the RC with wglMakeContext

  • wglMakeCurrent

  • wglGetProcAddress ARB Extensions --> OK

  • Delete RC

  • wglChoosePixelFormatARB --> OK

  • wglCreatePbufferARB --> OK

  • I destroy the window DC.

  • I destroy the window.

  • I create a DC from the created pBuffer with the wglGetPbufferDCARB function

  • I get a RC from that DC

  • wglMakeCurrent(pbDC,pbRC);

  • READY TO INIT OPENGL.

Maybe i’m so confused and this method is not valid.

Valid or not, i must render the scene to memory, not to a visible window, and capturing the pixels of that scene.

Thanks…

Even though you are not using it you probably have to keep the original onscreen window around. I think some drivers don’t care if the onscreen window is destroyed but some do. Just keep all the handles valid and make the onscreen window invisible.

thanks! i will test it with keep the window active but invisible. i’m rewriting now the entire DLL to do this.

I’m trying to render offscreen to make a DLL that allow using opengl in a language that is actually only for making 2D games, and it’s SDL based, so i need to render the scene and copy its pixels to a SDL surface.

is my english understandable? lol.

if you are using wglCreatePbufferARB extension you dont need to have another invisible window. You just create Pbuffer for your main application window. It is invisible from definition.

EDIT: OpenGL must be initialized before Pbuffer is created!

but i need to create a RC before declaring any extension… if i don’t do that, extension creation fails.

I didn’t know i must initialize opengl before i create a pBuffer, thanks for this tip!

If I understand correctly you just want to render the scene into backbuffer and than copy all the pixels into SDL surface. Just render the scene into any window (it may be your 2D game window) but dont swap buffers. The content of the rendered scene won’t be visible and you would be able to grab it all the time.

FBO ?

SeskaPeel.

but i cannot change the pixelformat of the target window, and SDL do a swapbuffer in this language every frame, i thought…

FBO is not supported by my graphics card (nVidia RIVA TNT 2)