I have a work thread function which updates the value of a float called scale:
DWORD WINAPI WorkThreadFn(LPVOID lpParam)
{
MyWin* pWin = (MyWin*)lpParam;
while (pWin->running)
{
//pWin->scale = pWin->scale - 0.001;
pWin->scale = 0.5;
SendMessage(pWin->hwnd, WM_PAINT, NULL, NULL);
Sleep(1);
}
return 0;
}
If I change the value of scale in this function, the WM_PAINT draws my triangle to the correct scale. But if I uncomment the section which increments the scale, then remove the line setting the scale, the scale of the triangle remains the same, despite the fact I can see from the window procedure that the value of scale is decreasing.
Code for Window procedure:
LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
PAINTSTRUCT ps;
HDC hdc;
MyWin* pThis = NULL;
if (uMsg == WM_CREATE)
{
CREATESTRUCT* pCreate = (CREATESTRUCT*)lParam;
pThis = (MyWin*)pCreate->lpCreateParams;
SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)pThis);
}
else
{
pThis = (MyWin*)GetWindowLongPtr(hwnd, GWLP_USERDATA);
}
..
switch(uMsg) {
case WM_PAINT:
hdc = BeginPaint(hwnd, &ps);
RECT region = ps.rcPaint;
glClearColor(0.62, 0.3, 0.5, 1.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
pThis->glUniform1f(pThis->scaleLoc, pThis->scale);
glBindVertexArray(vaNames[0]);
glDrawArrays(GL_TRIANGLES, 0, 3);
glBindVertexArray(0);
SwapBuffers(hdc);
And also here is the vertex shader code
in vec3 in_Position;
in vec3 in_Color;
out vec3 ex_Color;
uniform float scale;
void main(void)
{
gl_Position = vec4(in_Position * scale, 1.0);
ex_Color = in_Color;
}
I'm sure I'm doing something stupid here, can anybody help?
Edit (forgot to add the main function):
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine, int nCmdShow)
{
MyWin win(hInstance, nCmdShow);
DWORD ThreadID;
HANDLE hThread;
hThread = CreateThread(NULL, 0, WorkThreadFn, &win, 0, &ThreadID);
win.MsgLoop();
if (hThread != NULL)
CloseHandle(hThread);
return 0;
}