2DM example code
Example: 2DM example code
#include "2DM.h"
int main(void) {
WINDOW window = createWindow("2DM Window", 500, 500, WINDOW_NORMAL);
centerWindow(&window);
setIcon(&window, "icon.bmp");
float alpha = 0.0f;
while(window.open) {
if(pollEvents(&window)) {
switch(event.eventType) {
case CLOSE:
closeWindow(&window);
break;
case RESIZE:
{
updateWindowViewport(&window);
VEC2I windowSize = getWindowSize(&window);
printf("Window resized X:%d, Y:%d\n", windowSize.x, windowSize.y);
}
break;
#if defined(PLATFORM_WINAPI)
case RESIZING:
{
updateWindowViewport(&window);
VEC2I windowSize = getWindowSize(&window);
printf("Window resized with mouse X:%d, Y:%d\n", windowSize.x, windowSize.y);
}
break;
#endif
case KEYDOWN:
puts("Key down");
break;
case MOUSE_LBUTTON_PRESSED:
{
VEC2I mousePosition = getMousePosition(&window);
printf("Mouse X: %d, Mouse Y: %d\n", mousePosition.x, mousePosition.y);
}
break;
case MOUSE_RBUTTON_PRESSED:
puts("Right button pressed");
break;
}
}
if(isKeyPressed(A)) alpha -=1;
if(isKeyPressed(D)) alpha +=1;
glClearColor(0.0, 0.0, 0.0, 1.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glRotatef(alpha, 0.0f, 1.0f, 0.0f);
glBegin(GL_TRIANGLES);
glColor3f(1.0f, 0.0f, 0.0f);
glVertex2f(0.0f, 0.75f);
glColor3f(0.0f, 1.0f, 0.0f);
glVertex2f(-0.75f, -0.75f);
glColor3f(0.0f, 0.0f, 1.0f);
glVertex2f(0.75f, -0.75f);
glEnd();
glPopMatrix();
display(&window);
delay(10);
}
closeWindow(&window);
return 0;
}