/* 2+---3+----+----+ | | | | 0+---1+----+----+ | | | | +----+----+----+ */ static void create_verts() { int num_cols = NCOLS; int num_rows = NROWS; int num_chars = num_cols * num_rows; _num_verts = num_chars * 4; int num_floats = _num_verts * 2; _verts = (float*) malloc(num_floats * sizeof(float)); int i, j, k; k = 0; float x; float y = win_height() + _ch_h; for(i = 0; i < num_rows; ++i) { x = 0; y -= _ch_h; for(j = 0; j < num_cols; ++j) { // v0 _verts[k++] = x; _verts[k++] = y - _ch_h; // v1 _verts[k++] = x + _ch_w; _verts[k++] = y - _ch_h; // v2 _verts[k++] = x; _verts[k++] = y; // v3 _verts[k++] = x + _ch_w; _verts[k++] = y; x += _ch_w; } } }
/* +----+----+----+ | | | | +----+----+----+ | | | | +----+----+----+ */ static void create_tcoords() { int num_cols = NUM_TEXT_BUF_COLS; int num_rows = NUM_TEXT_BUF_ROWS; int num_chars = num_cols * num_rows; _num_tcoords = num_chars * 4; int num_floats = _num_tcoords * 2; int cb_tcoords = num_floats * sizeof(float); _tcoords = (float*) malloc(cb_tcoords); int i, j, k; k = 0; float x; unsigned char ch = ' '; // float y = NUM_TEXT_BUF_ROWS * _bm_h + _bm_h; float y = win_height() + _bm_h; for(i = 0; i < num_rows; ++i) { x = 0; y -= _bm_h; for(j = 0; j < num_cols; ++j) { tfont_get_tex_idx(ch, _tcoords+k); k += 8; x += _bm_w; } } if(k != num_floats) sys_err("_tcoords bounds error"); }
static void set_projection() { glMatrixMode(GL_PROJECTION); glLoadIdentity(); int l = 0; int r = win_width(); int b = 0; int t = win_height(); gluOrtho2D(l, r, b, t); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); }
int main(int argc, char* argv[]) { win_new(); glfwSetWindowTitle("font_perf"); // font_set_color(1, 1, 1, 0); perf_init(); // main loop glClearColor(0.3f, 0.3f, 0.3f, 1.0f); while(1) { perf_mark_beg("glClear"); glClear(GL_COLOR_BUFFER_BIT); perf_mark_end("glClear"); perf_mark_beg("ortho"); glMatrixMode(GL_PROJECTION); glLoadIdentity(); int l = 0; int r = win_width(); int b = 0; int t = win_height(); gluOrtho2D(l, r, b, t); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); perf_mark_end("ortho"); // draw bitmap letter // perf_mark_beg("draw_letter"); // int i; // for(i = 0; i < 50; ++i) { draw_letter(); // } // perf_mark_end("draw_letter"); // font_draw(100, 100, "bitchin camaro!"); perf_mark_beg("swap"); glfwSwapBuffers(); perf_mark_end("swap"); if(!glfwGetWindowParam(GLFW_OPENED)) break; // fps_inc_frames_drawn(); perf_report(); } perf_terminate(); glfwTerminate(); return 0; }
void draw_text() { int ch_rows = 36; int ch_h = 16; float x = 0; float y = win_height(); int i; for(i = 0; i < ch_rows; ++i) { x = 0; y -= ch_h; glPushMatrix(); glTranslatef(x, y, 0); const char* ln = test_line(i); tfont_draw_string(ln); glPopMatrix(); } }
/* 2+---3+----+----+ | | | | 0+---1+----+----+ | | | | +----+----+----+ */ static void create_verts() { int num_cols = NUM_TEXT_BUF_COLS; int num_rows = NUM_TEXT_BUF_ROWS; int num_chars = num_cols * num_rows; _num_verts = num_chars * 4; int num_floats = _num_verts * 2; int cb_verts = num_floats * sizeof(float); _verts = (float*) malloc(cb_verts); int i, j, k; k = 0; float x; // float y = NUM_TEXT_BUF_ROWS * _bm_h + _bm_h; float y = win_height() + _bm_h; for(i = 0; i < num_rows; ++i) { x = 0; y -= _bm_h; for(j = 0; j < num_cols; ++j) { // v0 _verts[k++] = x; _verts[k++] = y - _bm_h; // v1 _verts[k++] = x + _bm_w; _verts[k++] = y - _bm_h; // v2 _verts[k++] = x; _verts[k++] = y; // v3 _verts[k++] = x + _bm_w; _verts[k++] = y; x += _bm_w; } } if(k != num_floats) sys_err("_verts bounds error"); }
/* +----+----+----+ | | | | +----+----+----+ | | | | +----+----+----+ */ static void create_tcoords() { int num_cols = NCOLS; int num_rows = NROWS; int num_chars = num_cols * num_rows; _num_tcoords = num_chars * 4; int num_floats = _num_tcoords * 2; _tcoords = (float*) malloc(num_floats * sizeof(float)); int i, j, k; k = 0; float x; float y = win_height() + _ch_h; for(i = 0; i < num_rows; ++i) { const char* ln = test_line(i); x = 0; y -= _ch_h; for(j = 0; j < num_cols; ++j) { unsigned char ch = ln[j]; tfont_get_tex_idx(ch, _tcoords+k); k += 8; x += _ch_w; } } }
static void draw_font_set() { int x0, x1, x2, x3; int y0, y1, y2, y3; int i, j, k; int num_rows = NUM_FONT_ROWS; int num_cols = NUM_FONT_COLS; int pw = UNIT_RECT_WIDTH - 1; int ph = UNIT_RECT_HEIGHT - 1; // draw back polys glBegin(GL_TRIANGLES); y0 = y1 = win_height() - UNIT_RECT_HEIGHT; y2 = y3 = win_height() - UNIT_RECT_HEIGHT + ph; k = 0; for(i = 0; i < num_rows; ++i) { x2 = x0 = 0; x1 = x3 = pw; for(j = 0; j < num_cols; ++j) { glColor3f(POLY_COLOR[0], POLY_COLOR[1], POLY_COLOR[2]); glVertex2d(x0, y0); glVertex2d(x1, y1); glVertex2d(x2, y2); glVertex2d(x1, y1); glVertex2d(x3, y3); glVertex2d(x2, y2); x0 += UNIT_RECT_WIDTH; x1 += UNIT_RECT_WIDTH; x2 += UNIT_RECT_WIDTH; x3 += UNIT_RECT_WIDTH; } y0 -= UNIT_RECT_HEIGHT; y1 -= UNIT_RECT_HEIGHT; y2 -= UNIT_RECT_HEIGHT; y3 -= UNIT_RECT_HEIGHT; } glEnd(); // draw font chars y0 = y1 = win_height() - UNIT_RECT_HEIGHT; y2 = y3 = win_height() - UNIT_RECT_HEIGHT + ph; k = 0; for(i = 0; i < num_rows; ++i) { x2 = x0 = 0; x1 = x3 = pw; for(j = 0; j < num_cols; ++j) { font_set_color(FONT_COLOR[0], FONT_COLOR[1], FONT_COLOR[2], FONT_COLOR[3]); char s[2] = "\0\0"; s[0] = k++; // for some reason, font_draw currently crashes drawing chars >= 128 if(k==128) { goto outtahere; } font_draw(x0, y0, s); x0 += UNIT_RECT_WIDTH; x1 += UNIT_RECT_WIDTH; x2 += UNIT_RECT_WIDTH; x3 += UNIT_RECT_WIDTH; } y0 -= UNIT_RECT_HEIGHT; y1 -= UNIT_RECT_HEIGHT; y2 -= UNIT_RECT_HEIGHT; y3 -= UNIT_RECT_HEIGHT; } outtahere: return; }
LRESULT CALLBACK SpltWe_WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { static int oldx; static int y; static int line_height; static int min_left; static int max_right; POINT pt; HDC hdc; RECT rect; HWND hp = GetParent(hwnd); switch (message) { case WM_CREATE: return 0 ; case WM_LBUTTONDOWN: SetCapture(hwnd); we_sizing = 1; line_height = win_height(hwnd); y = win_top(hwnd);; pt.x = (short)LOWORD(lParam); // horizontal position of cursor pt.y = (short)HIWORD(lParam); GetWindowRect(hp,&rect); min_left = rect.left + MIN_SPLT_SPACE; max_right = rect.right - MIN_SPLT_SPACE; //GetClientRect(hwnd,&splt_rect); //SCreenToClient(rect); //GetWindowRect(hwnd_frame, &rect_frame_scr); //client_0_0.x = 0; //client_0_0.y=0; //ClientToScreen(hwnd_frame,&client_0_0); //client_0_0.y-= rect_frame_scr.top; //client_0_0.x-= rect_frame_scr.left; ClientToScreen(hwnd,&pt); //convert the mouse coordinates relative to the top-left of //the window //ScreenToClient(hwnd_frame,&pt); if(pt.x < min_left) pt.x = min_left; if(pt.x > max_right) { pt.x = max_right; } hdc = GetDC(NULL); DrawXorBar(hdc, pt.x-SPLT_WIDTH/2, y, SPLT_WIDTH, line_height); ReleaseDC(NULL, hdc); oldx = pt.x; break; case WM_LBUTTONUP: ReleaseCapture(); pt.x = (short)LOWORD(lParam); // horizontal position of cursor pt.y = (short)HIWORD(lParam); GetClientRect(hp,&rect); //GetClientRect(hwnd,&splt_rect); //GetWindowRect(hwnd_frame, &rect_frame_scr); //client_0_0.x = 0; //client_0_0.y=0; //ClientToScreen(hwnd_frame,&client_0_0); //client_0_0.y-= rect_frame_scr.top; //client_0_0.x-= rect_frame_scr.left; hdc = GetDC(NULL); DrawXorBar(hdc, oldx-SPLT_WIDTH/2, y, SPLT_WIDTH, line_height); ReleaseDC(NULL, hdc); we_sizing = 0; pt.x = oldx; ScreenToClient(hp,&pt); send_splitter_x(hp, pt.x); break; case WM_MOUSEMOVE: if(0==we_sizing) break; pt.x = (short)LOWORD(lParam); // horizontal position of cursor pt.y = (short)HIWORD(lParam); //GetClientRect(hwnd_frame,&rect); //GetClientRect(hwnd,&splt_rect); //SCreenToClient(rect); ClientToScreen(hwnd,&pt); //GetWindowRect(hwnd_frame, &rect_frame_scr); //client_0_0.x = 0; //client_0_0.y=0; //ClientToScreen(hwnd_frame,&client_0_0); //client_0_0.y-= rect_frame_scr.top; //client_0_0.x-= rect_frame_scr.left; //convert the mouse coordinates relative to the top-left of //the window //ScreenToClient(hwnd_frame,&pt); if(pt.x < min_left) pt.x = min_left; if(pt.x > max_right) { pt.x = max_right; } if(pt.x != oldx && wParam & MK_LBUTTON) { hdc = GetDC(NULL); DrawXorBar(hdc, oldx-SPLT_WIDTH/2, y, SPLT_WIDTH, line_height); DrawXorBar(hdc, pt.x-SPLT_WIDTH/2, y, SPLT_WIDTH, line_height); ReleaseDC(NULL, hdc); oldx = pt.x; } break; } return DefWindowProc (hwnd, message, wParam, lParam) ; }