diff --git a/.gitignore b/.gitignore index 49c87e0..5572e1d 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ *.a *.core *.dll +*.zip /deps /contrib /src/nishbox diff --git a/Makefile b/Makefile index 4c32637..9e5ac27 100644 --- a/Makefile +++ b/Makefile @@ -6,11 +6,12 @@ include mk/p_*.mk AR = $(TARGET_PREFIX)ar CC = $(TARGET_PREFIX)gcc OBJDUMP = $(TARGET_PREFIX)objdump -CFLAGS = -g -D_DEFAULT_SOURCE -DUSE_$(BACKEND) -I../engine $(ODE_CFLAGS) $(AMX_CFLAGS) $(PAWNC_CFLAGS) $(GL_CFLAGS) +STRIP = $(TARGET_PREFIX)strip +CFLAGS = -D_DEFAULT_SOURCE -DUSE_$(BACKEND) -I../engine $(ODE_CFLAGS) $(AMX_CFLAGS) $(PAWNC_CFLAGS) $(GL_CFLAGS) LDFLAGS = LIBS = $(ODE_LIBS) $(AMX_LIBS) $(PAWNC_LIBS) $(GL_LIBS) $(SOCKET_LIBS) -.PHONY: all format clean ./engine ./src print-deps +.PHONY: all format clean ./engine ./src print-deps pack all: ./src @@ -26,6 +27,9 @@ format: print-deps: @sh ./tool/deps.sh +pack: all + @sh ./tool/pack.sh + clean: $(MAKE) -C ./engine clean $(MAKE) -C ./src clean diff --git a/engine/GLX_draw.c b/engine/GLX_draw.c index 672788c..a392612 100644 --- a/engine/GLX_draw.c +++ b/engine/GLX_draw.c @@ -97,7 +97,7 @@ void _nb_draw_create(nb_draw_t** pdraw) { hints.height = draw->height; hints.flags = USSize | USPosition; XSetNormalHints(draw->display, draw->window, &hints); - XSetStandardProperties(draw->display, draw->window, "NishBox", "NishBox", None, (char**)NULL, 0, &hints); + XSetStandardProperties(draw->display, draw->window, "NishBox (GLX)", "NishBox", None, (char**)NULL, 0, &hints); draw->wm_delete_window = XInternAtom(draw->display, "WM_DELETE_WINDOW", False); XSetWMProtocols(draw->display, draw->window, &draw->wm_delete_window, 1); @@ -157,6 +157,7 @@ int _nb_draw_step(nb_draw_t* draw) { draw->y = event.xconfigure.y; draw->width = event.xconfigure.width; draw->height = event.xconfigure.height; + glXMakeCurrent(draw->display, draw->window, draw->context); nb_draw_reshape(draw); } else if(event.type == ClientMessage) { if(event.xclient.data.l[0] == draw->wm_delete_window) { diff --git a/engine/WGL_draw.c b/engine/WGL_draw.c index 6aad62f..cbc73cf 100644 --- a/engine/WGL_draw.c +++ b/engine/WGL_draw.c @@ -32,6 +32,7 @@ LRESULT CALLBACK _nb_draw_proc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp) { draw->y = rect.top; draw->width = rect.right - rect.left; draw->height = rect.bottom - rect.top; + wglMakeCurrent(draw->dc, draw->glrc); nb_draw_reshape(draw); break; case WM_CLOSE: @@ -96,10 +97,12 @@ void _nb_draw_create(nb_draw_t** pdraw) { DWORD style; draw->instance = (HINSTANCE)GetModuleHandle(NULL); if(draw->instance == NULL) { - nb_function_log("Failed to get the instance", ""); + nb_function_log("Failed to get instance", ""); nb_draw_destroy(draw); *pdraw = NULL; return; + } else { + nb_function_log("Got instance", ""); } wc.cbSize = sizeof(wc); @@ -119,41 +122,45 @@ void _nb_draw_create(nb_draw_t** pdraw) { nb_draw_destroy(draw); *pdraw = NULL; return; + } else { + nb_function_log("Registered class", ""); } - draw->window = CreateWindow("nishbox", "NishBox", (WS_OVERLAPPEDWINDOW), draw->x, draw->y, draw->width, draw->height, NULL, 0, draw->instance, NULL); + draw->window = CreateWindow("nishbox", "NishBox (WGL)", (WS_OVERLAPPEDWINDOW), draw->x, draw->y, draw->width, draw->height, NULL, 0, draw->instance, NULL); if(draw->window == NULL) { nb_function_log("Failed to create window", ""); nb_draw_destroy(draw); *pdraw = NULL; return; + } else { + nb_function_log("Created window", ""); } - SetRect(&rect, 0, 0, draw->width, draw->height); - style = (DWORD)GetWindowLongPtr(draw->window, GWL_STYLE); - AdjustWindowRect(&rect, style, FALSE); - SetWindowPos(draw->window, NULL, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, SWP_NOMOVE); - SetWindowLongPtr(draw->window, GWLP_USERDATA, (LONG_PTR)draw); - GetClientRect(draw->window, &rect); - memset(&desc, 0, sizeof(desc)); desc.nSize = sizeof(desc); desc.nVersion = 1; desc.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER; desc.iPixelType = PFD_TYPE_RGBA; - desc.cColorBits = 16; + desc.cColorBits = 24; desc.cAlphaBits = 8; - desc.cDepthBits = 16; + desc.cDepthBits = 32; draw->dc = GetDC(draw->window); fmt = ChoosePixelFormat(draw->dc, &desc); SetPixelFormat(draw->dc, fmt, &desc); - SetWindowPos(draw->window, HWND_TOP, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, SWP_FRAMECHANGED); draw->glrc = wglCreateContext(draw->dc); + if(draw->glrc == NULL) { + nb_function_log("Failed to create OpenGL context", ""); + nb_draw_destroy(draw); + *pdraw = NULL; + return; + } else { + nb_function_log("Created OpenGL context", ""); + } wglMakeCurrent(draw->dc, draw->glrc); wglSwapIntervalEXT = (PFNWGLSWAPINTERVALPROC)wglGetProcAddress("wglSwapIntervalEXT"); @@ -162,15 +169,22 @@ void _nb_draw_create(nb_draw_t** pdraw) { wglSwapIntervalEXT(1); } + SetRect(&rect, 0, 0, draw->width, draw->height); + style = (DWORD)GetWindowLongPtr(draw->window, GWL_STYLE); + AdjustWindowRect(&rect, style, FALSE); + SetWindowPos(draw->window, NULL, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, SWP_NOMOVE); + ShowWindow(draw->window, SW_NORMAL); UpdateWindow(draw->window); } void _nb_draw_destroy(nb_draw_t* draw) { - if(draw->window != NULL) { + if(draw->glrc != NULL) { wglMakeCurrent(NULL, NULL); ReleaseDC(draw->window, draw->dc); wglDeleteContext(draw->glrc); + } + if(draw->window != NULL) { DestroyWindow(draw->window); } } diff --git a/engine/draw.c b/engine/draw.c index becd67f..4260588 100644 --- a/engine/draw.c +++ b/engine/draw.c @@ -15,20 +15,23 @@ /* Standard */ #include #include +#include nb_draw_t* nb_draw_create(void) { nb_draw_t* draw = malloc(sizeof(*draw)); memset(draw, 0, sizeof(*draw)); - draw->x = 0; - draw->y = 0; - draw->width = 640; - draw->height = 480; + draw->x = 0; + draw->y = 0; + draw->width = 640; + draw->height = 480; + draw->running = 0; _nb_draw_create(&draw); if(draw != NULL) { nb_function_log("Created drawing interface successfully", ""); + nb_draw_init_opengl(draw); + nb_draw_reshape(draw); + draw->running = 1; } - nb_draw_init_opengl(draw); - nb_draw_reshape(draw); return draw; } @@ -87,17 +90,53 @@ void nb_draw_end_2d(nb_draw_t* draw) { glPopMatrix(); } -int i = 0; -void nb_draw_frame(nb_draw_t* draw) { - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - nb_draw_begin_2d(draw); - glBegin(GL_TRIANGLES); - glVertex2d(0, draw->height); - glVertex2d(i, 0); - glVertex2d(draw->width, draw->height); - i += 1; - glEnd(); - nb_draw_end_2d(draw); +double i = 0; +void nb_draw_frame(nb_draw_t* draw) { + double p = sin(i) * (draw->width / 2) + (draw->width / 2); + int j; + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + nb_draw_begin_2d(draw); + glColor3f(1, 0, 0); + glBegin(GL_TRIANGLES); + glVertex2d(0, 0); + glVertex2d(p, 0); + glVertex2d(0, draw->height); + glEnd(); + glColor3f(0, 1, 0); + glBegin(GL_TRIANGLES); + glVertex2d(0, draw->height); + glVertex2d(p, 0); + glVertex2d(draw->width, draw->height); + glEnd(); + glColor3f(0, 0, 1); + glBegin(GL_TRIANGLES); + glVertex2d(p, 0); + glVertex2d(draw->width, 0); + glVertex2d(draw->width, draw->height); + glEnd(); + + glEnable(GL_TEXTURE_2D); + for(j = 0; j <= 'Z' - 'A'; j++) { + double c = sin(i * 2 + j) / 2 + 1; + double s = 4.0 * c; + glColor3f(c, c, c); + glBindTexture(GL_TEXTURE_2D, draw->font['A' + j]); + glBegin(GL_QUADS); + glTexCoord2d(0, 0); + glVertex2d(0, 0); + glTexCoord2d(1, 0); + glVertex2d(3 * s, 0); + glTexCoord2d(1, 1); + glVertex2d(3 * s, 4 * s); + glTexCoord2d(0, 1); + glVertex2d(0, 4 * s); + glEnd(); + glTranslatef(3 * s, 0, 0); + } + glDisable(GL_TEXTURE_2D); + glBindTexture(GL_TEXTURE_2D, 0); + i += 0.01; + nb_draw_end_2d(draw); } int nb_draw_step(nb_draw_t* draw) { @@ -117,8 +156,10 @@ void nb_draw_reshape(nb_draw_t* draw) { void nb_draw_destroy(nb_draw_t* draw) { int i; - for(i = 0; i < sizeof(nb_font) / sizeof(nb_font[0]); i++) { - glDeleteTextures(1, &draw->font[i]); + if(draw->running) { + for(i = 0; i < sizeof(nb_font) / sizeof(nb_font[0]); i++) { + glDeleteTextures(1, &draw->font[i]); + } } _nb_draw_destroy(draw); free(draw); diff --git a/engine/nb_draw_platform.h b/engine/nb_draw_platform.h index f861080..1ffd739 100644 --- a/engine/nb_draw_platform.h +++ b/engine/nb_draw_platform.h @@ -37,6 +37,7 @@ typedef struct nb_draw { int y; int width; int height; + int running; GLuint font[128]; } nb_draw_t; #else diff --git a/tool/build-windows.sh b/tool/build-windows.sh index 41a8d1c..d164654 100755 --- a/tool/build-windows.sh +++ b/tool/build-windows.sh @@ -59,4 +59,3 @@ cd ../.. cd .. ${MAKE} PLATFORM=win${BITS} -cp `${MAKE} PLATFORM=win${BITS} print-deps` ./ diff --git a/tool/pack.sh b/tool/pack.sh new file mode 100755 index 0000000..6c37631 --- /dev/null +++ b/tool/pack.sh @@ -0,0 +1,11 @@ +#!/bin/sh + +rm -rf nishbox +rm -rf nishbox.zip +mkdir -p nishbox/bin +mkdir -p nishbox/lib +cp `./tool/deps.sh` ./nishbox/bin/ +cp src/nishbox.exe ./nishbox/bin/ +${STRIP} ./nishbox/bin/*.dll ./nishbox/bin/*.exe +zip -rv nishbox.zip nishbox +rm -rf nishbox