hi all,
 
I has tried to render OpenGL in a bitmap but not windows using WGL . My code is as follow:
 

from OpenGL.GL import *
from OpenGL.GLU import *
from OpenGL.WGL import *
import Image
import ImageWin
import win32gui,win32ui
w = 120
h = 90
hdc = win32gui.CreateCompatibleDC(0)

bmp = Image.new("RGB",(w,h))
dib = ImageWin.Dib(bmp)

dib.expose(hdc)

pfd = PIXELFORMATDESCRIPTOR()
pfd.dwFlags= PFD_DRAW_TO_BITMAP | PFD_SUPPORT_OPENGL
pfd.iPixelType=PFD_TYPE_RGBA
pfd.cColorBits=32
pfd.cDepthBits=32
pfd.iLayerType=PFD_MAIN_PLANE

ppfd = PIXELFORMATDESCRIPTORPtr(pfd)

pfid = ChoosePixelFormat(hdc,ppfd)
print pfid

bpf = SetPixelFormat(hdc,pfid,ppfd)
hglrc = wglCreateContext(hdc)
wglMakeCurrent(hdc, hglrc)


glMatrixMode(GL_PROJECTION);
gluPerspective(30.0, 1.33333, 1.0, 10.0);
glMatrixMode(GL_MODELVIEW);
gluLookAt(0, 0, -5, 0, 0, 0, 0, 1, 0);
glBegin(GL_TRIANGLES);
glColor3d(1, 0, 0);
glVertex3d(0, 1, 0);
glColor3d(0, 1, 0);
glVertex3d(-1, -1, 0);
glColor3d(0, 0, 1);
glVertex3d(1, -1, 0);
glEnd();
glFlush();

#img.save("gl.png","png")

I got a error at this line alway:" i = SetPixelFormat(hdc,pfid,ppfd)" ,But if I delete this line,I got a error at next line.
 
I don't know how to write now .Or opengl context has something similar?
 
I'm so sorry about my terrible english!
 
thanks