I created a sample app once that would fill a listview with a series of images created with openGL of rendered spheres. Each sphere would have a different material applied, different specular, ambient and diffuse values were also used.
In essence, I followed the following steps:
1.) Determine number of images required
2.) Create an imageList with space for this many images.
3.) Create image
4.) Add image to imageList
5.) if numImagesCreated < numImagesNeeded then goto step 3
6.) Assign imageList to listView container.
7.) Add item to listView (including specifying the index of it's image)
8.) If numListViewItems < numListViewItems required then goto step 7.
You can see the code in question here:
void fillListView(HINSTANCE hInst, HWND listHwnd)
{
HBITMAP tmpBmp;
HIMAGELIST imgList;
HWND ctrlWnd;
int i;
LV_ITEM newItem;
int numMaterials = matLib.size();
imgList = ImageList_Create(tileSize,tileSize,ILC_COLOR32,numMaterials,0);
for (i=0;i<numMaterials;i++)
{
tmpBmp = myMakeGlSphereBmp(matLib[i]);
ImageList_Add(imgList, tmpBmp, NULL);
DeleteObject(tmpBmp);
}
ListView_SetImageList(listHwnd, imgList, LVSIL_NORMAL);
newItem.mask = LVIF_IMAGE | LVIF_PARAM;
newItem.iItem = 0;
newItem.iSubItem = 0;
newItem.state = 0;
newItem.stateMask = 0;
char itemString[100];
for (i=0; i<numMaterials; i++)
{
newItem.iImage = i;
newItem.lParam = i;
ListView_InsertItem(listHwnd, &newItem);
}
ListView_SortItems(listHwnd, listViewLparamSHINYComparareProc, NULL);
ListView_SetIconSpacing(listHwnd, tileSize+4, tileSize+4);
}
I suppose that you could simply load the image before changing it's colour with FillRect. It should be a fairly straightforward task to create a function that will return a HBITMAP of the specified dimensions that is filled with a single solid colour.
Perhaps something like:
myMakeBmp(int xDim, int yDim, COLORREF colorToFillWith)
Here's my code for
myMakeGlSphereBmp
. I suggest you pay particular attention to the code up-to and including "
DeleteObject(myBrush);
"
[EDIT:] Forgot to mention, you'll need this clean-up code too
SelectObject(memDC, oldBmp);
DeleteDC(memDC);
HBITMAP myMakeGlSphereBmp(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;
DeleteObject(myBrush);
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;
}