SoundplaneZoneView::SoundplaneZoneView() : mpModel(nullptr) { setInterceptsMouseClicks (false, false); MLWidget::setComponent(this); setupGL(this); }
void ofApp::setup(){ ofEnableDataPath(); setupConstants(); setupGlobals(); setupGL(); setupGraph(forward_graph, forward_graph_path); setupParameters(); cout<<params<<endl; forward_graph->initFbos(); setupAudio(); // if(use_camera){ // camera.setVerbose(true); // camera.listDevices(); // camera.initGrabber(render_width, render_height); // } cout<<"setup complete"<<endl; }
int main(){ //Create window and setup GL context--- int window_width = 640; int window_height = 480; GLFWwindow* gl_window = setupGL(window_width,window_height,true); char *gl_context_version = (char*)glGetString(GL_VERSION); std::cout << "GL context version -> " << gl_context_version << std::endl; //Run gpgpu--- FloatTextureTestGPGPU gpgpu; gpgpu.execute(); }
void initializeGraphics(int argc, char** argv, char* programName, int windowWidth, int windowHeight) { WIN_WIDTH = windowWidth; WIN_HEIGHT = windowHeight; glutInit(&argc, argv); setupGLUT(programName); setupGL(); glewInit(); setupShaders(); }
void DarkenManager::init(int argc, char **argv) { setupGL(argc, argv); clTools::initOpenCL (m_context, m_id, m_queue, "", true, true); setupData(); setupCLprog(); setupShaders(); #ifdef _WIN32 QueryPerformanceFrequency((LARGE_INTEGER*)&m_ticksPerSecond); QueryPerformanceCounter((LARGE_INTEGER*)&m_start_ticks); #endif //_WIN32 m_frames = 0; }
Renderer::Renderer(int width, int height) { if (setupGL() == 1) { exit(1); } _window = setupWindow(width,height); if (!_window) { std::cout << "ERROR: Falied to initialize glfw window." << std::endl; exit(1); } vertexShaderPath = ""; fragmentShaderPath = ""; setCenterX = 0; setCenterY = 0; updateFunctions = new vector<void (*)(int)>(); }
/*! init the window: create the HDC and HGLRC */ void WIN32Window::init( void ) { setHdc(GetDC(getHwnd())); if(getHglrc() == NULL ) { setHglrc(wglCreateContext(getHdc())); if(getHglrc() == NULL) { SFATAL << "WIN32Window::init: failed: " << GetLastError() << endLog; } } ReleaseDC(getHwnd(),getHdc()); activate(); setupGL(); }
int main(int argc, char *argv[]) { //initCube(&cube0, 30.0f, 30.0f, 30.0f); setParticle(particles, isovalue); glutInit(&argc, argv); glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB); // TODO: test on psp glutInitWindowSize(SCREEN_WIDTH, SCREEN_HEIGHT); // TODO: test on psp glutInitWindowPosition(0,0); // TODO: test on psp glutCreateWindow(__FILE__); glutKeyboardFunc(keydown); glutKeyboardUpFunc(keyup); glutJoystickFunc(joystick, 0); //glutReshapeFunc(reshape); //glutReshapeFunc(setupGL); glutDisplayFunc(display2); setupGL(SCREEN_WIDTH, SCREEN_HEIGHT); glutMainLoop(); return 0; }
int main(int argc,char**argv) { double atStart,now,remain; /// Initialize GLFW glfwInit(); // Open registers OpenGL window if( !(windows[REGISTER_WINDOW]=glfwCreateWindow( REGISTER_WIDTH, REGISTER_HEIGHT, "cpu",NULL,NULL)) ) { glfwTerminate(); return 1; } glfwSetWindowPos(windows[REGISTER_WINDOW],600,740); glfwMakeContextCurrent(windows[REGISTER_WINDOW]); setupGL(REGISTER_WINDOW,REGISTER_WIDTH,REGISTER_HEIGHT); // Open timing OpenGL window if( !(windows[TIMING_WINDOW]=glfwCreateWindow( TIMING_WIDTH, TIMING_HEIGHT, "timing",NULL,NULL)) ) { glfwTerminate(); return 1; } glfwSetWindowPos(windows[TIMING_WINDOW],600,300); glfwMakeContextCurrent(windows[TIMING_WINDOW]); setupGL(TIMING_WINDOW,TIMING_WIDTH,TIMING_HEIGHT); // Open invaders OpenGL window if( !(windows[MAIN_WINDOW]=glfwCreateWindow( WIDTH, HEIGHT, "invaders",NULL,NULL)) ) { glfwTerminate(); return 1; } glfwSetWindowPos(windows[MAIN_WINDOW],300,300); glfwMakeContextCurrent(windows[MAIN_WINDOW]); setupGL(MAIN_WINDOW,WIDTH,HEIGHT); glfwSwapInterval(0); // Disable VSYNC glfwSetKeyCallback(windows[MAIN_WINDOW],kbHandler); glfwSetScrollCallback(windows[TIMING_WINDOW],mwHandler); atStart=glfwGetTime(); ////////////////// if (InitialiseMemory()) return -1; PinSetRESET(1); PIN_BUFFER_RESET=1; PinSetO1(1); // Run with reset high for a few cycles to perform a full cpu reset PinSetO1(0); PinSetO2(1); PinSetO2(0); PinSetO1(1); PinSetO1(0); PinSetO2(1); PinSetO2(0); PinSetO1(1); PinSetO1(0); PinSetO2(1); PinSetO2(0); PinSetRESET(0); // RESET CPU PIN_BUFFER_RESET=0; //dumpInstruction=100000; int stopTheClock=0; while (!glfwGetKey(windows[MAIN_WINDOW],GLFW_KEY_ESCAPE)) { if (!stopTheClock) { masterClock++; if ((masterClock%4)==0) pixelClock++; if ((masterClock%10)==0) { // I8080 emulation works off positive edge trigger. So we need to supply the same sort of // clock. PIN_BUFFER_O2=0; PIN_BUFFER_O1=1; PinSetO1(1); // Execute a cpu step if (bTimingEnabled) RecordPins(); PIN_BUFFER_O1=0; PinSetO1(0); if (bTimingEnabled) RecordPins(); PIN_BUFFER_O2=1; PinSetO2(1); if (bTimingEnabled) RecordPins(); PIN_BUFFER_O2=0; PinSetO2(0); if (!MEM_Handler()) { stopTheClock=1; } if (bTimingEnabled) RecordPins(); PinSetINT(0); // clear interrupt state PIN_BUFFER_INT=0; cpuClock++; } if (pixelClock==30432+10161) // Based on 19968000 Mhz master clock + mame notes { NEXTINT=0xCF; PinSetINT(1); PIN_BUFFER_INT=1; } if (pixelClock==71008+10161) { NEXTINT=0xD7; PinSetINT(1); PIN_BUFFER_INT=1; } } if (pixelClock>=83200 || stopTheClock) { if (pixelClock>=83200) pixelClock=0; if (glfwWindowShouldClose(windows[TIMING_WINDOW])) { bTimingEnabled=0; glfwHideWindow(windows[TIMING_WINDOW]); } if (glfwWindowShouldClose(windows[REGISTER_WINDOW])) { bRegisterEnabled=0; glfwHideWindow(windows[REGISTER_WINDOW]); } glfwMakeContextCurrent(windows[MAIN_WINDOW]); ShowScreen(MAIN_WINDOW,WIDTH,HEIGHT); glfwSwapBuffers(windows[MAIN_WINDOW]); if (bTimingEnabled) { glfwMakeContextCurrent(windows[TIMING_WINDOW]); DrawTiming(videoMemory[TIMING_WINDOW],TIMING_WIDTH); ShowScreen(TIMING_WINDOW,TIMING_WIDTH,TIMING_HEIGHT); glfwSwapBuffers(windows[TIMING_WINDOW]); } if (bRegisterEnabled) { glfwMakeContextCurrent(windows[REGISTER_WINDOW]); DrawRegister(videoMemory[REGISTER_WINDOW],REGISTER_WIDTH); ShowScreen(REGISTER_WINDOW,REGISTER_WIDTH,REGISTER_HEIGHT); glfwSwapBuffers(windows[REGISTER_WINDOW]); } glfwPollEvents(); g_traceStep=0; if (CheckKey(GLFW_KEY_PAUSE)) { g_instructionStep^=1; if (stopTheClock && !g_instructionStep) stopTheClock=0; ClearKey(GLFW_KEY_PAUSE); } if (stopTheClock && CheckKey('S')) { stopTheClock=0; ClearKey('S'); } if (stopTheClock && CheckKey('T')) { stopTheClock=0; g_traceStep=1; ClearKey('T'); } now=glfwGetTime(); remain = now-atStart; while ((remain<0.02f)) { now=glfwGetTime(); remain = now-atStart; } atStart=glfwGetTime(); } } return 0; }
void Briefing::draw() { Chapter::get()->hud()->draw(); setupGL(false); m_lblMain.doDraw(); switch (m_state) { case Text: case Targets: case Hints: if (m_time.elapsed() < 75) return; break; case Arrow: case PressKey: if (m_time.elapsed() < 500) return; m_toggleState = !m_toggleState; break; } m_time.restart(); ui::Label *label; if (m_state == Init) { m_state = Text; m_nextLine = 0; } if (m_state == Text) { if (m_nextLine < Chapter::get()->mission()->textB().count()) { label = new ui::Label(&m_lblMain); label->setFont(m_font); label->setText(Chapter::get()->mission()->textB().at(m_nextLine)); label->setPosition(0, 64 + m_nextLine*11); label->setWidth(304); label->setAlignment(ui::Label::AlignHCenter); m_woopSound.playInstance(); m_nextLine++; } else { m_state = Targets; m_nextLine = -3; } } if (m_state == Targets) { if (Chapter::get()->mission()->textP().count() > 0 && m_nextLine < Chapter::get()->mission()->textP().count()) { if (m_nextLine >= -2) { label = new ui::Label(&m_lblMain); label->setFont(m_font); if (m_nextLine == -2) label->setText(txt::StringTable::get(txt::Briefing_Targets)); else if (m_nextLine == -1) label->setText(txt::StringTable::get(txt::Briefing_TargetsLine)); else label->setText(Chapter::get()->mission()->textP().at(m_nextLine)); label->setPosition(18, 354 + m_nextLine*11); label->setWidth(304); m_woopSound.playInstance(); } m_nextLine++; } else { m_state = Hints; m_nextLine = -3; } } if (m_state == Hints) { if (Chapter::get()->mission()->textS().count() > 0 && m_nextLine < Chapter::get()->mission()->textS().count()) { if (m_nextLine >= -2) { label = new ui::Label(&m_lblMain); label->setFont(m_font); if (m_nextLine == -2) label->setText(txt::StringTable::get(txt::Briefing_Hints)); else if (m_nextLine == -1) label->setText(txt::StringTable::get(txt::Briefing_HintsLine)); else label->setText(Chapter::get()->mission()->textS().at(m_nextLine)); label->setPosition(322, 354 + m_nextLine*11); label->setWidth(304); m_woopSound.playInstance(); } m_nextLine++; } else { m_state = Arrow; m_nextLine = 0; m_eventInit(); } } if (m_state == Arrow) { m_lblArrow->setVisible(m_toggleState); m_nextLine++; if (m_nextLine > 5) { m_lblPressKey = new ui::Label(&m_lblMain); m_lblPressKey->setFont(m_font); m_lblPressKey->setText(txt::StringTable::get(txt::Briefing_PressAnyKey)); m_lblPressKey->setPosition(0, 454); m_lblPressKey->setWidth(640); m_lblPressKey->setAlignment(ui::Label::AlignHCenter); m_state = PressKey; } } if (m_state == PressKey) { m_lblArrow->setVisible(m_toggleState); m_lblPressKey->setVisible(m_toggleState); if (m_toggleState) m_woopSound.play(); } }
int main(int argc,char **argv) { unsigned char *romPtr; int running=1; int a; for (a=0;a<256;a++) { keyUpArray[a]=1; } // Initialize GLFW glfwInit(); // Open an OpenGL window if( !glfwOpenWindow( AMI_LINE_LENGTH, HEIGHT, 0,0,0,0,0,0, GLFW_WINDOW ) ) { glfwTerminate(); return 1; } glfwSetWindowTitle("MinAmi"); glfwSetWindowPos(670,700); setupGL(AMI_LINE_LENGTH,HEIGHT); romPtr=load_rom("../../out.rom"); if (!romPtr) { romPtr=load_rom("out.rom"); if (!romPtr) { printf("[ERR] Failed to load rom image\n"); glfwTerminate(); return 1; } } CPU_BuildTable(); MEM_Initialise(romPtr); CST_InitialiseCustom(); CPR_InitialiseCopper(); CIA_InitialiseCustom(); BLT_InitialiseBlitter(); DSP_InitialiseDisplay(); DSK_InitialiseDisk(); SPR_InitialiseSprites(); KBD_InitialiseKeyboard(); CPU_Reset(); glfwSetKeyCallback(kbHandler); while (running) { KBD_Update(); SPR_Update(); DSP_Update(); // Note need to priority order these ultimately CST_Update(); DSK_Update(); CPR_Update(); CIA_Update(); BLT_Update(); CPU_Step(); if (g_newScreenNotify) { static int lmx=0,lmy=0; int mx,my; DrawScreen(); glfwSwapBuffers(); g_newScreenNotify=0; glfwGetMousePos(&mx,&my); if ((mx>=1 && mx<=AMI_LINE_LENGTH && my>=1 && my <=HEIGHT) || captureMouse) { int vertMove = my-lmy; int horiMove = mx-lmx; int oldMoveX = CST_GETWRDU(CST_JOY0DAT,0x00FF); int oldMoveY = CST_GETWRDU(CST_JOY0DAT,0xFF00)>>8; if (horiMove>127) horiMove=127; if (horiMove<-128) horiMove=-128; if (vertMove>127) vertMove=127; if (vertMove<-128) vertMove=-128; oldMoveX+=horiMove; oldMoveY+=vertMove; CST_SETWRD(CST_JOY0DAT,((oldMoveY&0xFF)<<8)|(oldMoveX&0xFF),0xFFFF); lmx=mx; lmy=my; if (glfwGetMouseButton(GLFW_MOUSE_BUTTON_LEFT)) { leftMouseUp=0; } else { leftMouseUp=1; } if (glfwGetMouseButton(GLFW_MOUSE_BUTTON_MIDDLE)) { if (captureMouse) { captureMouse=0; glfwEnable(GLFW_MOUSE_CURSOR); } else { captureMouse=1; glfwDisable(GLFW_MOUSE_CURSOR); } } if (glfwGetMouseButton(GLFW_MOUSE_BUTTON_RIGHT)) { rightMouseUp=0; } else { rightMouseUp=1; } } } // Check if ESC key was pressed or window was closed running = !glfwGetKey( GLFW_KEY_ESC ) && glfwGetWindowParam( GLFW_OPENED ); }
void ofApp::setup() { // SYSTEM ofSetLogLevel(OF_LOG_VERBOSE); ofHideCursor(); ofSetFrameRate(60); // SCREEN ofEnableAlphaBlending(); ofBackground(100); width = ofGetWindowWidth(); height = ofGetWindowHeight(); // STATE presenting = true; tooSunny = false; fboAge = 0; imageTimer = 0; imageMAX = 500; playState = 1; currentBrightness = 0; targetAlpha = 155; #ifdef INTERACTIVE // KINECT #ifdef KINECT kinect.setRegistration(true); kinect.init(); kinect.open(); if(kinect.isConnected()) { ofLogNotice() << "sensor-emitter dist: " << kinect.getSensorEmitterDistance() << "cm"; ofLogNotice() << "sensor-camera dist: " << kinect.getSensorCameraDistance() << "cm"; ofLogNotice() << "zero plane pixel size: " << kinect.getZeroPlanePixelSize() << "mm"; ofLogNotice() << "zero plane dist: " << kinect.getZeroPlaneDistance() << "mm"; } angle = 23; kinect.setCameraTiltAngle(angle); #else camera.setVerbose(true); camera.initGrabber(320, 240); #endif // CAPTURE SIZE int capture_width, capture_height; #ifdef KINECT capture_width = kinect.width; capture_height = kinect.height; #else capture_width = camera.width; capture_height = camera.height; #endif // OPENCV colorImg.allocate(capture_width, capture_height); grayImage.allocate(capture_width, capture_height); grayThreshNear.allocate(capture_width, capture_height); grayThreshFar.allocate(capture_width, capture_height); grayBg.allocate(capture_width, capture_height); grayDiff.allocate(capture_width, capture_height); closePoints.allocate(capture_width, capture_height, GL_RGBA32F_ARB); nearThreshold = 350; farThreshold = 112; bLearnBakground = true; threshold = 80; bThreshWithOpenCV = false; minBlob = 25; maxBlob = (capture_width * capture_height)/2; // FBO & GLSL SHADER setupGL(width, height); #else playState = 2; imageMAX = 2500; #endif // XML ASSETS BASEPATH = "../../../MEDIA/"; assets.loadFile("xml/assets.xml"); if( assets.loadFile("xml/assets.xml") ) { ofLog(OF_LOG_NOTICE, "Loaded xml file !!! \n"); loadFonts(); loadArtists(); loadAssets(); } else { ofLog(OF_LOG_ERROR, "UNABLE to load xml file :( \n"); } // INDEX currentIndex = 0; updateCurrentIndex(); // ASSETS brush.loadImage("mouse/brush.png"); stamp.loadImage("logo/stamp_white2.png"); demo.loadMovie(BASEPATH + "demo/studio_in_the_city_6_promo.mp4"); // MEMORY checkMemory(); cout << "Setup Is Done \n" << endl; }
bool Font::open(const std::string& filepath, unsigned int size) { if(is_initialized) { printf("ERROR: you can only use one font file per font object.\n"); ::exit(0); } this->size = size; // READ TTF DATA // ------------- FILE* fp = fopen(filepath.c_str(), "rb"); if(!fp) { printf("ERROR: cannot open: %s\n", filepath.c_str()); return false; } fseek(fp, 0, SEEK_END); int fsize = ftell(fp); fseek(fp, 0, SEEK_SET); unsigned char* font_buffer = new unsigned char[fsize]; if(!font_buffer) { printf("ERROR: cannot allocate font buffer.\n"); return false; } fread(font_buffer, 1, fsize, fp); fclose(fp); fp = 0; // CREATE FONT BITMAP // ------------------- unsigned char* pixels = new unsigned char[int(w * h)]; if(!pixels) { printf("ERROR: cannot allocate font pixel buffer.\n"); return false; } int char_start = 32; int char_end = 96; int num_chars = char_end - char_start; cdata = new stbtt_bakedchar[num_chars * 2]; // when using num_chars I get a malloc: *** error for object 0x1008e2808: incorrect checksum for freed object - object was probably modified after being freed. printf("Creating a font with size: %d\n", size); int r = stbtt_BakeFontBitmap( font_buffer, 0, size, pixels, w, h, char_start, char_end, cdata ); if(r < 0) { printf("ERROR: The baked font doesn't fit in the allocated pixel buffer.\n"); ::exit(0); } else if (r == 0) { printf("ERROR: No characters fit in the pixel buffer.\n"); ::exit(0); } setupGL(pixels, w, h); /* roxlu::Image img; img.copyPixels(pixels, w, h, 1); img.save(File::toDataPath("font.png").c_str()); */ delete[] pixels; delete[] font_buffer; pixels = NULL; font_buffer = NULL; return true; }
void init() { setupGL(); Surface::init(); cam = new Camera(); mdl = new Model(); Mesh mesh = loadMeshFromObj("resources/meshes/dragon.obj", 0.1); Geometry dragon = createGeometryFromMesh(mesh); Surface *surface = new Surface(); //surface->loadDiffuseTexture("resources/meshes/textures/sponza_floor_a_spec.tga"); surfaces.insert(std::pair<std::string, Surface*> (std::string("default"), surface) ); mdl->addGeometryAndSurface(&dragon, surface); // Geometry floor; // Geometry::sVertex v; // v.position = vec3(-1, 0,-1); v.texCoord = vec2(0,0); floor.addVertex(v); // v.position = vec3( 1, 0,-1); v.texCoord = vec2(1,0); floor.addVertex(v); // v.position = vec3( 1, 0, 1); v.texCoord = vec2(1,1); floor.addVertex(v); // v.position = vec3(-1, 0, 1); v.texCoord = vec2(0,1); floor.addVertex(v); // floor.addTriangle(uvec3(0,2,1)); // floor.addTriangle(uvec3(0,3,2)); // mdl->addGeometryAndSurface(&floor, surface); model = new Geometry(); mesh = loadMeshFromObj("resources/meshes/sponza.obj", 0.01f); *model = createGeometryFromMesh(mesh); model->createStaticBuffers(); std::vector<Mesh> meshes = loadMeshesFromObj("resources/meshes/sponza.obj", 0.01f); std::vector<Geometry> geometries = createGeometryFromMesh(meshes); std::vector<Material> materials = loadMaterialsFromMtl("resources/meshes/sponza.mtl"); surfaces = createSurfaceFromMaterial(materials, "resources/meshes/"); for(unsigned int i=0; i<geometries.size(); ++i) { mdl->addGeometryAndSurface(&geometries[i], surfaces[geometries[i].material]); } mdl->prepare(); fsquad = new Geometry(); Geometry::sVertex v; v.position = vec3(-1,-1, 0); v.texCoord = vec2(0,0); fsquad->addVertex(v); v.position = vec3( 1,-1, 0); v.texCoord = vec2(1,0); fsquad->addVertex(v); v.position = vec3( 1, 1, 0); v.texCoord = vec2(1,1); fsquad->addVertex(v); v.position = vec3(-1, 1, 0); v.texCoord = vec2(0,1); fsquad->addVertex(v); fsquad->addTriangle(uvec3(0,1,2)); fsquad->addTriangle(uvec3(0,2,3)); fsquad->createStaticBuffers(); geometryShader = new Shader("resources/shaders/geometry_vert.glsl", "resources/shaders/geometry_frag.glsl"); geometryBackShader = new Shader("resources/shaders/geometry_vert.glsl", "resources/shaders/geometry_back_frag.glsl"); hbaoHalfShader = new Shader("resources/shaders/fullscreen_vert.glsl", "resources/shaders/hbao_frag.glsl"); hbaoFullShader = new Shader("resources/shaders/fullscreen_vert.glsl", "resources/shaders/hbao_full_frag.glsl"); compositShader = new Shader("resources/shaders/fullscreen_vert.glsl", "resources/shaders/composit_frag.glsl"); blurXShader = new Shader("resources/shaders/fullscreen_vert.glsl", "resources/shaders/blur_x_frag.glsl"); blurYShader = new Shader("resources/shaders/fullscreen_vert.glsl", "resources/shaders/blur_y_frag.glsl"); downsampleShader = new Shader("resources/shaders/fullscreen_vert.glsl", "resources/shaders/downsample_depth_frag.glsl"); upsampleShader = new Shader("resources/shaders/fullscreen_vert.glsl", "resources/shaders/upsample_aoz_frag.glsl"); // Full res deferred base fboFullRes = new Framebuffer2D(WIDTH, HEIGHT); fboFullRes->attachBuffer(FBO_DEPTH, GL_DEPTH_COMPONENT32, GL_DEPTH_COMPONENT, GL_FLOAT, GL_LINEAR, GL_LINEAR); fboFullRes->attachBuffer(FBO_AUX0, GL_RGBA8, GL_RGBA, GL_FLOAT); fboFullRes->attachBuffer(FBO_AUX1, GL_RG16F, GL_RG, GL_FLOAT, GL_LINEAR, GL_LINEAR); fboFullRes->attachBuffer(FBO_AUX2, GL_RG16F, GL_RG, GL_FLOAT, GL_LINEAR, GL_LINEAR); //fboFullRes->attachBuffer(FBO_AUX3, GL_R8, GL_RED, GL_FLOAT); // Half res buffer for AO fboHalfRes = new Framebuffer2D(AO_WIDTH, AO_HEIGHT); //fboHalfRes->attachBuffer(FBO_DEPTH, GL_DEPTH_COMPONENT32, GL_DEPTH_COMPONENT, GL_FLOAT); fboHalfRes->attachBuffer(FBO_AUX0, GL_R32F, GL_RED, GL_FLOAT, GL_LINEAR, GL_LINEAR); fboHalfRes->attachBuffer(FBO_AUX1, GL_R8, GL_RED, GL_FLOAT, GL_LINEAR, GL_LINEAR); float fovRad = cam->getFov() * 3.14159265f / 180.0f; vec2 FocalLen, InvFocalLen, UVToViewA, UVToViewB, LinMAD; FocalLen[0] = 1.0f / tanf(fovRad * 0.5f) * ((float)AO_HEIGHT / (float)AO_WIDTH); FocalLen[1] = 1.0f / tanf(fovRad * 0.5f); InvFocalLen[0] = 1.0f / FocalLen[0]; InvFocalLen[1] = 1.0f / FocalLen[1]; UVToViewA[0] = -2.0f * InvFocalLen[0]; UVToViewA[1] = -2.0f * InvFocalLen[1]; UVToViewB[0] = 1.0f * InvFocalLen[0]; UVToViewB[1] = 1.0f * InvFocalLen[1]; float near = cam->getNear(), far = cam->getFar(); LinMAD[0] = (near-far)/(2.0f*near*far); LinMAD[1] = (near+far)/(2.0f*near*far); hbaoHalfShader->bind(); int pos; pos = hbaoHalfShader->getUniformLocation("FocalLen"); glUniform2f(pos, FocalLen[0], FocalLen[1]); pos = hbaoHalfShader->getUniformLocation("UVToViewA"); glUniform2f(pos, UVToViewA[0], UVToViewA[1]); pos = hbaoHalfShader->getUniformLocation("UVToViewB"); glUniform2f(pos, UVToViewB[0], UVToViewB[1]); pos = hbaoHalfShader->getUniformLocation("LinMAD"); glUniform2f(pos, LinMAD[0], LinMAD[1]); pos = hbaoHalfShader->getUniformLocation("AORes"); glUniform2f(pos, (float)AO_WIDTH, (float)AO_HEIGHT); pos = hbaoHalfShader->getUniformLocation("InvAORes"); glUniform2f(pos, 1.0f/(float)AO_WIDTH, 1.0f/(float)AO_HEIGHT); pos = hbaoHalfShader->getUniformLocation("R"); glUniform1f(pos, AO_RADIUS); pos = hbaoHalfShader->getUniformLocation("R2"); glUniform1f(pos, AO_RADIUS*AO_RADIUS); pos = hbaoHalfShader->getUniformLocation("NegInvR2"); glUniform1f(pos, -1.0f / (AO_RADIUS*AO_RADIUS)); pos = hbaoHalfShader->getUniformLocation("MaxRadiusPixels"); glUniform1f(pos, AO_MAX_RADIUS_PIXELS / (float)RES_RATIO); pos = hbaoHalfShader->getUniformLocation("NoiseScale"); glUniform2f(pos, (float)AO_WIDTH/(float)NOISE_RES, (float)AO_HEIGHT/(float)NOISE_RES); pos = hbaoHalfShader->getUniformLocation("NumDirections"); glUniform1i(pos, AO_DIRS); pos = hbaoHalfShader->getUniformLocation("NumSamples"); glUniform1i(pos, AO_SAMPLES); hbaoFullShader->bind(); pos = hbaoFullShader->getUniformLocation("FocalLen"); glUniform2f(pos, FocalLen[0], FocalLen[1]); pos = hbaoFullShader->getUniformLocation("UVToViewA"); glUniform2f(pos, UVToViewA[0], UVToViewA[1]); pos = hbaoFullShader->getUniformLocation("UVToViewB"); glUniform2f(pos, UVToViewB[0], UVToViewB[1]); pos = hbaoFullShader->getUniformLocation("LinMAD"); glUniform2f(pos, LinMAD[0], LinMAD[1]); pos = hbaoFullShader->getUniformLocation("AORes"); glUniform2f(pos, (float)WIDTH, (float)HEIGHT); pos = hbaoFullShader->getUniformLocation("InvAORes"); glUniform2f(pos, 1.0f/(float)WIDTH, 1.0f/(float)HEIGHT); pos = hbaoFullShader->getUniformLocation("R"); glUniform1f(pos, AO_RADIUS); pos = hbaoFullShader->getUniformLocation("R2"); glUniform1f(pos, AO_RADIUS*AO_RADIUS); pos = hbaoFullShader->getUniformLocation("NegInvR2"); glUniform1f(pos, -1.0f / (AO_RADIUS*AO_RADIUS)); pos = hbaoFullShader->getUniformLocation("MaxRadiusPixels"); glUniform1f(pos, AO_MAX_RADIUS_PIXELS); pos = hbaoFullShader->getUniformLocation("NoiseScale"); glUniform2f(pos, (float)WIDTH/(float)NOISE_RES, (float)HEIGHT/(float)NOISE_RES); pos = hbaoFullShader->getUniformLocation("NumDirections"); glUniform1i(pos, AO_DIRS); pos = hbaoFullShader->getUniformLocation("NumSamples"); glUniform1i(pos, AO_SAMPLES); blurXShader->bind(); pos = blurXShader->getUniformLocation("AORes"); glUniform2f(pos, AO_WIDTH, AO_HEIGHT); pos = blurXShader->getUniformLocation("InvAORes"); glUniform2f(pos, 1.0f/AO_WIDTH, 1.0f/AO_HEIGHT); pos = blurXShader->getUniformLocation("FullRes"); glUniform2f(pos, WIDTH, HEIGHT); pos = blurXShader->getUniformLocation("InvFullRes"); glUniform2f(pos, 1.0f/WIDTH, 1.0f/HEIGHT); pos = blurXShader->getUniformLocation("LinMAD"); glUniform2f(pos, LinMAD[0], LinMAD[1]); blurYShader->bind(); pos = blurYShader->getUniformLocation("AORes"); glUniform2f(pos, AO_WIDTH, AO_HEIGHT); pos = blurYShader->getUniformLocation("InvAORes"); glUniform2f(pos, 1.0f/AO_WIDTH, 1.0f/AO_HEIGHT); pos = blurYShader->getUniformLocation("FullRes"); glUniform2f(pos, WIDTH, HEIGHT); pos = blurYShader->getUniformLocation("InvFullRes"); glUniform2f(pos, 1.0f/WIDTH, 1.0f/HEIGHT); pos = blurYShader->getUniformLocation("LinMAD"); glUniform2f(pos, LinMAD[0], LinMAD[1]); downsampleShader->bind(); pos = downsampleShader->getUniformLocation("LinMAD"); glUniform2f(pos, LinMAD[0], LinMAD[1]); pos = downsampleShader->getUniformLocation("ResRatio"); glUniform1i(pos, RES_RATIO); upsampleShader->bind(); pos = upsampleShader->getUniformLocation("LinMAD"); glUniform2f(pos, LinMAD[0], LinMAD[1]); glGenTextures(1, &noiseTexture); glBindTexture(GL_TEXTURE_2D, noiseTexture); generateNoiseTexture(NOISE_RES, NOISE_RES); }
/* main window procedure */ LONG WINAPI MainWndProc ( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { LONG lRet = 1; extern unsigned int uiWheelMessage; // if ( uMsg == uiWheelMessage ) // uMsg = WM_MOUSEWHEEL; switch (uMsg) { case WM_CREATE: hDC = GetDC( hWnd ); glRC = setupGL( lParam ); ready = 1; if ( !glRC ) { DestroyWindow( hWnd ); Error( "Failed to Create OpenGL Rendering Context." ); } SetTimer( hWnd, 1, 1, NULL ); break; case WM_KEYDOWN: g_kbhit = 1; break; /* case WM_MOVE: // window_x = (int) LOWORD(lParam); // window_y = (int) HIWORD(lParam); // VID_UpdateWindowStatus (); break; case WM_SYSCHAR: // keep Alt-Space from happening break; case WM_SIZE: break; case WM_CLOSE: break; */ case WM_DESTROY: { // if (dibwindow) // DestroyWindow (dibwindow); PostQuitMessage (0); } break; default: /* pass all unhandled messages to DefWindowProc */ lRet = DefWindowProc (hWnd, uMsg, wParam, lParam); break; } /* return 1 if handled message, 0 if not */ return lRet; }
int main(int argc, char **argv) { if (SDL_Init(SDL_INIT_VIDEO) < 0) { fprintf(stderr, "Error: Unable to init SDL: %s\n", SDL_GetError()); exit(1); } SDL_Window* screen; SDL_GLContext glcontext; screen = SDL_CreateWindow("Window Name", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 600, 600,SDL_WINDOW_OPENGL); glcontext = SDL_GL_CreateContext(screen); SDL_ShowCursor(false); GLenum err = glewInit(); if (err != GLEW_OK) fprintf(stderr, "Error: %s", glewGetErrorString(err)); if (!screen) { fprintf(stderr, "Unable to start video: %s\n", SDL_GetError()); } setupGL(); light=glm::vec3(0.0,-100.0,20.0); //setup geometry geoms.push_back(new CCubeVAO(1000,10,1000,glm::vec3(0,-50,0))); geoms.push_back(new CCubeVAO(50,50,10,glm::vec3(-100,0,0))); geoms.push_back(new CCubeVAO(10,10,10,glm::vec3(100,70,-100))); geoms.push_back(new CCubeVAO(100,10,500,glm::vec3(200,50,-100))); geoms.push_back(new ImageVAO(tex)); yaw=0; pit=0; bool quit=false; long long count=0; while(!quit){ input(screen,quit); render(screen,count++); } //cleanup glUseProgram(0); for(int x=0;x<geoms.size();x++) delete geoms.at(x); glDeleteProgram(program); glDeleteTextures(1,&tex); SDL_GL_DeleteContext(glcontext); }
/*! init the window: create the HDC and HGLRC */ void EGLWindow::init( void ) { activate(); setupGL(); }
int main( int argc, char **argv ) { int nRC= 0; printf("ess-sample v1.0\n"); ctx= EssContextCreate(); if ( ctx ) { int len; bool error= false; for( int i= 1; i < argc; ++i ) { len= strlen(argv[i]); if ( (len == 9) && !strncmp( (const char*)argv[i], "--wayland", len) ) { if ( !EssContextSetUseWayland( ctx, true ) ) { error= true; break; } } } if ( !EssContextSetTerminateListener( ctx, 0, &terminateListener ) ) { error= true; } if ( !EssContextSetKeyListener( ctx, 0, &keyListener ) ) { error= true; } if ( !EssContextSetPointerListener( ctx, 0, &pointerListener ) ) { error= true; } if ( !error ) { struct sigaction sigint; sigint.sa_handler= signalHandler; sigemptyset(&sigint.sa_mask); sigint.sa_flags= SA_RESETHAND; sigaction(SIGINT, &sigint, NULL); if ( !EssContextStart( ctx ) ) { error= true; } else if ( !EssContextGetDisplaySize( ctx, &gDisplayWidth, &gDisplayHeight ) ) { error= true; } if ( !error ) { setupGL(); gRunning= true; while( gRunning ) { EssContextRunEventLoopOnce( ctx ); renderGL(); EssContextUpdateDisplay( ctx ); } } } if ( error ) { const char *detail= EssContextGetLastErrorDetail( ctx ); printf("Essos error: (%s)\n", detail ); } EssContextDestroy( ctx ); } return nRC; }
/*! Just call the standard OpenGL setup. */ void PassiveWindow::init( void ) { setupGL(); }