My code draws a square but doesn’t change size for each timer tick event?
Any ideas please?
#include "frmDeviceRender.h"
void initGL() {
glClearColor (0.0, 0.0, 0.0, 0.0);
glColor3f (1.0, 1.0, 1.0);
glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0);
};
void drawIt(float bsize) {
glClear (GL_COLOR_BUFFER_BIT);
glBegin(GL_POLYGON);
float from = (1 - bsize) / 2;
float to = (1 - from);
glVertex3f (from, from, 0.0);
glVertex3f (to, from, 0.0);
glVertex3f (to, to, 0.0);
glVertex3f (from, to, 0.0);
glEnd();
glFlush();
};
void FrmDeviceRender::setFormDefaults() {
setFormProperties(0, WS_OVERLAPPEDWINDOW , CW_USEDEFAULT, CW_USEDEFAULT, 400, 300, TEXT("Rendered Container"));
};
void FrmDeviceRender::populateForm() {
hdc = GetDC (me) ;
GLsizei width = 200;
GLsizei height = 200;
int bits = 32;
GLuint PixelFormat;
static PIXELFORMATDESCRIPTOR pfd=
{
sizeof(PIXELFORMATDESCRIPTOR),
1,
PFD_DRAW_TO_WINDOW |
PFD_SUPPORT_OPENGL |
PFD_DOUBLEBUFFER,
PFD_TYPE_RGBA,
bits,
0, 0, 0, 0, 0, 0,
0,
0,
0,
0, 0, 0, 0,
16,
0,
0,
PFD_MAIN_PLANE,
0,
0, 0, 0
};
if (!(PixelFormat=ChoosePixelFormat(hdc,&pfd))) {
MessageBox(NULL,L"Can't Find A Suitable PixelFormat.",L"ERROR",MB_OK|MB_ICONEXCLAMATION);
}
if(!SetPixelFormat(hdc,PixelFormat,&pfd)) {
MessageBox(NULL,L"Can't Set The PixelFormat.",L"ERROR",MB_OK|MB_ICONEXCLAMATION);
}
if (!(hRC=wglCreateContext(hdc))) {
MessageBox(NULL,L"Can't Create A GL Rendering Context.",L"ERROR",MB_OK|MB_ICONEXCLAMATION);
}
if(!wglMakeCurrent(hdc,hRC)) {
MessageBox(NULL,L"Can't Activate The GL Rendering Context.",L"ERROR",MB_OK|MB_ICONEXCLAMATION);
}
};
void FrmDeviceRender::onPaint() {
initGL();
BoxSize = 0.8;
drawIt(BoxSize);
SwapBuffers(hdc);
SetTimer (me, 1, 1000, NULL);
}
void FrmDeviceRender::onUnload() {
KillTimer (me, 1);
ReleaseDC (me, hdc) ;
PostQuitMessage (0);
};
void FrmDeviceRender::onTimerTick(int id) {
BoxSize *= 0.9;
drawIt(BoxSize);
SwapBuffers(hdc);
};