int main(int argc, char **argv) { Poly *l, *p, *q = poly_alloc(3); Hpoly *t = hpoly_alloc(3); Item *i; init_sdl(); s = scene_read(); init_render(); for (o = s->objs; o != NULL; o = o->next) { for (l = prim_uv_decomp(o->u.prim, 1.); l != NULL; l = l->next) { p = poly_transform(prim_polys(o->u.prim, l), mclip); if (!is_backfacing(p, v3_unit(v3_scale(-1, poly_centr(p))))) hither_clip(0, p, z_store, plist_free); } } z = z_sort(z); for (i = z->head; i != NULL; i = i->next) { t = hpoly_polyxform(t, S(i), mdpy); q = poly_wz_hpoly(q, W(i), t); texture_wscale(W(i), T(i)); scan_spoly3(q, 2, texture_shadepaint, texture_set(td,W(i),T(i),P(i),N(i),DU(i),DV(i),rc,M(i))); } img_write(s->img, "stdout", 0); exit(0); }
int main(int argc, char **argv) { Poly *l, *p, *c = poly_alloc(3); Item *i; init_sdl(); s = scene_read(); init_render(); for (o = s->objs; o != NULL; o = o->next) { for (l = prim_uv_decomp(o->u.prim, 1.); l != NULL; l = l->next) { p = poly_transform(prim_polys(o->u.prim, l), mclip); if (!is_backfacing(p, v3_unit(v3_scale(-1, poly_centr(p))))) hither_clip(VIEW_ZMIN(s->view), p, z_store, plist_free); } } z = z_sort(z); for (i = z->head; i != NULL; i = i->next) { gouraud_shade(c, P(i), N(i), s->view->center, rc, M(i)); p = poly_homoxform(S(i),mdpy); scan_poly(p, gouraud_paint, gouraud_set(g,c,s->img)); } img_write(s->img, "stdout", 0); exit(0); }
main(int argc, char **argv) { Prim *o; Color c; int u, v; Ray r; Inode *l; o = sphere_instance(&sphere_funcs); init_sdl(); s = scene_read(); init_render(); for (v = s->view->sc.ll.y; v < s->view->sc.ur.y; v += 1) { for (u = s->view->sc.ll.x; u < s->view->sc.ur.x; u += 1) { r = ray_unit(ray_transform(ray_view(u, v), mclip)); if ((l = ray_intersect(s->objs, r)) != NULL) c = point_tshade(ray_point(r, l->t), l->n, s->view->center, rc, l->m, o); else c = bgcolor; inode_free(l); img_putc(s->img, u, v, col_dpymap(c)); } } img_write(s->img,"stdout",0); exit(0); }
void main (int argc, char** argv) { glutInit(&argc,argv); //GLUT initialization glutInitDisplayMode (GLUT_DOUBLE| GLUT_RGB | GLUT_DEPTH ); glClear(GL_DEPTH_BUFFER_BIT); glEnable(GL_DEPTH_TEST); glutInitWindowPosition(50,100); //set top-left display-window position glutInitWindowSize(400,300); //set display-window width and height glutCreateWindow("Mini Project by TANG Xiaowu");//create the display window ////////////////////////////////////////////////////////////////// // // Register mouse-click and mouse-move glut callback functions // for the rotation user-interface. // //glutMouseFunc( gsrc_mousebutton ); //glutMotionFunc( gsrc_mousemove ); // ////////////////////////////////////////////////////////////////// init_render(); //initialize the lighting init(); //initialize the objects and load textures glutDisplayFunc (drawscene); //display the scene glutTimerFunc(40,move,0); //a timer function which is used for animation glutMainLoop (); }
int init_engine(SDL_GLContext *context, SDL_Window *window) { int img_flags = IMG_INIT_PNG; if (!(IMG_Init(img_flags) & img_flags)) { printf("SD_image could not initialize! SDL_image Error: %s\n", IMG_GetError()); return -1; } if (init_gl(context, window)) return -1; if (init_glew()) return -1; // if (init_effects(shader_programs, shader_infos, LENGTH(shader_programs))) { // printf("Something went wrong with shader program initialization!\n"); // return -1; // } load_effects( effects.all, LENGTH(effects.all), shader_file_paths, LENGTH(shader_file_paths), attribute_strings, LENGTH(attribute_strings), uniform_strings, LENGTH(uniform_strings)); open_simplex_noise(open_simplex_noise_seed, &osnctx); SDL_GameControllerEventState(SDL_ENABLE); /* Open the first available controller. */ SDL_GameController *controller = NULL; for (int i = 0; i < SDL_NumJoysticks(); ++i) { printf("Testing controller %i\n", i); if (SDL_IsGameController(i)) { controller = SDL_GameControllerOpen(i); if (controller) { printf("Successfully opened controller %i\n", i); break; } else { printf("Could not open gamecontroller %i: %s\n", i, SDL_GetError()); } } else { printf("Controller %i is not a controller?\n", i); } } init_keyboard(); init_render(); //Located in render.c if (signal(SIGUSR1, reload_signal_handler) == SIG_ERR) { printf("An error occurred while setting a signal handler.\n"); } return 0; }
void reload_effects_void_wrapper() { // if (!reload_effects(shader_programs, shader_infos, LENGTH(shader_programs))) { // deinit_render(); // init_render(); // } load_effects( effects.all, LENGTH(effects.all), shader_file_paths, LENGTH(shader_file_paths), attribute_strings, LENGTH(attribute_strings), uniform_strings, LENGTH(uniform_strings)); deinit_render(); init_render(); }
main(int argc, char **argv) { Color c; int u, v; Ray r; init_sdl(); s = scene_read(); init_render(); for (v = s->view->sc.ll.y; v < s->view->sc.ur.y; v += 1) { for (u = s->view->sc.ll.x; u < s->view->sc.ur.x; u += 1) { r = ray_unit(ray_transform(ray_view(u, v), mclip)); c = ray_shade(0, 1., r, rc, s->objs); img_putc(s->img, u, v, col_dpymap(c)); } } img_write(s->img,"stdout",0); exit(0); }
//////////////////////////////////////////////////////////////////////// // WndProc - "Window procedure" function LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { switch(message) { case WM_CREATE: { // As soon as the window is first created, create // the back buffer. init_render(window_width, window_height); InitBackBuffer() ; return 0; } break; case WM_PAINT: { PAINTSTRUCT ps; HDC winhdc = BeginPaint(hwnd, &ps); // Do nothing here. All drawing happens in draw(), // and you draw to the backbuffer, NOT the // front buffer. EndPaint(hwnd, &ps); return 0; } break; case WM_DESTROY: { PostQuitMessage(0); return 0; } break; } // If message was NOT handled by us, we pass it off to // the windows operating system to handle it. return DefWindowProc(hwnd, message, wParam, lParam); }
bool is_window_created() { bool success = true; if (SDL_Init(SDL_INIT_VIDEO) < 0) { printf("is_window_created: err %s\n", SDL_GetError()); success = false; } else { // Set texture filtering to linear if ( !SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "1") ) { printf("is_window_created: Warning: Linear texture filtering not enabled!"); } g_window = SDL_CreateWindow( "sdl mouse", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN); if ( !g_window ) { printf("is_window_created: err %s\n", SDL_GetError()); success = false; } else { success = init_render(); } } /* end init */ return success; }
void init() { sigset_t sigmask; sigemptyset(&sigmask); sigaddset(&sigmask, SIGALRM); sigaddset(&sigmask, SIGUSR1); sigprocmask(SIG_BLOCK, &sigmask, NULL); console_print("Emergence Client " VERSION "\n"); SDL_Init(SDL_INIT_AUDIO); init_user(); init_network(); init_timer(); init_openssl(); init_key(); init_download(); init_servers(); create_cvars(); init_console_cvars(); init_render_cvars(); init_map_cvars(); create_control_cvars(); // create_input_cvars(); init_tick_cvars(); init_console(); create_colour_cvars(); struct string_t *string = new_string_string(emergence_home_dir); string_cat_text(string, "/client.config"); if(!exec_config_file(string->text)) { exec_config_file(find_resource("default-controls.config")); } else { char *ver = get_cvar_string("version"); if(*ver == '\0') { struct string_t *command = new_string_text("rm "); string_cat_string(command, emergence_home_dir); string_cat_text(command, "/skins/default.skin*"); console_print("%s\n", command->text); system(command->text); vid_mode = -1; // find a nice mode exec_config_file(find_resource("default-controls.config")); } free(ver); } free_string(string); set_cvar_string("version", VERSION); init_skin(); init_input(); init_control(); init_render(); init_rcon(); init_ping(); create_cvar_command("quit", client_shutdown_char); init_sound(); init_game(); init_alarm(); render_frame(); string = new_string_text("%s%s", emergence_home_dir->text, "/client.autoexec"); if(!exec_config_file(string->text)) exec_config_file(find_resource("default-client.autoexec")); free_string(string); start_server_discovery(); }
// Just as said every C++ program starts at main, // // every Windows program will start at WinMain. // ///////////////////////////////////////////////////////////////// int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd ) { #pragma region get window up WNDCLASSEX window = { 0 } ; window.cbSize = sizeof(WNDCLASSEX); window.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH); // BLACK_BRUSH, DKGRAY_BRUSH window.hCursor = LoadCursor(NULL, IDC_ARROW); // load hand cursor.. make to guitar window.hIcon = LoadIcon(NULL, IDI_APPLICATION); // large icon for app window.hIconSm = LoadIcon(NULL, IDI_APPLICATION); // small icon that shows up in top left of window window.hInstance = hInstance; // program's instance handle that was first passed to WinMain by windows when program was first run window.lpfnWndProc = WndProc; // function pointer to WndProc function window.lpszClassName = win_name; // window class name window.lpszMenuName = NULL; // menu name -- but our app has no menu now window.style = CS_HREDRAW | CS_VREDRAW; // window style -- if(!RegisterClassEx( &window )) { MessageBox(NULL, TEXT("Something's wrong with the WNDCLASSEX structure you defined.. quitting"), TEXT("Error"), MB_OK); return 1; // return from WinMain.. i.e. quit } // CREATE THE WINDOW AND KEEP THE HANDLE TO IT. winhwnd = CreateWindowEx( 0/*WS_EX_TOPMOST*/, // extended window style.. this sets the window to being always on top win_name, // window class name.. defined above TEXT("Water"),// title bar of window WS_OVERLAPPEDWINDOW,// window style 400, 200, // initial x, y start position of window window_width, window_height, // initial width, height of window. Can also be CW_USEDEFAULT to let Windows choose these values NULL, NULL, // parent window, window menu hInstance, NULL); // program instance handle, creation params // now we show and paint our window, so it appears ShowWindow( winhwnd, nShowCmd ); // you have to ask that your Window be shown to see it UpdateWindow(winhwnd); // paint the window #pragma endregion #pragma region message loop MSG msg; init_render(window_width, window_height); //show some text HDC winhdc = GetDC(winhwnd); char buffer[128]; sprintf(buffer, "Rendering..."); TextOutA(winhdc, window_width/2 - 50, window_height/2 - 20, buffer, strlen(buffer)); while(1) { if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { if(msg.message == WM_QUIT) { PostQuitMessage(0); break; } TranslateMessage(&msg); // translates 'character' keyboard messages DispatchMessage(&msg); // send off to WndProc for processing } else { // could put more update code in here // before drawing. draw(); } } #pragma endregion return 0; // end program once we exit the message loop }
int main(int argc, char ** argv) { if (argc < 2) return 0; if (argv[1][0] == '-' && argv[1][1] == 'e') { set_emacs_mode(1); register_render_commands(); register_empic_commands(); start_read_commands(); argv += 1; argc -= 1; } if (SDL_Init(SDL_INIT_VIDEO) < 0) { SDL_Log("Couldn't init: %s\n", SDL_GetError()); cleanup_and_quit(); return 1; } if (!create_window()) { SDL_Log("Couldn't create window: %s\n", SDL_GetError()); cleanup_and_quit(); return 2; } if (!init_render()) { cleanup_and_quit(); return 3; } files_list.names = argv + 1; files_list.size = argc - 1; load_next_image(); if (files_list.current < 0) { cleanup_and_quit(); return 4; } /* Simulate keydown for ZOOM_FIT_BIG */ SDL_Event key; key.type = SDL_KEYDOWN; key.key.keysym.sym = SDLK_0; key.key.keysym.scancode = SDL_SCANCODE_0; SDL_PushEvent(&key); key.key.keysym.sym = SDLK_KP_0; key.key.keysym.scancode = SDL_SCANCODE_KP_0; SDL_PushEvent(&key); while (!quit) { if (!render()) { cleanup_and_quit(); return 5; } wait_event(); } cleanup_and_quit(); return 0; }
bool is_window_created() { bool success = true; // if (SDL_Init(SDL_INIT_VIDEO) < 0) // if ( SDL_Init( SDL_INIT_VIDEO | SDL_INIT_JOYSTICK ) < 0 ) if ( SDL_Init( SDL_INIT_VIDEO | SDL_INIT_AUDIO ) < 0 ) { printf("is_window_created: err %s\n", SDL_GetError()); success = false; } else { // Set texture filtering to linear if ( !SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "1") ) { printf("is_window_created: Warning: Linear texture filtering not enabled!"); } // http://wiki.libsdl.org/SDL_NumJoysticks // if ( SDL_NumJoysticks() < 1 ) // { // printf("is_window_created: no joystick connected\n"); // } // else // load joystick // { // // http://wiki.libsdl.org/SDL_JoystickOpen // g_gamepad = SDL_JoystickOpen(0); // // if ( !g_gamepad ) // { // printf("is_window_created: joystick err: %s\n", SDL_GetError()); // } // else // { // printf("Opened Joystick 0\n"); // printf("Name: %s\n", SDL_JoystickNameForIndex(0)); // printf("Number of Axes: %d\n", SDL_JoystickNumAxes(g_gamepad)); // printf("Number of Buttons: %d\n", SDL_JoystickNumButtons(g_gamepad)); // printf("Number of Balls: %d\n", SDL_JoystickNumBalls(g_gamepad)); // } // } g_window = SDL_CreateWindow( "sdl mouse", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN); if ( !g_window ) { printf("is_window_created: err %s\n", SDL_GetError()); success = false; } else { success = init_render(); } } /* end init */ return success; }