I wrote the following code a couple of years ago, having learned and forgotten plenty since then. :embarrassed:
I used it to create bitmaps of spheres with different material properties, which would then be inserted into a listView - it was a materials editor.
HBITMAP makeBmp(material_t materialToUse)
{
HDC memDC, screenDC;
HBITMAP result, oldBmp;
BITMAPINFO bitmapInfo;
char *bitmapBits;
RECT myRect;
HBRUSH myBrush;
bitmapInfo.bmiHeader.biBitCount = 24;
bitmapInfo.bmiHeader.biWidth = tileSize;
bitmapInfo.bmiHeader.biHeight = tileSize;
bitmapInfo.bmiHeader.biCompression = BI_RGB;
bitmapInfo.bmiHeader.biPlanes = 1;
bitmapInfo.bmiHeader.biSize = sizeof(bitmapInfo.bmiHeader);
bitmapInfo.bmiHeader.biClrImportant = 0;
bitmapInfo.bmiHeader.biClrUsed = 0;
screenDC = GetDC(NULL);
memDC = CreateCompatibleDC(screenDC);
result = CreateDIBSection(memDC, &bitmapInfo, DIB_RGB_COLORS, (void**)&bitmapBits, 0, 0);
oldBmp = (HBITMAP)SelectObject(memDC, result);
myRect.left=0;
myRect.top=0;
myRect.right=bitmapInfo.bmiHeader.biWidth;
myRect.bottom=bitmapInfo.bmiHeader.biHeight;
HGLRC tmpRC;
tmpRC = EnableOpenGL(memDC);
glViewport(0, 0, bitmapInfo.bmiHeader.biWidth, bitmapInfo.bmiHeader.biHeight);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
float aspectRatio = (float)bitmapInfo.bmiHeader.biWidth / bitmapInfo.bmiHeader.biHeight;
gldPerspective (40, -aspectRatio, 1, 10.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glEnable(GL_LIGHT0);
glEnable(GL_NORMALIZE);
glEnable(GL_LIGHTING);
const GLfloat light_ambient[] = { 0.3f, 0.3f, 0.3f, 1.0f };
const GLfloat light_diffuse[] = { 0.5f, 0.5f, 0.5f, 1.0f };
const GLfloat light_specular[] = { 0.8f, 0.8f, 0.8f, 1.0f };
const GLfloat light_position[] = { -3.0f, -4.0f, 5.0f, 0.0f };
glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
const GLfloat mat_ambient[] = { 0.5f, 0.5f, 0.5f, 1.0f };
const GLfloat mat_diffuse[] = { 0.8f, 0.8f, 0.8f, 1.0f };
const GLfloat mat_specular[] = { 0.9f, 0.9f, 0.9f, 1.0f };
const GLfloat high_shininess[] = { materialToUse.shininess};
glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
glMaterialfv(GL_FRONT, GL_SHININESS, high_shininess);
glEnable(GL_COLOR_MATERIAL);
glClearColor(1,1,1,1.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
GLfloat rr,gg,bb;
rr=(int)materialToUse.r/255.0;
gg=(int)materialToUse.g/255.0;
bb=(int)materialToUse.b/255.0;
glTranslated(0,0,-3);
glRotated(-90,1,0,0);
glColor3d(rr,gg,bb);
myGlutBall(1, 32,32);
SwapBuffers(memDC);
wglMakeCurrent( NULL, NULL );
wglDeleteContext( tmpRC );
SelectObject(memDC, oldBmp);
DeleteDC(memDC);
return result;
}
Basically, I think you can cull all code between EnableOpenGL and SwapBuffer, replacing it with the code you have. Note: that this code does not make use of anything other than 'raw' openGL - no use of glut or glaux or any other frameworks/libraries. I've no idea what you would need to modify/write to achieve the same with one.
If you combine this code with some that will write a HBITMAP to a .BMP file, you should have what you need.
You should also continue to improve and hone your problem-solving skills. Namely, break-down a problem into manageable components, before solving each of them - either by yourself with some help from google & forums, or by simply searching for code you can copy and paste. I would generally ignore a request similar to yours - however, I'm in a good mood, you asked if we could help (rather than telling us to help, as many do), also, you didn't say "it's urgent".
I debated whether or not to answer, lest it encourage others to ask questions without trying to solve the problem first. I figured, you'll hopefully read my advice regarding solving a problem on your own, as would they. Besides, generally speaking, someone that wants to learn should be rewarded, I think!