#include "init.h" #include "globals.h" #include "util3d.h" #include "render.h" #include "light.h" #include "geom.h" #include "geom_menu.h" #include "disp_menu.h" #include "event.h" #include "image.h" #ifdef WIN32 // local variables HDC ghDC; HGLRC SetupGL() { static PIXELFORMATDESCRIPTOR pfd = { sizeof(PIXELFORMATDESCRIPTOR), // size of this pfd 1, // version number PFD_DRAW_TO_WINDOW // support window | PFD_SUPPORT_OPENGL // support OpenGL | PFD_DOUBLEBUFFER, // double buffered PFD_TYPE_RGBA, // RGBA type 32, // 32-bit color depth 0, 0, 0, 0, 0, 0, // color bits ignored 0, // no alpha buffer 0, // shift bit ignored 0, // no accumulation buffer 0, 0, 0, 0, // accum bits ignored 32, // 32-bit z-buffer 0, // no stencil buffer 0, // no auxiliary buffer PFD_MAIN_PLANE, // main layer 0, // reserved 0, 0, 0 // layer masks ignored }; int pixelFormat; HGLRC rv; pixelFormat = ChoosePixelFormat(ghDC, &pfd); if (pixelFormat) { if (SetPixelFormat(ghDC, pixelFormat, &pfd)) { rv = wglCreateContext(ghDC); if (rv) { if (!wglMakeCurrent(ghDC, rv)) { wglDeleteContext(rv); rv = 0; } } } } return rv; } #endif /* WIN32 */ void InitGL() { #ifdef WIN32 SetupGL(); #endif // backface culling glEnable(GL_CULL_FACE); glCullFace(GL_BACK); // polygon mode gstate.wire_frame = 0; glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); // zbuffer glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LEQUAL); glDepthRange(0.0, 1.0); // material glEnable(GL_COLOR_MATERIAL); // lighting make_ambient_light(0.1f, 0.1f, 0.1f, 0, 0); make_directional_light(0, 0.4f, 0.4f, 0.4f, 0.1f, 0.5f, 0.2f, -5.0f, 5.0f, 5.0f); make_directional_light(1, 0.1f, 0.1f, 0.1f, 0.1f, 0.5f, 0.2f, 5.0f, 0.0f, 0.0f); glEnable(GL_LIGHTING); // shading gstate.shading = 1; glShadeModel(GL_SMOOTH); // enable texture mapping gstate.texmap = 0; glDisable(GL_TEXTURE_2D); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glHint(GL_FASTEST, GL_POINT_SMOOTH_HINT); glHint(GL_NICEST, GL_LINE_SMOOTH_HINT); glHint(GL_DONT_CARE, GL_POLYGON_SMOOTH_HINT); glHint(GL_FASTEST, GL_PERSPECTIVE_CORRECTION_HINT); glDisable(GL_ALPHA_TEST); glDisable(GL_BLEND); glDisable(GL_FOG); glDisable(GL_LOGIC_OP); glDisable(GL_STENCIL_TEST); glDisable(GL_TEXTURE_1D); glPixelTransferi(GL_MAP_COLOR, GL_FALSE); glPixelTransferi(GL_RED_SCALE, 1); glPixelTransferi(GL_RED_BIAS, 0); glPixelTransferi(GL_GREEN_SCALE, 1); glPixelTransferi(GL_GREEN_BIAS, 0); glPixelTransferi(GL_BLUE_SCALE, 1); glPixelTransferi(GL_BLUE_BIAS, 0); glPixelTransferi(GL_ALPHA_SCALE, 1); glPixelTransferi(GL_ALPHA_BIAS, 0); glNewList(1, GL_COMPILE); gstate.num_polygons = geometry_display_list(); glEndList(); } void InitStates() { int str_len; gstate.num_polygons = 0; gstate.texmap = 0; gstate.wire_frame = 0; gstate.envmap = 0; gstate.xrot = gstate.yrot = gstate.zrot = 0.0f; gstate.dx = gstate.dy = gstate.dz = 0.0f; gstate.scale_factor = 1.0f; gstate.axis = '\0'; gstate.cop[X] = 0.0f; gstate.cop[Y] = 0.0f; gstate.cop[Z] = 8.0f; gstate.vrp[X] = 0.0f; gstate.vrp[Y] = 0.0f; gstate.vrp[Z] = 0.0f; gstate.nearCP = 0.01f; gstate.farCP = 100.0f; gstate.bg_r = gstate.bg_g = gstate.bg_b = 0; gstate.bg_on = 0; gstate.bg_sizeX = gstate.bg_sizeY = gstate.bg_sizeZ = 0; gstate.bg_data = NULL; gstate.auto_rotate = 0; gstate.yrot = 2.0f; gstate.auto_wobble = 0; gstate.wobble_steps = 60; gstate.wobble_step = 0; gstate.wobble_angle = 15.75f; gstate.frames = 0; str_len = strlen("Images/image.ppm"); gstate.tex_file = new char[str_len + 1]; strcpy(gstate.tex_file, "Images/marble2.ppm"); str_len = strlen("Images/sunset.rgb"); gstate.bg_file = new char[str_len + 1]; strcpy(gstate.bg_file, "Images/SculptStand.rgb"); if (LoadBackground(gstate.bg_file) == -1) { exit(0xdeadbeef); } } void InitEvent() { gevent.leftmouse_down = 0; gevent.rightmouse_down = 0; gevent.mpos1[X] = 0; gevent.mpos1[Y] = 0; gevent.mpos2[X] = 0; gevent.mpos2[Y] = 0; gevent.lastmpos[X] = 0; gevent.lastmpos[Y] = 0; gevent.mspeed = 0; } int InitTcl(Tcl_Interp *interp) { /* Initialize Tcl, Tk, and the Togl widget module. */ if (Tcl_Init(interp) == TCL_ERROR) { return TCL_ERROR; } if (Tk_Init(interp) == TCL_ERROR) { return TCL_ERROR; } if (Togl_Init(interp) == TCL_ERROR) { return TCL_ERROR; } /* * Specify the C callback functions for widget creation, display, * and reshape. */ Togl_CreateFunc(CreateCB); Togl_DisplayFunc(RenderCB); Togl_ReshapeFunc(ReshapeCB); Togl_TimerFunc(DynamicsCB); /* Make a new Togl widget command so the Tcl code can set a C variable. */ Togl_CreateCommand("ScherkBranches", ScherkBranchesCB); Togl_CreateCommand("ScherkStoreys", ScherkStoreysCB); Togl_CreateCommand("ScherkHeight", ScherkHeightCB); Togl_CreateCommand("ScherkFlange", ScherkFlangeCB); Togl_CreateCommand("ScherkThickness", ScherkThicknessCB); Togl_CreateCommand("ScherkRimBulge", ScherkRimBulgeCB); Togl_CreateCommand("ScherkAzimuth", ScherkAzimuthCB); Togl_CreateCommand("ScherkTwist", ScherkTwistCB); Togl_CreateCommand("ScherkWarp", ScherkWarpCB); Togl_CreateCommand("ScherkTexTiles", ScherkTexTilesCB); Togl_CreateCommand("ScherkDetail", ScherkDetailCB); Togl_CreateCommand("AutoRotate", AutoRotateCB); Togl_CreateCommand("AutoWobble", AutoWobbleCB); Togl_CreateCommand("WireFrame", WireFrameCB); Togl_CreateCommand("TexMap", TexMapCB); Togl_CreateCommand("EnvMap", EnvMapCB); Togl_CreateCommand("Background", BackgroundCB); Togl_CreateCommand("BackgroundColor", BackgroundColorCB); Togl_CreateCommand("MaterialColor", MaterialColorCB); Togl_CreateCommand("BackgroundFile", BackgroundFileCB); Togl_CreateCommand("TextureFile", TextureFileCB); Togl_CreateCommand("HandleButton", HandleButtonCB); Togl_CreateCommand("HandleMotion", HandleMotionCB); Togl_CreateCommand("StartOver", StartOverCB); Togl_CreateCommand("SaveSpec", SaveSpecCB); Togl_CreateCommand("LoadSpec", LoadSpecCB); /* * Specify a user-specific startup file to invoke if the application * is run interactively. Typically the startup file is "~/.apprc" * where "app" is the name of the application. If this line is deleted * then no user-specific startup file will be run under any conditions. */ #if (TCL_MAJOR_VERSION * 100 + TCL_MINOR_VERSION) >= 705 Tcl_SetVar( interp, "tcl_rcFileName", "./generator.tcl", TCL_GLOBAL_ONLY ); #else tcl_RcFileName = "./generator.tcl"; #endif return TCL_OK; }