bool RenderTarget::initWithColorBuffersAndDepth(int width, int heigth, const std::vector<GLint>& formats, GLint depthFormat) { if (width <= 0 || heigth <= 0 || formats.empty() || formats.size() > 16) { Logger::toLog("RenderTarget error: Cannot initialize, incorrect parameters.\n"); return false; } destroy(); glGenFramebuffers(1, &m_framebufferObject); glBindFramebuffer(GL_FRAMEBUFFER, m_framebufferObject); initColorBuffers(width, heigth, formats); initDepth(width, heigth, depthFormat); glBindFramebuffer(GL_FRAMEBUFFER, 0); m_isInitialized = true; if (!checkStatus()) destroy(); if (m_isInitialized) initDestroyable(); return m_isInitialized; }
int main( void ) { initGLFW(); initWindow(); initGLEW(); initKeyboard(); // Dark blue background glClearColor(0.0f, 0.0f, 0.4f, 0.0f); int size = 5; float* map = generateHeightMap(size); printf("generated map\n" ); std::vector<glm::vec3> terrain; mapHeightsToPoints(terrain, map, size); printf("mapped to points\n"); // GLuint* indices = generateIndices(terrain, size); uint terrainVertexAmount = size* size * 3; uint indiceAmount = 3 * (1 << size); for(int i = 0; i < terrain.size(); ++i){ printf("[%f, %f, %f]\n", terrain[i].x, terrain[i].y, terrain[i].z); } printf("vertices %d\n", terrainVertexAmount); GLuint VertexArrayID = newVertexArray(); // Create and compile our GLSL program from the shaders GLuint programID = LoadShaders( "SimpleVertexShader.vertexshader", "SimpleFragmentShader.fragmentshader" ); printf("loaded\n"); initMatrices(programID); GLuint vertexbuffer = newVertexBuffer(terrainVertexAmount, &terrain); double lastTime = glfwGetTime(); int nbFrames = 0; printf("loop\n"); initDepth(); do{ // Clear the screen glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Use our shader glUseProgram(programID); // TODO // recalculateMatrices(); // Send our transformation to the currently bound shader, // in the "MVP" uniform glUniformMatrix4fv(MatrixID, 1, GL_FALSE, &MVP[0][0]); // 1rst attribute buffer : vertices bindVertexBuffer(vertexbuffer); // Draw the triangle ! glDrawArrays(GL_TRIANGLE_FAN, 0, terrainVertexAmount); // 3 indices starting at 0 -> 1 triangle glDisableVertexAttribArray(0); // Swap buffers glfwSwapBuffers(window); glfwPollEvents(); // measureTime(lastTime, &nbFrames); } // Check if the ESC key was pressed or the window was closed while( glfwGetKey(window, GLFW_KEY_ESCAPE ) != GLFW_PRESS && glfwWindowShouldClose(window) == 0 ); // Cleanup VBO glDeleteBuffers(1, &vertexbuffer); glDeleteVertexArrays(1, &VertexArrayID); glDeleteProgram(programID); // Close OpenGL window and terminate GLFW glfwTerminate(); // normal** ns = generateNormals(map, size); return 0; }
void KinectInterfacePrimesense::initOpenNI(const char* device_uri) { initOpenNIStatic(); if (device_uri) { cout << "Initializing device " << device_uri << "..." << endl; } else { cout << "Initializing first avaliable openNI device..." << endl; } // Open a connection to the OpenNI device const char* deviceURI = openni::ANY_DEVICE; if (device_uri != NULL) { deviceURI = device_uri; } device_ = new openni::Device(); checkOpenNIRC(device_->open(deviceURI), "Failed to connect to device"); const openni::DeviceInfo& info = device_->getDeviceInfo(); device_uri_ = info.getUri(); // Note: XYZ (real world values are ALL wrong when image registration is // turned on). It looks OK for a single Kinect, but the space is warped. // This is an OpenNI bug: setCropDepthToRGB(false); setDepthColorSync(false); // Open a connection to the device's depth channel initDepth(); const int depth_size = depth_dim_[0] * depth_dim_[1]; labels_ = new uint8_t[depth_size]; pts_world_ = new float[3 * depth_size]; pts_uvd_ = new float[3 * depth_size]; registered_rgb_ = new uint8_t[3 * depth_size]; // Open a connection to the device's rgb channel bool sync_ir_stream_ = false; initRGB(!sync_ir_stream_); initIR(sync_ir_stream_); bool flip_image_ = true; setFlipImage(flip_image_); std::this_thread::sleep_for(std::chrono::milliseconds(1)); // Update the OpenNIFuncs constants float depth_hfov = streams_[DEPTH_STREAM]->getHorizontalFieldOfView(); float depth_vfov = streams_[DEPTH_STREAM]->getVerticalFieldOfView(); openni_funcs_ = new OpenNIFuncs(depth_dim_[0], depth_dim_[1], depth_hfov, depth_vfov, openni_devices_open_); // Check OpenNI's math: //uint64_t zpd; //streams_[DEPTH_STREAM]->getProperty(XN_STREAM_PROPERTY_ZERO_PLANE_DISTANCE, &zpd); //double zpps; //streams_[DEPTH_STREAM]->getProperty(XN_STREAM_PROPERTY_ZERO_PLANE_PIXEL_SIZE, &zpps); //double focal_length_cmos = (double)zpd / zpps; //// http://en.wikipedia.org/wiki/Angle_of_view FOV calculation //double FOVh = 2.0 * atan( ( 1280.0 * 0.5 ) / focal_length_cmos ); //double FOVv = 2.0 * atan( ( 960.0 * 0.5 ) / focal_length_cmos ); //std::streamsize old_precision = std::cout.precision(); //std::cout.precision(15); //std::cout << "FOVh = " << FOVh << std::endl; //std::cout << "FOVv = " << FOVv << std::endl; //std::cout << "depth_hfov = " << depth_hfov << std::endl; //std::cout << "depth_vfov = " << depth_vfov << std::endl; //std::cout.precision(old_precision); std::cout << "Finished initializaing OpenNI device" << std::endl; }