void draw (int picking) { if(picking==2)return; gle(); glPushAttrib(GL_ALL_ATTRIB_BITS); gle(); if(!picking) { CameraUpdate (); gle(); EntityUpdate (); gle(); WorldUpdate (); gle(); TextureUpdate (); gle(); VisibleUpdate (); gle(); CarUpdate (); } gle(); RenderResize(); gle(); RenderUpdate (picking); resetviewport(); gle(); glPopAttrib(); gle(); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glMatrixMode(GL_MODELVIEW); }
void RenderLetterboxToggle () { letterbox = !letterbox; IniIntSet ("Letterbox", letterbox ? 1 : 0); RenderResize (); }
static void resize (int newWidth, int newHeight) { width = newWidth; height = newHeight; IniIntSet ("WindowWidth", width); IniIntSet ("WindowHeight", height); RenderResize (); }
void RenderInit (void) { HWND hWnd; unsigned PixelFormat; HFONT font; HFONT oldfont; hWnd = WinHwnd (); if (!(hDC = GetDC (hWnd))) YOUFAIL ("Can't Create A GL Device Context.") ; if (!(PixelFormat = ChoosePixelFormat(hDC,&pfd))) YOUFAIL ("Can't Find A Suitable PixelFormat.") ; if(!SetPixelFormat(hDC,PixelFormat,&pfd)) YOUFAIL ("Can't Set The PixelFormat."); if (!(hRC = wglCreateContext (hDC))) YOUFAIL ("Can't Create A GL Rendering Context."); if(!wglMakeCurrent(hDC,hRC)) YOUFAIL ("Can't Activate The GL Rendering Context."); //Load the fonts for printing debug info to the window. for (int i = 0; i < FONT_COUNT; i++) { fonts[i].base_char = glGenLists(96); font = CreateFont (FONT_SIZE, 0, 0, 0, FW_BOLD, FALSE, FALSE, FALSE, DEFAULT_CHARSET, OUT_TT_PRECIS, CLIP_DEFAULT_PRECIS, ANTIALIASED_QUALITY, FF_DONTCARE|DEFAULT_PITCH, fonts[i].name); oldfont = (HFONT)SelectObject(hDC, font); wglUseFontBitmaps(hDC, 32, 96, fonts[i].base_char); SelectObject(hDC, oldfont); DeleteObject(font); } //If the program is running for the first time, set the defaults. if (!IniInt ("SetDefaults")) { IniIntSet ("SetDefaults", 1); IniIntSet ("Effect", EFFECT_BLOOM); IniIntSet ("ShowFog", 1); } //load in our settings letterbox = IniInt ("Letterbox") != 0; show_wireframe = IniInt ("Wireframe") != 0; show_fps = IniInt ("ShowFPS") != 0; show_fog = IniInt ("ShowFog") != 0; effect = IniInt ("Effect"); flat = IniInt ("Flat") != 0; fog_distance = WORLD_HALF; //clear the viewport so the user isn't looking at trash while the program starts glViewport (0, 0, WinWidth (), WinHeight ()); glClearColor (0.0f, 0.0f, 0.0f, 1.0f); glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); SwapBuffers (hDC); RenderResize (); }
void CTexture::Rebuild() { int i, j; int x, y; int name_num, prefix_num, suffix_num; int max_size; float radius; GLvector2 pos; bool use_framebuffer; unsigned char* bits; unsigned start; int lapsed; start = GetTickCount(); //Since we make textures by drawing into the viewport, we can't make them bigger //than the current view. _size = _desired_size; max_size = RenderMaxTextureSize(); while (_size > max_size) _size /= 2; glBindTexture(GL_TEXTURE_2D, _glid); //Set up the texture glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, _size, _size, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); if (_clamp) { glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); } //Set up our viewport so that drawing into our texture will be as easy //as possible. We make the viewport and projection simply match the given //texture size. glViewport(0, 0, _size, _size); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0, _size, _size, 0, 0.1f, 2048); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); glDisable(GL_CULL_FACE); glDisable(GL_FOG); glBindTexture(GL_TEXTURE_2D, 0); glTranslatef(0, 0, -10.0f); glClearColor(0, 0, 0, _masked ? 0.0f : 1.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); use_framebuffer = true; glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); switch (_my_id) { case TEXTURE_LATTICE: glLineWidth(2.0f); glColor3f(0, 0, 0); glBegin(GL_LINES); glVertex2i(0, 0); glVertex2i(_size, _size); //diagonal glVertex2i(0, 0); glVertex2i(0, _size); //vertical glVertex2i(0, 0); glVertex2i(_size, 0); //vertical glEnd(); glBegin(GL_LINE_STRIP); glVertex2i(0, 0); for (i = 0; i < _size; i += 9) { if (i % 2) glVertex2i(0, i); else glVertex2i(i, i); } for (i = 0; i < _size; i += 9) { if (i % 2) glVertex2i(i, 0); else glVertex2i(i, i); } glEnd(); break; case TEXTURE_SOFT_CIRCLE: //Make a simple circle of light, bright in the center and fading out glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); radius = ((float)_half) - 3; glBegin(GL_TRIANGLE_FAN); glColor4f(1, 1, 1, 1); glVertex2i(_half, _half); glColor4f(0, 0, 0, 0); for (i = 0; i <= 360; i++) { pos.x = sinf((float)i * DEGREES_TO_RADIANS) * radius; pos.y = cosf((float)i * DEGREES_TO_RADIANS) * radius; glVertex2i(_half + (int)pos.x, _half + (int)pos.y); } glEnd(); break; case TEXTURE_LIGHT: glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); radius = ((float)_half) - 3; for (j = 0; j < 2; j++) { glBegin(GL_TRIANGLE_FAN); glColor4f(1, 1, 1, 1); glVertex2i(_half, _half); if (!j) radius = ((float)_half / 2); else radius = 8; glColor4f(1, 1, 1, 0); for (i = 0; i <= 360; i++) { pos.x = sinf((float)i * DEGREES_TO_RADIANS) * radius; pos.y = cosf((float)i * DEGREES_TO_RADIANS) * radius; glVertex2i(_half + (int)pos.x, _half + (int)pos.y); } glEnd(); } break; case TEXTURE_HEADLIGHT: DrawHeadlight(); break; case TEXTURE_LOGOS: i = 0; glDepthMask(false); glDisable(GL_BLEND); name_num = RandomVal(NAME_COUNT); prefix_num = RandomVal(PREFIX_COUNT); suffix_num = RandomVal(SUFFIX_COUNT); glColor3f(1, 1, 1); while (i < _size) { //randomly use a prefix OR suffix, but not both. Too verbose. if (COIN_FLIP) RenderPrint(2, _size - i - LOGO_PIXELS / 4, RandomVal(), glRgba(1.0f), "%s%s", prefix[prefix_num], name[name_num]); else RenderPrint(2, _size - i - LOGO_PIXELS / 4, RandomVal(), glRgba(1.0f), "%s%s", name[name_num], suffix[suffix_num]); name_num = (name_num + 1) % NAME_COUNT; prefix_num = (prefix_num + 1) % PREFIX_COUNT; suffix_num = (suffix_num + 1) % SUFFIX_COUNT; i += LOGO_PIXELS; } break; case TEXTURE_TRIM: int margin; y = 0; margin = MAX(TRIM_PIXELS / 4, 1); for (x = 0; x < _size; x += TRIM_PIXELS) drawrect_simple(x + margin, y + margin, x + TRIM_PIXELS - margin, y + TRIM_PIXELS - margin, glRgba(1.0f), glRgba(0.5f)); y += TRIM_PIXELS; for (x = 0; x < _size; x += TRIM_PIXELS * 2) drawrect_simple(x + margin, y + margin, x + TRIM_PIXELS - margin, y + TRIM_PIXELS - margin, glRgba(1.0f), glRgba(0.5f)); y += TRIM_PIXELS; for (x = 0; x < _size; x += TRIM_PIXELS * 3) drawrect_simple(x + margin, y + margin, x + TRIM_PIXELS - margin, y + TRIM_PIXELS - margin, glRgba(1.0f), glRgba(0.5f)); y += TRIM_PIXELS; for (x = 0; x < _size; x += TRIM_PIXELS) drawrect_simple(x + margin, y + margin * 2, x + TRIM_PIXELS - margin, y + TRIM_PIXELS - margin, glRgba(1.0f), glRgba(0.5f)); break; case TEXTURE_SKY: DrawSky(); break; default: //building textures DrawWindows(); break; } glPopMatrix(); //Now blit the finished image into our texture if (use_framebuffer) { glBindTexture(GL_TEXTURE_2D, _glid); glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 0, 0, _size, _size, 0); } if (_mipmap) { bits = (unsigned char*)malloc(_size * _size * 4); glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, bits); gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA, _size, _size, GL_RGBA, GL_UNSIGNED_BYTE, bits); free(bits); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); } else glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); //cleanup and restore the viewport RenderResize(); _ready = true; lapsed = GetTickCount() - start; build_time += lapsed; }
LONG WINAPI ScreenSaverProc(HWND hwnd_in,UINT message,WPARAM wparam,LPARAM lparam) { RECT r; int key; float delta_x, delta_y; POINT p; // Handles screen saver messages switch(message) { case WM_SIZE: width = LOWORD(lparam); // width of client area height = HIWORD(lparam); // height of client area if (wparam == SIZE_MAXIMIZED) { IniIntSet ("WindowMaximized", 1); } else { IniIntSet ("WindowWidth", width); IniIntSet ("WindowHeight", height); IniIntSet ("WindowMaximized", 0); } RenderResize (); break; case WM_KEYDOWN: key = (int) wparam; if (key == 'R') WorldReset (); else if (key == 'W') RenderWireframeToggle (); else if (key == 'E') RenderEffectCycle (); else if (key == 'L') RenderLetterboxToggle (); else if (key == 'F') RenderFPSToggle (); else if (key == 'G') RenderFogToggle (); else if (key == 'T') RenderFlatToggle (); else if (key == VK_F1) RenderHelpToggle (); else if (key == VK_ESCAPE) break; else if (!SCREENSAVER) { //Dev mode keys if (key == 'C') CameraAutoToggle (); if (key == 'B') CameraNextBehavior (); if (key == VK_F5) CameraReset (); if (key == VK_UP) CameraMedial (1.0f); if (key == VK_DOWN) CameraMedial (-1.0f); if (key == VK_LEFT) CameraLateral (1.0f); if (key == VK_RIGHT) CameraLateral (-1.0f); if (key == VK_PRIOR) CameraVertical (1.0f); if (key == VK_NEXT) CameraVertical (-1.0f); if (key == VK_F5) CameraReset (); return 0; } else break; return 0; case WM_MOVE: GetClientRect (hwnd, &r); height = r.bottom - r.top; width = r.right - r.left; IniIntSet ("WindowX", r.left); IniIntSet ("WindowY", r.top); IniIntSet ("WindowWidth", width); IniIntSet ("WindowHeight", height); half_width = width / 2; half_height = height / 2; return 0; case WM_LBUTTONDOWN: lmb = true; SetCapture (hwnd); break; case WM_RBUTTONDOWN: rmb = true; SetCapture (hwnd); break; case WM_LBUTTONUP: lmb = false; if (!rmb) { ReleaseCapture (); MoveCursor (select_pos.x, select_pos.y); } break; case WM_RBUTTONUP: rmb = false; if (!lmb) { ReleaseCapture (); MoveCursor (select_pos.x, select_pos.y); } break; case WM_MOUSEMOVE: p.x = LOWORD(lparam); // horizontal position of cursor p.y = HIWORD(lparam); // vertical position of cursor if (p.x < 0 || p.x > width) break; if (p.y < 0 || p.y > height) break; if (!mouse_forced && !lmb && !rmb) { select_pos = p; } if (mouse_forced) { mouse_forced = false; } else if (rmb || lmb) { CenterCursor (); delta_x = (float)(mouse_pos.x - p.x) * MOUSE_MOVEMENT; delta_y = (float)(mouse_pos.y - p.y) * MOUSE_MOVEMENT; if (rmb && lmb) { GLvector pos; CameraPan (delta_x); pos = CameraPosition (); pos.y += delta_y; CameraPositionSet (pos); } else if (rmb) { CameraPan (delta_x); CameraForward (delta_y); } else if (lmb) { GLvector angle; angle = CameraAngle (); angle.y -= delta_x; angle.x += delta_y; CameraAngleSet (angle); } } mouse_pos = p; break; case WM_CREATE: hwnd = hwnd_in; if (SCREENSAVER) AppInit (); SetTimer (hwnd, 1, 7, NULL); return 0; case WM_TIMER: AppUpdate (); return 0; case WM_DESTROY: PostQuitMessage(0); return 0; } #if SCREENSAVER return DefScreenSaverProc(hwnd_in,message,wparam,lparam); #else return DefWindowProc (hwnd_in,message,wparam,lparam); #endif }