int main(int argc, char * argv[]) { glutInit(&argc , argv); glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE); glutInitWindowPosition(0 , 0); glutInitWindowSize(window_width, window_height); glutCreateWindow("Warp"); glutDisplayFunc(DisplayFunc); glutTimerFunc(1000 / 60, TimerFunc, 1000 / 60); glutReshapeFunc(ReshapeFunc); glutSpecialFunc(SpecialFunc); glutKeyboardFunc(KeyboardFunc); glutMouseFunc(MouseFunc); glutMotionFunc(MotionFunc); glutCloseFunc(CloseFunc); glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE, GLUT_ACTION_CONTINUE_EXECUTION); glEnable(GL_DEPTH_TEST); ilInit(); iluInit(); ilutInit(); ilutRenderer(ILUT_OPENGL); if (glewInit() != GLEW_OK) { cerr << "GLEW failed to initialize." << endl; return 0; } if (!shader.Initialize("stub.vert", "stub.frag")) { return 0; } if (!background.Initialize("back.vert", "back.frag")) { return 0; } image_1_handle = ilutGLLoadImage("lotr-scene.jpg"); image_1_w = ilGetInteger(IL_IMAGE_WIDTH); image_1_h = ilGetInteger(IL_IMAGE_HEIGHT); tex_handle = ilutGLLoadImage("Home-Theater.jpg"); tex_w = ilGetInteger(IL_IMAGE_WIDTH); tex_h = ilGetInteger(IL_IMAGE_HEIGHT); left_overlay_handle = ilutGLLoadImage("left-over.jpg"); right_overlay_handle = ilutGLLoadImage("right-over.jpg"); left_curtain_handle = ilutGLLoadImage("left-curtain.jpg"); cout << "Image 1: " << image_1_w << " x " << image_1_h << endl; cout << "Background: " << tex_w << " x " << tex_h << endl; if (!frame.Initialize(glm::ivec2(image_1_w, image_1_h), 1, true)) { cerr << "Frame buffer 1 failed to initialize." << endl; return 0; } cout << "Window Size: " << window_width << " x " << window_height << endl; cout << "Frame buffer 1 size: " << frame.size.x << " x " << frame.size.y << endl; glutMainLoop(); return 0; }
void ilOgl::Init() { ilutRenderer(ILUT_OPENGL); return; }
int main(int argc, char **argv) { if (argc != 2) { cout << "No configuration file" << endl; system("pause"); return 1; } ilInit(); iluInit(); ilEnable(IL_FILE_OVERWRITE); ilutRenderer(ILUT_OPENGL); glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH); glutInitWindowSize(640, 480); glutInitWindowPosition(100, 100); glutCreateWindow("JelloSim by AlineN"); glutDisplayFunc(onDrawCb); glutKeyboardFunc(onKeyboardCb); glutSpecialFunc(onKeyboardSpecialCb); glutMouseFunc(onMouseCb); glutMotionFunc(onMouseMotionCb); glutTimerFunc(100, onTimerCb, 0); glutReshapeFunc(onResizeCb); int intMenu = glutCreateMenu(onMenuCb); glutAddMenuEntry("Euler\t'8'", '8'); glutAddMenuEntry("Midpoint\t'9'", '9'); glutAddMenuEntry("RK4\t'0'", '0'); int displayMenu = glutCreateMenu(onMenuCb); glutAddMenuEntry("Mesh\t'1'", '1'); glutAddMenuEntry("Forces\t'2'", '2'); glutAddMenuEntry("Collision Normals\t'3'", '3'); glutAddMenuEntry("Structural Springs\t'4'", '4'); glutAddMenuEntry("Shear Springs\t'5'", '5'); glutAddMenuEntry("Bend Springs\t'6'", '6'); theMenu = glutCreateMenu(onMenuCb); glutAddMenuEntry("Start\t'>'", '>'); glutAddMenuEntry("Pause\t'='", '='); glutAddMenuEntry("Reset\t'<'", '<'); glutAddMenuEntry("Record\t'r'", 'r'); glutAddSubMenu("Integration Type", intMenu); glutAddSubMenu("Draw Settings", displayMenu); glutAddMenuEntry("_________________", -1); glutAddMenuEntry("Exit", 27); glutAttachMenu(GLUT_RIGHT_BUTTON); init(); if (loadJelloParameters(argv[1]) != 0) { cout << "Failed to open configuration file" << endl; system("pause"); return 1; } glutMainLoop(); return 0; }
void EditorUI::Initialize () { optimizeOnLoad=true; archives.Load (); ilInit (); ilutInit(); ilutRenderer(ILUT_OPENGL); callback.ui = this; new BackupManager(&callback); objectViewer = new ObjectView (this, objectTree); uiIK = new IK_UI (&callback); uiTimeline = new TimelineUI (&callback); uiAnimTrackEditor = new AnimTrackEditorUI (&callback, uiTimeline); uiRotator = new RotatorUI; uiRotator->CreateUI(&callback); uiBackupViewer = new BackupViewerUI(&callback); tools.SetEditor (&callback); tools.camera->button = selectCameraTool; tools.move->button = selectMoveTool; tools.rotate->button = selectRotateTool; tools.scale->button = selectScaleTool; tools.texmap->button = selectTextureTool; tools.color->button = selectColorTool; tools.flip->button = selectFlipTool; tools.originMove->button = selectOriginMoveTool; tools.rotateTex->button = selectRotateTexTool; tools.toggleCurvedPoly->button = selectCurvedPolyTool; tools.LoadImages(); currentTool = tools.GetDefaultTool (); modelDrawer = new ModelDrawer; model = 0; SetModel (new Model); UpdateTitle(); textureHandler = new TextureHandler (); for (set<string>::iterator arch=archives.archives.begin();arch!=archives.archives.end();++arch) textureHandler->Load (arch->c_str()); textureGroupHandler = new TextureGroupHandler (textureHandler); textureGroupHandler->Load ((applicationPath + TextureGroupConfig).c_str()); UpdateTextureGroups(); InitTexBrowser(); uiMapping = new MappingUI (&callback); uiTexBuilder = new TexBuilderUI (0,0); LoadSettings(); // create 4 views if no views were specified in the config (ie: there was no config) if (!viewsGroup->children()) { viewsGroup->begin(); EditorViewWindow *views[4]; int vw = viewsGroup->w (); int vh = viewsGroup->h (); for (int a=0;a<4;a++) { int Xofs=(a&1)*vw/2; int Yofs=(a&2)*vh/4; int W=vw/2; int H=vh/2; if (Xofs) W = vw-Xofs; if (Yofs) H = vh-Yofs; views[a]=new EditorViewWindow (Xofs, Yofs, W,H, &callback); views[a]->SetMode(a); views[a]->bDrawRadius = false; } views[3]->rendermode = M3D_TEX; viewsGroup->end(); } BACKUP_POINT("New model"); }
int TextureControl::InitImageLibrary() { ilInit(); iluInit(); ilutRenderer(ILUT_WIN32); return 0; }
int main() { if (!glfwInit()) exit(EXIT_FAILURE); if (!glfwOpenWindow(screenWidth, screenHeight, 0, 0, 0, 0, 0, 0, GLFW_WINDOW)) { glfwTerminate(); exit(EXIT_FAILURE); } glfwSetWindowTitle("Example Program: Craig McMillan 10004794 "); GLenum error = glewInit(); if (error != GLEW_OK) { std::cout << "Error: " << glewGetErrorString(error) <<std::endl; exit(EXIT_FAILURE); } const GLubyte* renderer = glGetString(GL_RENDERER); const GLubyte* vendor = glGetString(GL_VENDOR); const GLubyte* version = glGetString(GL_VERSION); const GLubyte* glslVersion = glGetString(GL_SHADING_LANGUAGE_VERSION); GLint major , minor; glGetIntegerv(GL_MAJOR_VERSION, &major); glGetIntegerv(GL_MINOR_VERSION, &minor); printf("GL VENDOR : %s\n", vendor); printf("GL Renderer : %s\n", renderer); printf("GL Version (string) : %s\n", version); printf("GL Version (integer) : %d.%d\n", major, minor); printf("GLSL version : %s\n", glslVersion); ilInit(); iluInit(); ilutRenderer(ILUT_OPENGL); initialise(); double prevTimeStamp = glfwGetTime(); double lastFPS = glfwGetTime(); double currentTimeStamp; int nbFrames = 0; while (running) { currentTimeStamp = glfwGetTime(); //calculate frame rate nbFrames++; update(currentTimeStamp - prevTimeStamp); if (currentTimeStamp - lastFPS >= 1.0) { printf("%f ms/frame\n", double(nbFrames)); nbFrames = 0; lastFPS += 1.0; } render(); prevTimeStamp = currentTimeStamp; } cleanup(); glfwTerminate(); exit(EXIT_SUCCESS); }
int APIENTRY WinMain(HINSTANCE hInst, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { MSG msg; WNDCLASSEX wcex; HACCEL hAccelTable; hInstance = hInst; memset(OpenFileName, 0, 2048 * sizeof(TCHAR)); BackBrush = CreateSolidBrush(RGB(128,128,128)); wcex.cbSize = sizeof(WNDCLASSEX); wcex.style = CS_HREDRAW | CS_VREDRAW; wcex.lpfnWndProc = (WNDPROC)WndProc; wcex.cbClsExtra = 0; wcex.cbWndExtra = 0; wcex.hInstance = hInstance; wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON1)); wcex.hCursor = LoadCursor(NULL, IDC_ARROW); wcex.hbrBackground = BackBrush; wcex.lpszMenuName = (LPCWSTR)IDR_MENU1; //@TODO: (LPCSTR)IDR_MENU1; wcex.lpszClassName = TITLE; wcex.hIconSm = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_ICON1); RegisterClassEx(&wcex); HWnd = CreateWindow(TITLE, TITLE, WS_OVERLAPPEDWINDOW | WS_VISIBLE, 50, 50, 400, 300, NULL, NULL, hInstance, NULL); if (HWnd == NULL) return FALSE; //if (SDL_Init(SDL_INIT_TIMER) < 0) // return FALSE; //atexit(SDL_Quit); // Display the window ShowWindow(HWnd, nCmdShow); UpdateWindow(HWnd); // Initialize DevIL ilInit(); iluInit(); ilutRenderer(ILUT_WIN32); // Is there a file to load from the command-line? if (__argc > 1) { ilGenImages(1, Undos); ilBindImage(Undos[0]); /*if (ilLoadImage(__argv[1])) { CurImage = 0; //ilConvertImage(IL_BGRA); ilutRenderer(ILUT_WIN32); ResizeWin(); CreateGDI(); sprintf(NewTitle, "%s - %s", TITLE, __argv[1]); SetWindowText(HWnd, NewTitle); }*/ } hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDR_MENU1); while (GetMessage(&msg, NULL, 0, 0)) { if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) { TranslateMessage(&msg); DispatchMessage(&msg); } } #ifdef _DEBUG _CrtDumpMemoryLeaks(); #endif return (int)msg.wParam; }
// Window procedure, handles all messages for this program LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { static HMENU hMenu; static ILuint Colours; static RECT Rect; static PAINTSTRUCT ps; static HDROP hDrop; static TCHAR OpenFilter[2048]; static TCHAR SaveFilter[2048]; static TCHAR *OFilter[] = { L"All Files (*.*)", L"*.*", L"Alias|Wavefront Files (*.pix)", L"*.pix", L"Cut Files (*.cut)", L"*.cut", L"Dcx Files (*.dcx)", L"*.dcx", L"Graphics Interchange Format (*.gif)", L"*.gif", L"Half-Life Model Files (*.mdl)", L"*.mdl", L"Homeworld Image Files (*.lif)", L"*.lif", L"Image Files (All Supported Types)", L"*.jpe;*.jpg;*.jpeg;*.lif;*.bmp;*.ico;*.pbm;*.pgm;*.pnm;*.ppm;*.png;*.bw;*.rgb;*.rgba;*.sgi;*.tga;*.tif;*.tiff;*.pcx;*.xpm;*.psp;*.psd;*.pix;*.pxr;*.cut;*.dcx", L"Jpeg Files (*.jpe, *.jpg, *.jpeg)", L"*.jpe;*.jpg;*.jpeg", L"Kodak Photo CD Files (*.pcd)", L"*.pcd", L"Microsoft Bitmap Files (*.bmp)", L"*.bmp", L"Microsoft DirectDraw Surface (*.dds)", L"*.dds", L"Microsoft Icon Files (*.ico, *.cur)", L"*.ico, *.cur", L"Multiple Network Graphics Files (*.mng)", L"*.mng", L"Paint Shop Pro Files (*.psp)", L"*.psp", L"PhotoShop Files (*.psd)", L"*.psd", L"Pic Files (*.pic)", L"*.pic", L"Pixar Files (*.pix)", L"*.pix", L"Portable AnyMap Files (*.pbm, *.pgm, *.pnm, *.ppm)", L"*.pbm;*.pgm;*.pnm;*.ppm", L"Portable Network Graphics Files (*.png)", L"*.png", L"Sgi Files (*.sgi)", L"*.bw;*.rgb;*.rgba;*.sgi", L"Targa Files (*.tga, *.vda, *.icb, *.vst)", L"*.tga;*.vda;*.icb;*.vst", L"Tiff Files (*.tif)", L"*.tif;*.tiff", L"Valve Texture Files (*.vtf)", L"*.vtf", L"Quake Wal Files (*.wal)", L"*.wal", L"X PixelMap (*.xpm)", L"*.xpm", L"ZSoft Pcx Files (*.pcx)", L"*.pcx", L"\0\0" }; static TCHAR *SFilter[] = { L"All Files (*.*)", L"*.*", L"C-Style Header (*.h)", L"*.h", L"Jpeg Files (*.jpe, *.jpg, *.jpeg)", L"*.jpe;*.jpg;*.jpeg", L"Microsoft Bitmap Files (*.bmp)", L"*.bmp", L"Microsoft DirectDraw Surface (*.dds)", L"*.dds", L"PhotoShop Files (*.psd)", L"*.psd", L"Portable AnyMap Files (*.pbm, *.pgm, *.ppm)", L"*.pbm;*.pgm;*.ppm", L"Portable Network Graphics Files (*.png)", L"*.png", L"Sgi Files (*.sgi)", L"*.bw;*.rgb;*.rgba;*.sgi", L"Targa Files (*.tga)", L"*.tga", L"Tiff Files (*.tif)", L"*.tif", L"ZSoft Pcx Files (*.pcx)", L"*.pcx", L"\0\0" }; static OPENFILENAME Ofn = { sizeof(OPENFILENAME), hWnd, NULL, OpenFilter, NULL, 0, 0, OpenFileName, 2048, NULL, 0, NULL, NULL, OFN_HIDEREADONLY | OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST, 0, 0, NULL, NULL, NULL, NULL }; POINT CurMouse; static POINT PrevMouse; static ILboolean MouseDown = IL_FALSE; static RECT WinSize; unsigned int currentColor = 0x80000000; unsigned int originalColor = 0x80000000; bool userClickedOK; ILclampf Red = 255, Green = 255, Blue = 255; ILubyte *AlphaChannel; ILenum Origin; switch (message) { case WM_CREATE: GenFilterString(OpenFilter, OFilter); GenFilterString(SaveFilter, SFilter); hDC = GetDC(hWnd); DragAcceptFiles(hWnd, TRUE); ReleaseDC(hWnd, hDC); break; case WM_CLOSE: #ifdef _DEBUG _CrtDumpMemoryLeaks(); #endif DestroyGDI(); DestroyWindow(hWnd); UnregisterClass(TITLE, hInstance); break; case WM_DESTROY: PostQuitMessage(0); break; case WM_PAINT: GetWindowRect(HWnd, &WinSize); // Shouldn't be here! hDC = BeginPaint(hWnd, &ps); //StretchBlt(hDC, 0, 0, WinSize.right - WinSize.left, // WinSize.bottom - WinSize.top, BackHDC, 0, 0, 1, 1, SRCCOPY); WinSize.right -= WinSize.left; WinSize.bottom -= WinSize.top; WinSize.top = 0; WinSize.left = 0; FillRect(hDC, &WinSize, BackBrush); BitBlt(hDC, XOff, YOff, (WORD)BmpInfo.biWidth, (WORD)BmpInfo.biHeight, hMemDC, 0, 0, SRCCOPY); EndPaint(hWnd, &ps); ValidateRect(hWnd, NULL); break; case WM_KEYDOWN: if (wParam == VK_ESCAPE) PostQuitMessage(0); // View the next image in the animation chain. if (wParam == VK_RIGHT) { ilBindImage(Undos[0]); // @TODO: Implement undos better with this. CurImage++; if (CurImage > ilGetInteger(IL_NUM_IMAGES)) CurImage = 0; // Go back to the beginning of the animation. ilActiveImage(CurImage); ilutRenderer(ILUT_WIN32); ResizeWin(); CreateGDI(); } if (wParam == '0') { ilBindImage(Undos[0]); // @TODO: Implement undos better with this. ilutRenderer(ILUT_WIN32); ResizeWin(); CreateGDI(); } if (wParam == '1') { ilActiveMipmap(1); ilutRenderer(ILUT_WIN32); ResizeWin(); CreateGDI(); } else if (wParam == '2') { ilActiveMipmap(2); ilutRenderer(ILUT_WIN32); ResizeWin(); CreateGDI(); } else if (wParam == '3') { ilActiveMipmap(3); ilutRenderer(ILUT_WIN32); ResizeWin(); CreateGDI(); } else if (wParam == '4') { ilActiveMipmap(4); ilutRenderer(ILUT_WIN32); ResizeWin(); CreateGDI(); } else if (wParam == '5') { ilActiveMipmap(5); ilutRenderer(ILUT_WIN32); ResizeWin(); CreateGDI(); } else if (wParam == '6') { ilActiveMipmap(6); ilutRenderer(ILUT_WIN32); ResizeWin(); CreateGDI(); } else if (wParam == '7') { ilActiveMipmap(7); ilutRenderer(ILUT_WIN32); ResizeWin(); CreateGDI(); } else if (wParam == '8') { ilActiveMipmap(8); ilutRenderer(ILUT_WIN32); ResizeWin(); CreateGDI(); } else if (wParam == '9') { ilActiveMipmap(9); ilutRenderer(ILUT_WIN32); ResizeWin(); CreateGDI(); } // View the previous image in the animation chain. if (wParam == VK_LEFT) { ilBindImage(Undos[0]); // @TODO: Implement undos better with this. CurImage--; if (CurImage < 0) CurImage = 0; ilActiveImage(CurImage); ilutRenderer(ILUT_WIN32); ResizeWin(); CreateGDI(); } if (wParam == VK_PRIOR) { if (!GetPrevImage()) break; DestroyGDI(); if (UndoSize == 0) UndoSize = 1; ilDeleteImages(UndoSize, Undos); UndoSize = 0; XOff = 0; YOff = 0; ilGenImages(1, Undos); ilBindImage(Undos[0]); //last_elapsed = SDL_GetTicks(); if (!ilLoadImage(OpenFileName)) { wsprintf(CurFileName, L"%s", OpenFileName); wsprintf(NewTitle, L"%s - Could not open %s", TITLE, OpenFileName); SetWindowText(hWnd, NewTitle); return (0L); } CurImage = 0; //cur_elapsed = SDL_GetTicks(); elapsed = cur_elapsed - last_elapsed; last_elapsed = cur_elapsed; ilutRenderer(ILUT_WIN32); ResizeWin(); CreateGDI(); wsprintf(CurFileName, L"%s", OpenFileName); wsprintf(NewTitle, L"%s - %s: %u ms", TITLE, OpenFileName, (unsigned int)elapsed); SetWindowText(hWnd, NewTitle); } if (wParam == VK_NEXT) { if (!GetNextImage()) break; DestroyGDI(); if (UndoSize == 0) UndoSize = 1; ilDeleteImages(UndoSize, Undos); UndoSize = 0; XOff = 0; YOff = 0; ilGenImages(1, Undos); ilBindImage(Undos[0]); //last_elapsed = SDL_GetTicks(); if (!ilLoadImage(OpenFileName)) { wsprintf(CurFileName, L"%s", OpenFileName); wsprintf(NewTitle, L"%s - Could not open %s", TITLE, OpenFileName); SetWindowText(hWnd, NewTitle); return (0L); } CurImage = 0; //cur_elapsed = SDL_GetTicks(); elapsed = cur_elapsed - last_elapsed; last_elapsed = cur_elapsed; ilutRenderer(ILUT_WIN32); ResizeWin(); CreateGDI(); wsprintf(CurFileName, L"%s", OpenFileName); wsprintf(NewTitle, L"%s - %s: %u ms", TITLE, OpenFileName, (unsigned int)elapsed); SetWindowText(hWnd, NewTitle); } InvalidateRect(hWnd, NULL, FALSE); break; // Moves the "viewport" case WM_MOUSEMOVE: if (!MouseDown) break; GetCursorPos(&CurMouse); XOff += CurMouse.x - PrevMouse.x; YOff += CurMouse.y - PrevMouse.y; PrevMouse.x = CurMouse.x; PrevMouse.y = CurMouse.y; InvalidateRect(hWnd, NULL, FALSE); break; case WM_LBUTTONDOWN: MouseDown = IL_TRUE; GetCursorPos(&PrevMouse); break; case WM_LBUTTONUP: MouseDown = IL_FALSE; break; case WM_DROPFILES: hDrop = (HDROP)wParam; DragQueryFile(hDrop, 0, OpenFileName, 512); DestroyGDI(); ilDeleteImages(UndoSize, Undos); UndoSize = 0; ilGenImages(1, Undos); ilBindImage(Undos[0]); ilLoadImage(OpenFileName); CurImage = 0; ilutRenderer(ILUT_WIN32); ResizeWin(); CreateGDI(); wsprintf(CurFileName, L"%s", OpenFileName); wsprintf(NewTitle, L"%s - %s", TITLE, OpenFileName); SetWindowText(hWnd, NewTitle); DragFinish(hDrop); return 0; case WM_COMMAND: FilterType = LOWORD(wParam); switch (LOWORD(wParam)) { case ID_FILE_EXIT: PostMessage(hWnd, WM_CLOSE, 0, 0); return (0L); case ID_HELP_ABOUT: DialogBox (hInstance, MAKEINTRESOURCE(IDD_DIALOG_ABOUT), hWnd, AboutDlgProc); return (0L); case ID_FILE_PROPERTIES: DialogBox (hInstance, MAKEINTRESOURCE(IDD_DIALOG_PROPERTIES), hWnd, PropertiesDlgProc); return (0L); case ID_BATCHCONVERT: DialogBox (hInstance, MAKEINTRESOURCE(IDD_DIALOG_BATCHCONV), hWnd, BatchDlgProc); return (0L); case ID_EFFECTS_COUNTCOLORS: Colours = iluColoursUsed(); TCHAR ColourString[255]; wsprintf(ColourString, L"The number of colours in this image is: %d", Colours); MessageBox(NULL, ColourString, L"Colour Count", MB_OK); return (0L); case ID_EFFECTSTOOLS_BACKGROUNDCOLOUR: //userClickedOK = FSColorPickerDoModal(¤tColor, true, &originalColor, true, 0); userClickedOK = 0; if (userClickedOK) { Red = (ILfloat)((currentColor & 0xff0000) >> 16) / 255.0f; Green = (ILfloat)((currentColor & 0xff00) >> 8) / 255.0f; Blue = (ILfloat)(currentColor & 0xff) / 255.0f; ilClearColour(Red, Green, Blue, 1.0f); } return (0L); case ID_EDIT_COPY: ilutSetWinClipboard(); return (0L); case ID_EDIT_PASTE: ILuint Test; ilGenImages(1, &Test); ilBindImage(Test); // Check if there's anything in the clipboard. if (!ilutGetWinClipboard()) { ilDeleteImages(1, &Test); return (0L); } ilDeleteImages(1, &Test); DestroyGDI(); ilDeleteImages(UndoSize, Undos); UndoSize = 0; XOff = 0; YOff = 0; ilGenImages(1, Undos); ilBindImage(Undos[0]); ilutGetWinClipboard(); wsprintf(CurFileName, L"Clipboard Paste"); wsprintf(NewTitle, L"%s - Pasted from the Clipboard", TITLE); SetWindowText(hWnd, NewTitle); //ilConvertImage(IL_BGRA); ilutRenderer(ILUT_WIN32); ResizeWin(); CreateGDI(); return (0L); // @TODO: Will probably fail if no image loaded! case ID_FILE_PRINT: /*PRINTDLG Pd; DOCINFO Di; //HDC PrintDC; //HBITMAP PrintReplace; memset(&Pd, 0, sizeof(PRINTDLG)); Pd.lStructSize = sizeof(PRINTDLG); Pd.hwndOwner = hWnd; Pd.Flags = PD_RETURNDC; Pd.nCopies = 1; Pd.nFromPage = 0xFFFF; Pd.nToPage = 0xFFFF; Pd.nMinPage = 1; Pd.nMaxPage = 0xFFFF; if (!PrintDlg(&Pd)) return (0L); Di.cbSize = sizeof(DOCINFO); Di.lpszDocName = L"DevIL Printing Test"; Di.lpszOutput = NULL; Di.lpszDatatype = NULL; Di.fwType = 0; StartDoc(Pd.hDC, &Di); StartPage(Pd.hDC); //PrintDC = CreateCompatibleDC(Pd.hDC); //PrintReplace = (HBITMAP)SelectObject(PrintDC, hBitmap); StretchBlt(Pd.hDC, 0, 0, Width * 2, Height * 2, hMemDC, 0, 0, Width, Height, SRCCOPY); EndPage(Pd.hDC); EndDoc(Pd.hDC); //DeleteObject(PrintReplace); //DeleteDC(PrintDC); DeleteDC(Pd.hDC);*/ ilutWinPrint(0, 0, ilGetInteger(IL_IMAGE_WIDTH) * 2, ilGetInteger(IL_IMAGE_HEIGHT) * 2, hDC); return (0L); case ID_FILE_LOAD: wsprintf(OpenFileName, L"*.*"); Ofn.lpstrFilter = OpenFilter; Ofn.lpstrFile = OpenFileName; Ofn.lpstrTitle = L"Open File"; Ofn.nFilterIndex = 1; Ofn.Flags = OFN_HIDEREADONLY | OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST; if (!GetOpenFileName(&Ofn)) return (0L); DestroyGDI(); if (UndoSize == 0) UndoSize = 1; ilDeleteImages(UndoSize, Undos); UndoSize = 0; XOff = 0; YOff = 0; ilGenImages(1, Undos); ilBindImage(Undos[0]); //last_elapsed = SDL_GetTicks(); if (!ilLoadImage(OpenFileName)) return (0L); CurImage = 0; //cur_elapsed = SDL_GetTicks(); elapsed = cur_elapsed - last_elapsed; last_elapsed = cur_elapsed; //iluBuildMipmaps(); //ilConvertImage(IL_RGBA, IL_UNSIGNED_BYTE); //ilEnable(IL_NVIDIA_COMPRESS); //ilEnable(IL_SQUISH_COMPRESS); //ilSetInteger(IL_DXTC_FORMAT, IL_DXT5); //free(ilCompressDXT(ilGetData(), ilGetInteger(IL_IMAGE_WIDTH), ilGetInteger(IL_IMAGE_HEIGHT), 1, IL_DXT5, &Size)); //free(ilNVidiaCompressDXT(ilGetData(), ilGetInteger(IL_IMAGE_WIDTH), ilGetInteger(IL_IMAGE_HEIGHT), 1, IL_DXT5)); ilutRenderer(ILUT_WIN32); ResizeWin(); CreateGDI(); wsprintf(CurFileName, L"%s", OpenFileName); wsprintf(NewTitle, L"%s - %s: %u ms", TITLE, OpenFileName, (unsigned int)elapsed); SetWindowText(hWnd, NewTitle); return (0L); case ID_FILE_OPENURL: if (DialogBox(hInstance, MAKEINTRESOURCE(IDD_DIALOG_FILTER), hWnd, FilterDlgProc) != TRUE) { return (0L); } DestroyGDI(); ilDeleteImages(UndoSize, Undos); UndoSize = 0; XOff = 0; YOff = 0; ilGenImages(1, Undos); ilBindImage(Undos[0]); /*if (!ilutWinLoadUrl(FilterEditString)) return (0L);*/ ilutRenderer(ILUT_WIN32); ResizeWin(); CreateGDI(); wsprintf(NewTitle, L"%s - %s", TITLE, FilterEditString); SetWindowText(hWnd, NewTitle); return (0L); case ID_FILE_SAVE: wsprintf(SaveFileName, L"monkey.tga"); Ofn.lpstrFilter = SaveFilter; Ofn.lpstrFile = SaveFileName; Ofn.lpstrTitle = L"Save File"; Ofn.nFilterIndex = 1; Ofn.Flags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT; if (!GetSaveFileName(&Ofn)) return (0L); ilEnable(IL_FILE_OVERWRITE); //ilBindImage(Undos[0]); //@TODO: Do better here... //last_elapsed = SDL_GetTicks(); ilSaveImage(SaveFileName); //cur_elapsed = SDL_GetTicks(); elapsed = cur_elapsed - last_elapsed; last_elapsed = cur_elapsed; wsprintf(CurFileName, L"%s", SaveFileName); wsprintf(NewTitle, L"%s - %s: %u ms", TITLE, SaveFileName, (unsigned int)elapsed); SetWindowText(hWnd, NewTitle); return (0L); case ID_EDIT_UNDOLEVEL: if (DialogBox(hInstance, MAKEINTRESOURCE(IDD_DIALOG_FILTER), hWnd, FilterDlgProc) == TRUE) { NumUndosAllowed = FilterParamInt <= 10 ? FilterParamInt : 10; } return (0L); case ID_EDIT_UNDO: if (UndoSize && NumUndosAllowed) { ilDeleteImages(1, &Undos[UndoSize]); ilBindImage(Undos[--UndoSize]); ResizeWin(); CreateGDI(); } return (0L); case ID_EDIT_VIEWIMAGENUM: if (DialogBox(hInstance, MAKEINTRESOURCE(IDD_DIALOG_FILTER), hWnd, FilterDlgProc) == TRUE) { ilBindImage(Undos[0]); // @TODO: Implement undos better with this. ilActiveImage(FilterParamInt); ilutRenderer(ILUT_WIN32); ResizeWin(); CreateGDI(); } return (0L); case ID_EDIT_VIEWFACE: if (DialogBox(hInstance, MAKEINTRESOURCE(IDD_DIALOG_FILTER), hWnd, FilterDlgProc) == TRUE) { ilActiveFace(FilterParamInt); ilutRenderer(ILUT_WIN32); ResizeWin(); CreateGDI(); } return (0L); case ID_EDIT_VIEWMIPMAP: if (DialogBox(hInstance, MAKEINTRESOURCE(IDD_DIALOG_FILTER), hWnd, FilterDlgProc) == TRUE) { ilActiveMipmap(FilterParamInt); ilutRenderer(ILUT_WIN32); ResizeWin(); CreateGDI(); } return (0L); case ID_EDIT_NEXT: ilBindImage(Undos[0]); // @TODO: Implement undos better with this. CurImage++; ilActiveImage(CurImage); ilutRenderer(ILUT_WIN32); ResizeWin(); CreateGDI(); return (0L); case ID_EDIT_PREV: ilBindImage(Undos[0]); // @TODO: Implement undos better with this. CurImage--; ilActiveImage(CurImage); ilutRenderer(ILUT_WIN32); ResizeWin(); CreateGDI(); return (0L); } if (++UndoSize > NumUndosAllowed) { if (NumUndosAllowed > 0) { UndoSize = NumUndosAllowed; ilDeleteImages(1, &Undos[0]); memcpy(Undos, Undos+1, NumUndosAllowed * sizeof(ILuint)); ilBindImage(Undos[UndoSize]); } } if (NumUndosAllowed > 0) { ilGetIntegerv(IL_ACTIVE_IMAGE, (ILint*)&Undos[UndoSize]); /*ilGenImages(1, &Undos[UndoSize]); ilBindImage(Undos[UndoSize]); ilCopyImage(Undos[UndoSize-1]);*/ Undos[UndoSize] = ilCloneCurImage(); ilBindImage(Undos[UndoSize]); } DestroyGDI(); switch (LOWORD(wParam)) { case ID_CONVERT_PALETTE: ilConvertImage(IL_COLOUR_INDEX, IL_UNSIGNED_BYTE); break; case ID_CONVERT_RGB: ilConvertImage(IL_RGB, ilGetInteger(IL_IMAGE_TYPE)); break; case ID_CONVERT_RGBA: ilConvertImage(IL_RGBA, ilGetInteger(IL_IMAGE_TYPE)); break; case ID_CONVERT_BGR: ilConvertImage(IL_BGR, ilGetInteger(IL_IMAGE_TYPE)); break; case ID_CONVERT_BGRA: ilConvertImage(IL_BGRA, ilGetInteger(IL_IMAGE_TYPE)); break; case ID_CONVERT_LUMINANCE: ilConvertImage(IL_LUMINANCE, ilGetInteger(IL_IMAGE_TYPE)); break; case ID_CONVERT_LUMINANCEALPHA: ilConvertImage(IL_LUMINANCE_ALPHA, ilGetInteger(IL_IMAGE_TYPE)); break; case ID_EDIT_VIEWALPHA: Origin = ilGetInteger(IL_ORIGIN_MODE); AlphaChannel = ilGetAlpha(IL_UNSIGNED_BYTE); ilTexImage(ilGetInteger(IL_IMAGE_WIDTH), ilGetInteger(IL_IMAGE_HEIGHT), ilGetInteger(IL_IMAGE_DEPTH), 1, IL_LUMINANCE, IL_UNSIGNED_BYTE, AlphaChannel); free(AlphaChannel); ilRegisterOrigin(Origin); break; case ID_EFFECTS_FLIP: iluFlipImage(); break; case ID_EFFECTS_MIRROR: iluMirror(); break; case ID_FILTER_EMBOSS: iluEmboss(); break; case ID_FILTER_EQUALIZE: iluEqualize(); break; case ID_FILTER_ALIENIFY: iluAlienify(); break; case ID_FILTER_NEGATIVE: iluNegative(); break; case ID_EFFECTS_FILTERS_EDGEDETECT_EMBOSS: iluEdgeDetectE(); break; case ID_EFFECTS_FILTERS_EDGEDETECT_SOBEL: iluEdgeDetectS(); break; case ID_EFFECTS_FILTERS_EDGEDETECT_PREWITT: iluEdgeDetectP(); break; case ID_FILTER_NOISE: if (DialogBox(hInstance, MAKEINTRESOURCE(IDD_DIALOG_FILTER), hWnd, FilterDlgProc) == TRUE) { iluNoisify(FilterParamFloat); } break; case ID_EFFECTS_FILTERS_WAVE: if (DialogBox(hInstance, MAKEINTRESOURCE(IDD_DIALOG_FILTER), hWnd, FilterDlgProc) == TRUE) { iluWave(FilterParamFloat); } break; case ID_FILTER_PIXELIZE: if (DialogBox(hInstance, MAKEINTRESOURCE(IDD_DIALOG_FILTER), hWnd, FilterDlgProc) == TRUE) { iluPixelize(FilterParamInt); } break; case ID_FILTERS_BLUR_AVERAGE: if (DialogBox(hInstance, MAKEINTRESOURCE(IDD_DIALOG_FILTER), hWnd, FilterDlgProc) == TRUE) { iluBlurAvg(FilterParamInt); } break; case ID_FILTERS_BLUR_GAUSSIAN: if (DialogBox(hInstance, MAKEINTRESOURCE(IDD_DIALOG_FILTER), hWnd, FilterDlgProc) == TRUE) { iluBlurGaussian(FilterParamInt); /*iluMatrixMode(ILU_CONVOLUTION_MATRIX); iluLoadFilter(ILU_FILTER_GAUSSIAN_5X5); iluApplyMatrix();*/ } break; case ID_FILTER_GAMMACORRECT: if (DialogBox(hInstance, MAKEINTRESOURCE(IDD_DIALOG_FILTER), hWnd, FilterDlgProc) == TRUE) { iluGammaCorrect(FilterParamFloat); } break; case ID_FILTER_SHARPEN: if (DialogBox(hInstance, MAKEINTRESOURCE(IDD_DIALOG_FILTER), hWnd, FilterDlgProc) == TRUE) { iluSharpen(FilterParamFloat, 1); } break; case ID_EFFECTS_FILTERS_ROTATE: if (DialogBox(hInstance, MAKEINTRESOURCE(IDD_DIALOG_FILTER), hWnd, FilterDlgProc) == TRUE) { iluRotate(FilterParamFloat); ResizeWin(); } break; case ID_EFFECTS_FILTERS_SCALE: HWnd = hWnd; iluImageParameter(ILU_FILTER, ILU_BILINEAR); DialogBox(hInstance, MAKEINTRESOURCE(IDD_DIALOG_RESIZE), hWnd, ResizeDlgProc); break; } CreateGDI(); InvalidateRect(hWnd, NULL, FALSE); break; default: return (DefWindowProc(hWnd, message, wParam, lParam)); } return (0L); }
ILvoid ilWin32::Init() { ilutRenderer(ILUT_WIN32); return; }
ILvoid ilAlleg::Init() { ilutRenderer(IL_ALLEGRO); return; }
/* Program entry point */ int main(int argc, char *argv[]) { glutInit(&argc, argv); glutInitWindowSize(winWidth,winHeight); glutInitWindowPosition(300,50); glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH | GLUT_STENCIL); glutCreateWindow("Turmites v01 ---- Martin Johansson"); // Parse settings file std::ifstream file_settings("settings.txt"); if(file_settings.is_open()) { std::cout << "Successfully opened settings.txt" << std::endl; } if( !file_settings.is_open() ) { file_settings.open("../settings.txt"); } if(file_settings.is_open()) { std::cout << "Successfully opened settings.txt in down folder" << std::endl; } std::string str; std::vector<int> v; // Debug // Get map size and boarder settings while(std::getline(file_settings, str)) { std::istringstream iss(str); int n; while (iss >> n) v.push_back(n); } // Validate input if(v.size() != 3 || v[0] < 2 || v[1] < 2 || v[2]<0 || v[2]>1) { printf("Error reading settings file"); return EXIT_FAILURE; } // Create the turmite on the specified map size turmite.reset(new Turmite(v[0], v[1])); // Set boundary condition turmite->toroidalWalk = v[2]; bool success = turmite->readInput(); if(!success) { printf("Error loading input file."); return EXIT_FAILURE; } //callbacks glutDisplayFunc(draw); glutReshapeFunc(changeSize); glutCreateMenu(timer); glutAddMenuEntry("Fastest", 1); glutAddMenuEntry("2 ms delay", 2); glutAddMenuEntry("10 ms delay", 10); glutAddMenuEntry("100 ms delay", 100); glutAddMenuEntry("Slowest", 1000); glutAttachMenu(GLUT_RIGHT_BUTTON); // Setup keyboard glutKeyboardFunc(keyboard); ilInit(); iluInit(); ilutRenderer(ILUT_OPENGL); Viewer::init(winWidth,winHeight); glutMainLoop(); return EXIT_SUCCESS; }
/* inicjuje * -oswietlenie * -cieniowanie * -biblioteke glut * -wspolprace z systemem okienkowym */ void init() { GLenum err = glewInit(); if (GLEW_OK != err) { std::cout << "GLEW initialisation error: " << glewGetErrorString(err) << std::endl; exit(-1); } std::cout << "GLEW intialised successfully. Using GLEW version: " << glewGetString(GLEW_VERSION) << std::endl; GLfloat mat_ambient[] = { 1.0, 1.0, 1.0, 1.0 }; GLfloat mat_diffuse[] = { 0.5, 0.5, 0.5, 1.0 }; GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 }; GLfloat light1_position[] = { 10.0, 5.0, 10.0, 1.0 }; GLfloat light2_position[] = { -10.0, 10.0, -10.0, 1.0 }; GLfloat light3_position[] = { 10.0, 10.0, -10.0, 1.0 }; GLfloat light4_position[] = { -10.0, 10.0, 10.0, 1.0 }; GLfloat lm_ambient[] = { 0.2, 0.2, 0.2, 1.0 }; glMaterialfv( GL_FRONT, GL_AMBIENT, mat_ambient ); glMaterialfv( GL_FRONT, GL_SPECULAR, mat_specular ); glMaterialf( GL_FRONT, GL_SHININESS, 50.0 ); glLightfv( GL_LIGHT0, GL_POSITION, light1_position ); glLightfv( GL_LIGHT1, GL_POSITION, light2_position ); glLightfv(GL_LIGHT1, GL_DIFFUSE, mat_diffuse); glLightfv( GL_LIGHT2, GL_POSITION, light3_position ); glLightfv(GL_LIGHT2, GL_DIFFUSE, mat_diffuse); glLightfv( GL_LIGHT3, GL_POSITION, light4_position ); glLightfv(GL_LIGHT3, GL_DIFFUSE, mat_diffuse); glLightModelfv( GL_LIGHT_MODEL_AMBIENT, lm_ambient ); glEnable(GL_NORMALIZE); glShadeModel( GL_SMOOTH ); // obliczanie swiatla glEnable( GL_LIGHTING ); glEnable( GL_LIGHT0 ); glEnable( GL_LIGHT1 ); glEnable( GL_LIGHT2 ); glEnable( GL_LIGHT3 ); glDepthFunc( GL_LESS ); glEnable( GL_DEPTH_TEST ); //glBlendFunc (GL_SRC_ALPHA, GL_ONE); // DevIL sanity check if ( (iluGetInteger(IL_VERSION_NUM) < IL_VERSION) || (iluGetInteger(ILU_VERSION_NUM) < ILU_VERSION) || (ilutGetInteger(ILUT_VERSION_NUM) < ILUT_VERSION) ) { std::cout << "DevIL versions are different... Exiting." << std::endl; exit(-1); } // Initialise all DevIL functionality ilInit(); iluInit(); ilutInit(); ilutRenderer(ILUT_OPENGL); // Tell DevIL that we're using OpenGL for our rendering }
void TransIcelandicExpress::redraw( void ) { static tex_init = 0; if (!tex_init) { ilutRenderer( ILUT_OPENGL ); ilGenImages( 1, &ImageName ); ilBindImage( ImageName ); glEnable( GL_TEXTURE_2D ); glEnable( GL_BLEND ); glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); if (!ilLoadImage( "ludum48.png" )) { printf("Loading image failed\n"); } gl_tex_id = ilutGLBindTexImage(); ilutGLTexImage( 0 ); tex_init = 1; } glBindTexture (GL_TEXTURE_2D, gl_tex_id ); glClearColor( 0.3f, 0.4f, 0.6f, 1.0f ); glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); //glEnable( GL_CULL_FACE ); glEnable( GL_DEPTH_TEST ); // 3d part glMatrixMode( GL_PROJECTION ); glLoadIdentity(); gluPerspective( 60.0, 800.0/600.0, 0.05, 100.0 ); gluLookAt( player->pos[0]+cameraPos[0], player->pos[1]+cameraPos[1]+c_PlayerHeight, player->pos[2]+cameraPos[2], player->pos[0], player->pos[1]+ c_PlayerHeight, player->pos[2], 0.0, 1.0, 0.0 ); glMatrixMode( GL_MODELVIEW ); glLoadIdentity(); // apply some of the camera xform to the light just to make // it more shiny glPushMatrix(); float viewHead = atan2( cameraPos[2], cameraPos[0] ); glRotated( viewHead * SG_RADIANS_TO_DEGREES, 0.0f, 1.0f, 0.0f ); setupLights(); glPopMatrix(); draw3d(); // 2d part glMatrixMode( GL_PROJECTION ); glLoadIdentity(); gluOrtho2D( 0, 800, 0, 600 ) ; glMatrixMode( GL_MODELVIEW ); glLoadIdentity(); glDisable( GL_LIGHTING ); draw2d(); SDL_GL_SwapBuffers(); }