void initSaver(HWND hwnd){ RECT rect; // Window initialization hdc = GetDC(hwnd); setBestPixelFormat(hdc); hglrc = wglCreateContext(hdc); GetClientRect(hwnd, &rect); wglMakeCurrent(hdc, hglrc); // setup viewport //viewport[0] = rect.left; //viewport[1] = rect.top; //viewport[2] = rect.right - rect.left; //viewport[3] = rect.bottom - rect.top; // initialize extensions if(!initExtensions()) dShaders = 0; reshape(rect.right, rect.bottom); #endif //#ifdef RS_XSCREENSAVER void initSaver(HyperspaceSaverSettings *inSettings){ //#endif // Seed random number generator srand((unsigned)time(NULL)); // Limit memory consumption because the Windows previewer is just too darn slow /*if(doingPreview){ dResolution = 6; if(dDepth > 3) dDepth = 3; };*/ // Set up some other inSettings defaults... inSettings->camPos[0] = 0.0f; inSettings->camPos[1] = 0.0f; inSettings->camPos[2] = 0.0f; inSettings->numAnimTexFrames = 20; inSettings->whichTexture = 0; glDisable(GL_DEPTH_TEST); glEnable(GL_BLEND); glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE); initFlares(inSettings); inSettings->thePath = new splinePath((inSettings->dDepth * 2) + 6); if(inSettings->dUseTunnels) inSettings->theTunnel = new tunnel(inSettings->thePath, 20); // To avoid popping, depth, which will be used for fogging, is set to // dDepth * goo grid size - size of one goo cubelet inSettings->depth = float(inSettings->dDepth) * 2.0f - 2.0f / float(inSettings->dResolution); if(inSettings->dUseGoo) inSettings->theGoo = new goo(inSettings->dResolution, inSettings->depth); inSettings->stars = new stretchedParticle*[inSettings->dStars]; for(int i=0; i<inSettings->dStars; i++){ inSettings->stars[i] = new stretchedParticle; inSettings->stars[i]->radius = rsRandf(float(inSettings->dStarSize) * 0.0005f) + float(inSettings->dStarSize) * 0.0005f; if(i % 10){ // usually bland stars inSettings->stars[i]->color[0] = 0.8f + rsRandf(0.2f); inSettings->stars[i]->color[1] = 0.8f + rsRandf(0.2f); inSettings->stars[i]->color[2] = 0.8f + rsRandf(0.2f); } else{ // occasionally a colorful one inSettings->stars[i]->color[0] = 0.3f + rsRandf(0.7f); inSettings->stars[i]->color[1] = 0.3f + rsRandf(0.7f); inSettings->stars[i]->color[2] = 0.3f + rsRandf(0.7f); inSettings->stars[i]->color[rsRandi(3)] = 1.0f; } inSettings->stars[i]->color[rsRandi(3)] = 1.0f; inSettings->stars[i]->pos[0] = rsRandf(2.0f * inSettings->depth) - inSettings->depth; inSettings->stars[i]->pos[1] = rsRandf(4.0f) - 2.0f; inSettings->stars[i]->pos[2] = rsRandf(2.0f * inSettings->depth) - inSettings->depth; inSettings->stars[i]->fov = float(inSettings->dFov); } inSettings->sunStar = new stretchedParticle; inSettings->sunStar->radius = float(inSettings->dStarSize) * 0.004f; inSettings->sunStar->pos[0] = 0.0f; inSettings->sunStar->pos[1] = 2.0f; inSettings->sunStar->pos[2] = 0.0f; inSettings->sunStar->fov = float(inSettings->dFov); inSettings->theStarBurst = new starBurst; for(int i=0; i<SB_NUM_STARS; i++) inSettings->theStarBurst->stars[i]->radius = rsRandf(float(inSettings->dStarSize) * 0.001f) + float(inSettings->dStarSize) * 0.001f; glGenTextures(1, &inSettings->nebulatex); if(inSettings->dShaders){ initShaders(); inSettings->numAnimTexFrames = 20; glBindTexture(GL_TEXTURE_CUBE_MAP_ARB, inSettings->nebulatex); glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); gluBuild2DMipmaps(GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB, 3, NEBULAMAPSIZE, NEBULAMAPSIZE, GL_RGB, GL_UNSIGNED_BYTE, nebulamap); gluBuild2DMipmaps(GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB, 3, NEBULAMAPSIZE, NEBULAMAPSIZE, GL_RGB, GL_UNSIGNED_BYTE, nebulamap); gluBuild2DMipmaps(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB, 3, NEBULAMAPSIZE, NEBULAMAPSIZE, GL_RGB, GL_UNSIGNED_BYTE, nebulamap); gluBuild2DMipmaps(GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB, 3, NEBULAMAPSIZE, NEBULAMAPSIZE, GL_RGB, GL_UNSIGNED_BYTE, nebulamap); gluBuild2DMipmaps(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB, 3, NEBULAMAPSIZE, NEBULAMAPSIZE, GL_RGB, GL_UNSIGNED_BYTE, nebulamap); gluBuild2DMipmaps(GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB, 3, NEBULAMAPSIZE, NEBULAMAPSIZE, GL_RGB, GL_UNSIGNED_BYTE, nebulamap); } else{ //unsigned char spheremap[NEBULAMAPSIZE][NEBULAMAPSIZE][3] = nebulamap; inSettings->numAnimTexFrames = 60; float x, y, temp; const int halfsize(NEBULAMAPSIZE / 2); for(int i=0; i<NEBULAMAPSIZE; ++i){ for(int j=0; j<NEBULAMAPSIZE; ++j){ x = float(i - halfsize) / float(halfsize); y = float(j - halfsize) / float(halfsize); temp = (x * x) + (y * y); if(temp > 1.0f) temp = 1.0f; if(temp < 0.0f) temp = 0.0f; temp = temp * temp; temp = temp * temp; nebulamap[i][j][0] = GLubyte(float(nebulamap[i][j][0]) * temp); nebulamap[i][j][1] = GLubyte(float(nebulamap[i][j][1]) * temp); nebulamap[i][j][2] = GLubyte(float(nebulamap[i][j][2]) * temp); } } glEnable(GL_NORMALIZE); glBindTexture(GL_TEXTURE_2D, inSettings->nebulatex); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); gluBuild2DMipmaps(GL_TEXTURE_2D, 3, NEBULAMAPSIZE, NEBULAMAPSIZE, GL_RGB, GL_UNSIGNED_BYTE, nebulamap); } glEnable(GL_FOG); float fog_color[4] = {0.0f, 0.0f, 0.0f, 1.0f}; glFogfv(GL_FOG_COLOR, fog_color); glFogf(GL_FOG_MODE, GL_LINEAR); glFogf(GL_FOG_START, inSettings->depth * 0.7f); glFogf(GL_FOG_END, inSettings->depth); // Initialize text inSettings->textwriter = new rsText; //outfile.open("outfile"); inSettings->readyToDraw = 1; }
/** * Initialization of CUDA and GLFW. */ bool init(int argc, char **argv) { // Set window title to "Student Name: [SM 2.0] GPU Name" cudaDeviceProp deviceProp; int gpuDevice = 0; int device_count = 0; cudaGetDeviceCount(&device_count); if (gpuDevice > device_count) { std::cout << "Error: GPU device number is greater than the number of devices!" << " Perhaps a CUDA-capable GPU is not installed?" << std::endl; return false; } cudaGetDeviceProperties(&deviceProp, gpuDevice); int major = deviceProp.major; int minor = deviceProp.minor; std::ostringstream ss; ss << projectName << " [SM " << major << "." << minor << " " << deviceProp.name << "]"; deviceName = ss.str(); // Window setup stuff glfwSetErrorCallback(errorCallback); if (!glfwInit()) { std::cout << "Error: Could not initialize GLFW!" << " Perhaps OpenGL 3.3 isn't available?" << std::endl; return false; } int width = 1280; int height = 720; glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); window = glfwCreateWindow(width, height, deviceName.c_str(), NULL, NULL); if (!window) { glfwTerminate(); return false; } glfwMakeContextCurrent(window); glfwSetKeyCallback(window, keyCallback); glewExperimental = GL_TRUE; if (glewInit() != GLEW_OK) { return false; } // Initialize drawing state initVAO(); // Default to device ID 0. If you have more than one GPU and want to test a non-default one, // change the device ID. cudaGLSetGLDevice(0); cudaGLRegisterBufferObject(planetVBO); // Initialize N-body simulation Nbody::initSimulation(N_FOR_VIS); projection = glm::perspective(fovy, float(width) / float(height), zNear, zFar); glm::mat4 view = glm::lookAt(cameraPosition, glm::vec3(0), glm::vec3(0, 0, 1)); projection = projection * view; initShaders(program); glEnable(GL_DEPTH_TEST); return true; }
void init(void) { // modified to include IdxBufObj also 26 Jan initBuffers(); initShaders(); initRendering(); }