//Set up variables bool DemoInit() { if(!window.Init("Metaballs", 512, 512, 32, 24, 8, WINDOWED_SCREEN)) return 0; //quit if not created //set up grid if(!cubeGrid.CreateMemory()) return false; if(!cubeGrid.Init(gridSize)) return false; //set up metaballs for(int i=0; i<numMetaballs; i++) metaballs[i].Init(VECTOR3D(0.0f, 0.0f, 0.0f), 5.0f+float(i)); //Set Up Colors diffuseColors[0].Set(0.345f, 0.843f, 0.902f, 1.0f); diffuseColors[1].Set(0.047f, 0.839f, 0.271f, 1.0f); diffuseColors[2].Set(0.976f, 0.213f, 0.847f, 1.0f); //reset timer for start timer.Reset(); return true; }
//Set up variables bool DemoInit() { if(!window.Init("Project Template", 640, 480, 32, 24, 8, WINDOWED_SCREEN)) return 0; //quit if not created SetUpARB_multitexture(); SetUpEXT_texture3D(); SetUpEXT_texture_edge_clamp(); SetUpNV_register_combiners(); SetUpNV_texture_shader(); SetUpNV_vertex_program(); if( !EXT_texture_edge_clamp_supported || !ARB_multitexture_supported || !NV_vertex_program_supported || !NV_register_combiners_supported) return false; //Check we have at least 3 texture units GLint maxTextureUnitsARB; glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, &maxTextureUnitsARB); if(maxTextureUnitsARB<3) { errorLog.OutputError("I require at least 3 texture units"); return false; } //Set light colors lightColors[0].Set(1.0f, 1.0f, 1.0f, 1.0f); lightColors[1].Set((float)47/255, (float)206/255, (float)240/255, 1.0f); lightColors[2].Set((float)254/255, (float)48/255, (float)18/255, 1.0f); lightColors[3].Set((float)83/255, (float)243/255, (float)29/255, 1.0f); //Load textures //Decal image decalImage.Load("decal.tga"); glGenTextures(1, &decalTexture); glBindTexture(GL_TEXTURE_2D, decalTexture); glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA8, decalImage.width, decalImage.height, 0, decalImage.format, GL_UNSIGNED_BYTE, decalImage.data); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); //Create light textures if(!InitLightTextures( atten1DTexture, atten2DTexture, atten3DTexture, gaussian1DTexture, gaussian2DTexture)) return false; camera.Init(VECTOR3D(0.0f, 0.0f, 3.5f)); //reset timer for start timer.Reset(); return true; }
void StateGraphicsNext(int state) { if (StateGraphics == state) { return; } StateGraphicsTimer.Reset(); StateGraphicsLast = StateGraphics; StateGraphics = state; // The visual target first appears in this state, so set graphics sync timer. if (StateGraphics == STATE_GO) { // Set graphics sync timer relative to offset of next vertical retrace. GraphicsTargetTimer.Reset(-GRAPHICS_VerticalRetraceOffsetTimeUntilNext()); } }
//Set up variables bool DemoInit() { //Demo initialisation here //reset timer timer.Reset(); return true; }
void StateNext(int state) { if (State == state) { return; } printf("STATE: %s[%d] > %s[%d] (%.0lf msec).\n", StateText[State], State, StateText[state], state, StateTimer.Elapsed()); StateTimer.Reset(); StateLast = State; State = state; }
//Set up variables bool DemoInit() { if(!window.Init("Render To Texture", 640, 480, 32, 24, 8, WINDOWED_SCREEN)) return 0; //quit if not created camera.Init(VECTOR3D(0.0f, 0.0f, -2.5f), 2.0f, 100.0f); //Set up extensions if( !SetUpWGL_ARB_extensions_string()) return false; SetUpEXT_texture_filter_anisotropic(); SetUpSGIS_generate_mipmap(); //Get the WGL extensions string const char * wglExtensions; wglExtensions=wglGetExtensionsStringARB(window.hDC); //Set up wgl extensions if( !SetUpWGL_ARB_pbuffer(wglExtensions) || !SetUpWGL_ARB_pixel_format(wglExtensions) || !SetUpWGL_ARB_render_texture(wglExtensions)) return false; //Init the pbuffer int pbufferExtraIAttribs[]={WGL_BIND_TO_TEXTURE_RGBA_ARB, true, 0}; int pbufferFlags[]={WGL_TEXTURE_FORMAT_ARB, WGL_TEXTURE_RGBA_ARB, WGL_TEXTURE_TARGET_ARB, WGL_TEXTURE_2D_ARB, //request mipmap space if mipmaps are to be used SGIS_generate_mipmap_supported ? WGL_MIPMAP_TEXTURE_ARB : 0, SGIS_generate_mipmap_supported ? true : 0, 0}; if(!pbuffer.Init(pbufferSize, pbufferSize, 32, 24, 8, 1, pbufferExtraIAttribs, pbufferFlags)) return false; //Create the texture object to relate to the pbuffer glGenTextures(1, &pbufferTexture); glBindTexture(GL_TEXTURE_2D, pbufferTexture); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); //Use generated mipmaps if supported if(SGIS_generate_mipmap_supported) { glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP_SGIS, true); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); glHint(GL_GENERATE_MIPMAP_HINT_SGIS, GL_NICEST); useMipmapFilter=true; } //Use maximum anisotropy if supported if(EXT_texture_filter_anisotropic_supported) { glGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &maxAnisotropy); currentAnisotropy=maxAnisotropy; glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, currentAnisotropy); } //Load the decal texture //Note: This MUST be done when the pbuffer is the current context pbuffer.MakeCurrent(); IMAGE decalImage; decalImage.Load("decal.bmp"); glGenTextures(1, &decalTexture); glBindTexture(GL_TEXTURE_2D, decalTexture); glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA8, decalImage.width, decalImage.height, 0, decalImage.format, GL_UNSIGNED_BYTE, decalImage.data); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); //reset timer for start timer.Reset(); return true; }
//Set up variables bool DemoInit() { if(!window.Init("Project Template", 640, 480, 32, 24, 8, WINDOWED_SCREEN)) return 0; //quit if not created SetUpARB_multitexture(); SetUpARB_texture_cube_map(); SetUpEXT_texture_edge_clamp(); SetUpNV_register_combiners(); SetUpNV_register_combiners2(); SetUpNV_vertex_program(); //Check for necessary extensions if( !ARB_multitexture_supported || !ARB_texture_cube_map_supported || !EXT_texture_edge_clamp_supported || !NV_register_combiners_supported || !NV_vertex_program_supported) return false; //Check for single-pass chromatic aberration states GLint maxTextureUnits; glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, &maxTextureUnits); if( NV_register_combiners2_supported && maxTextureUnits>=4) { errorLog.OutputSuccess("Single Pass Chromatic Aberration Supported!"); pathOneSupported=true; renderPath=CHROMATIC_SINGLE; } camera.Init(VECTOR3D(0.0f, 0.0f, 4.0f), 2.5f, 10.0f); if( !cubeMapPosX.Load("cube_face_posx.tga") || !cubeMapNegX.Load("cube_face_negx.tga") || !cubeMapPosY.Load("cube_face_posy.tga") || !cubeMapNegY.Load("cube_face_negy.tga") || !cubeMapPosZ.Load("cube_face_posz.tga") || !cubeMapNegZ.Load("cube_face_negz.tga")) return false; //Build a texture from the data glGenTextures(1, &cubeMapTexture); //Generate Texture ID glBindTexture(GL_TEXTURE_CUBE_MAP_ARB, cubeMapTexture); //Bind texture glTexImage2D( GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB, 0, GL_RGBA8, cubeMapPosX.width, cubeMapPosX.height, 0, cubeMapPosX.format, GL_UNSIGNED_BYTE, cubeMapPosX.data); glTexImage2D( GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB, 0, GL_RGBA8, cubeMapNegX.width, cubeMapNegX.height, 0, cubeMapNegX.format, GL_UNSIGNED_BYTE, cubeMapNegX.data); glTexImage2D( GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB, 0, GL_RGBA8, cubeMapPosY.width, cubeMapPosY.height, 0, cubeMapPosY.format, GL_UNSIGNED_BYTE, cubeMapPosY.data); glTexImage2D( GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB, 0, GL_RGBA8, cubeMapNegY.width, cubeMapNegY.height, 0, cubeMapNegY.format, GL_UNSIGNED_BYTE, cubeMapNegY.data); glTexImage2D( GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB, 0, GL_RGBA8, cubeMapPosZ.width, cubeMapPosZ.height, 0, cubeMapPosZ.format, GL_UNSIGNED_BYTE, cubeMapPosZ.data); glTexImage2D( GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB, 0, GL_RGBA8, cubeMapNegZ.width, cubeMapNegZ.height, 0, cubeMapNegZ.format, GL_UNSIGNED_BYTE, cubeMapNegZ.data); glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_MIN_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); glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE); //reset timer for start timer.Reset(); return true; }
//Called for initiation bool Init(void) { //Check for necessary extensions if(!GLEE_ARB_depth_texture || !GLEE_ARB_shadow) { printf("I require ARB_depth_texture and ARB_shadow extensionsn\n"); return false; } //Load identity modelview glMatrixMode(GL_MODELVIEW); glLoadIdentity(); //Shading states glShadeModel(GL_SMOOTH); glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glColor4f(1.0f, 1.0f, 1.0f, 1.0f); glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); //Depth states glClearDepth(1.0f); glDepthFunc(GL_LEQUAL); glEnable(GL_DEPTH_TEST); glEnable(GL_CULL_FACE); //We use glScale when drawing the scene glEnable(GL_NORMALIZE); //Create the shadow map texture glGenTextures(1, &shadowMapTexture); glBindTexture(GL_TEXTURE_2D, shadowMapTexture); glTexImage2D( GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, shadowMapSize, shadowMapSize, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, NULL); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); //Use the color as the ambient and diffuse material glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE); glEnable(GL_COLOR_MATERIAL); //White specular material color, shininess 16 glMaterialfv(GL_FRONT, GL_SPECULAR, white); glMaterialf(GL_FRONT, GL_SHININESS, 16.0f); //Calculate & save matrices glPushMatrix(); glLoadIdentity(); gluPerspective(45.0f, (float)windowWidth/windowHeight, 1.0f, 100.0f); glGetFloatv(GL_MODELVIEW_MATRIX, cameraProjectionMatrix); glLoadIdentity(); gluLookAt(cameraPosition.x, cameraPosition.y, cameraPosition.z, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f); glGetFloatv(GL_MODELVIEW_MATRIX, cameraViewMatrix); glLoadIdentity(); gluPerspective(45.0f, 1.0f, 2.0f, 8.0f); glGetFloatv(GL_MODELVIEW_MATRIX, lightProjectionMatrix); glLoadIdentity(); gluLookAt( lightPosition.x, lightPosition.y, lightPosition.z, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f); glGetFloatv(GL_MODELVIEW_MATRIX, lightViewMatrix); glPopMatrix(); //Reset timer timer.Reset(); return true; }
//Set up variables bool DemoInit() { //Seed random number generator srand( (unsigned)time( NULL ) ); //Initialise the array of vertices numVertices=gridDensity*gridDensity; vertices=new SIMPLE_VERTEX[numVertices]; if(!vertices) { LOG::Instance()->OutputError("Unable to allocate space for %d vertices", numVertices); return false; } for(int i=0; i<gridDensity; ++i) { for(int j=0; j<gridDensity; ++j) { vertices[i*gridDensity+j].position.Set( (float(i)/(gridDensity-1))*2-1, 0.0f, (float(j)/(gridDensity-1))*2-1); vertices[i*gridDensity+j].normal.Set( 0.0f, 1.0f, 0.0f); vertices[i*gridDensity+j].texCoords.Set( (float(i)/(gridDensity-1)), -(float(j)/(gridDensity-1))); } } //Initialise the indices numIndices=2*(gridDensity)*(gridDensity-1); indices=new GLuint[numIndices]; if(!indices) { LOG::Instance()->OutputError("Unable to allocate space for %d indices", numIndices); return false; } for(int i=0; i<gridDensity-1; ++i) { for(int j=0; j<gridDensity; ++j) { indices[(i*gridDensity+j)*2 ]=(i+1)*gridDensity+j; indices[(i*gridDensity+j)*2+1]=i*gridDensity+j; } } //Load texture IMAGE floorImage; floorImage.Load("OpenGL.tga"); if(floorImage.paletted) floorImage.ExpandPalette(); glGenTextures(1, &floorTexture); glBindTexture(GL_TEXTURE_2D, floorTexture); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); gluBuild2DMipmaps( GL_TEXTURE_2D, GL_RGBA8, floorImage.width, floorImage.height, floorImage.format, GL_UNSIGNED_BYTE, floorImage.data); //Initialise the lights for(int i=0; i<numLights; ++i) { lights[i].position.Set( (float(rand())/RAND_MAX)*2-1, 0.02f, (float(rand())/RAND_MAX)*2-1); lights[i].velocity.Set( (float(rand())/RAND_MAX)*2-1, 0.0f, (float(rand())/RAND_MAX)*2-1); lights[i].color.Set( (float(rand())/RAND_MAX)*0.75f, (float(rand())/RAND_MAX)*0.75f, (float(rand())/RAND_MAX)*0.75f, 1.0f); } //Load vertex programs if(GLEE_NV_vertex_program) { glGenProgramsNV(1, &vp1); glBindProgramNV(GL_VERTEX_PROGRAM_NV, vp1); LoadARB_program(GL_VERTEX_PROGRAM_NV, "vp1.txt"); } if(GLEE_NV_vertex_program2) { glGenProgramsNV(1, &vp2); glBindProgramNV(GL_VERTEX_PROGRAM_NV, vp2); LoadARB_program(GL_VERTEX_PROGRAM_NV, "vp2.txt"); } if(GLEE_NV_vertex_program || GLEE_NV_vertex_program2) { //Track modelview-projection matrix glTrackMatrixNV(GL_VERTEX_PROGRAM_NV, 0, GL_MODELVIEW_PROJECTION_NV, GL_IDENTITY_NV); } //reset timer timer.Reset(); return true; }
//Set up variables bool DemoInit() { SetUpARB_multitexture(); SetUpARB_texture_cube_map(); SetUpEXT_compiled_vertex_array(); SetUpEXT_texture_edge_clamp(); SetUpNV_register_combiners(); SetUpNV_vertex_program(); SetUpNV_texture_shader(); if( !GL_ARB_texture_cube_map || !GL_EXT_compiled_vertex_array || !GL_ARB_multitexture || !GL_NV_register_combiners || !GL_NV_vertex_program || !GL_EXT_texture_edge_clamp) return false; //Get some useful info int maxTextureUnitsARB; glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, &maxTextureUnitsARB); int maxGeneralCombinersNV; glGetIntegerv(GL_MAX_GENERAL_COMBINERS_NV, &maxGeneralCombinersNV); if( GL_NV_texture_shader && maxTextureUnitsARB>=4 && maxGeneralCombinersNV>=4) { Util::log("Higher Quality bump mapping supported"); paths1And2Supported=true; currentTechnique=TEXTURE_LOOKUP; } else Util::log("Higher Quality bump mapping unsupported"); //Load Textures //normal map - put gloss map in alpha normalMapImage.Load("Normal Map.bmp"); normalMapImage.LoadAlphaTGA("gloss.tga"); glGenTextures(1, &normalMapTexture); glBindTexture(GL_TEXTURE_2D, normalMapTexture); glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA8, normalMapImage.width, normalMapImage.height, 0, normalMapImage.format, GL_UNSIGNED_BYTE, normalMapImage.data); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); //decal decalImage.Load("Decal.bmp"); glGenTextures(1, &decalTexture); glBindTexture(GL_TEXTURE_2D, decalTexture); glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA8, decalImage.width, decalImage.height, 0, decalImage.format, GL_UNSIGNED_BYTE, decalImage.data); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); //Create normalisation cube map glGenTextures(1, &normalisationCubeMap); glBindTexture(GL_TEXTURE_CUBE_MAP_ARB, normalisationCubeMap); GenerateNormalisationCubeMap(); glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_MIN_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); glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE); if(paths1And2Supported) { //Create signed normap map //Create space for signed data GLbyte * signedData=new GLbyte[normalMapImage.width*normalMapImage.height*3]; if(!signedData) { Util::log("Unable to allocate memory for signed normal map data"); return false; } //Convert unsigned to signed RGB data, ignoring alpha for(unsigned int i=0; i<normalMapImage.width*normalMapImage.height; i++) { for(unsigned int j=0; j<3; j++) { signedData[i*3+j]=normalMapImage.data[i*4+j]-128; } } glGenTextures(1, &signedNormalMap); glBindTexture(GL_TEXTURE_2D, signedNormalMap); glTexImage2D( GL_TEXTURE_2D, 0, GL_SIGNED_RGBA8_NV, normalMapImage.width, normalMapImage.height, 0, GL_RGB, GL_BYTE, signedData); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); if(signedData) delete [] signedData; signedData=NULL; } //make sure texImage2D is finished with normalMapImage before we change the image glFinish(); //Flatten the bumps in the normal map for(unsigned int i=0; i<normalMapImage.width*normalMapImage.height; ++i) { normalMapImage.data[i*4]=128; normalMapImage.data[i*4+1]=128; normalMapImage.data[i*4+2]=255; } //create flat normal map with gloss map in alpha glGenTextures(1, &flatNormalMap); glBindTexture(GL_TEXTURE_2D, flatNormalMap); glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA8, normalMapImage.width, normalMapImage.height, 0, normalMapImage.format, GL_UNSIGNED_BYTE, normalMapImage.data); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); if(paths1And2Supported) { //Create signed flat normap map //Create space for signed data GLbyte * signedData=new GLbyte[normalMapImage.width*normalMapImage.height*3]; if(!signedData) { Util::log("Unable to allocate memory for signed normal map data"); return false; } //Convert unsigned to signed RGB data, ignoring alpha for(unsigned int i=0; i<normalMapImage.width*normalMapImage.height; i++) { for(unsigned int j=0; j<3; j++) { signedData[i*3+j]=normalMapImage.data[i*4+j]-128; } } glGenTextures(1, &signedFlatNormalMap); glBindTexture(GL_TEXTURE_2D, signedFlatNormalMap); glTexImage2D( GL_TEXTURE_2D, 0, GL_SIGNED_RGBA8_NV, normalMapImage.width, normalMapImage.height, 0, GL_RGB, GL_BYTE, signedData); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); if(signedData) delete [] signedData; signedData=NULL; //Create specular ramp texture unsigned char specularRampValues[256]; for(unsigned int i=0; i<256; i++) { double poweredValue=(double)i/255; //raise to 16th power poweredValue= poweredValue*poweredValue*poweredValue*poweredValue* poweredValue*poweredValue*poweredValue*poweredValue* poweredValue*poweredValue*poweredValue*poweredValue* poweredValue*poweredValue*poweredValue*poweredValue; specularRampValues[i] = char(poweredValue*255); } glGenTextures(1, &specularRamp); glBindTexture(GL_TEXTURE_2D, specularRamp); glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA8, 256, 1, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, specularRampValues); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); } //reset timer for start timer.Reset(); return true; }
void StateProcess(void) { double d; // Check that robot is in a safe state. if (!ROBOT_Safe(ROBOT_ID)) { printf("Robot not safe.\n"); ProgramExit(); } // Special processing while a trial is running. if (TrialRunning) { if (!RobotActive()) { // If robot is not active, abort current trial. ErrorRobotInactive(); TrialAbort(); MissTrial(); } else if (FrameData.Full()) { // Abort current trail if frame data is full. ErrorFrameDataFull(); TrialAbort(); MissTrial(); } } // Some states are processing in the LoopTask. if (StateLoopTask[State]) { return; } // State processing. switch (State) { case STATE_INITIALIZE: // Initialization state. if (TargetTestFlag) { break; } ExperimentTimer.Reset(); StateNext(STATE_SETUP); break; case STATE_SETUP: // Setup details of next trial, but only when robot stationary and active. if (RobotNotMoving() && RobotActive()) { printf("Dynamic learning: before Trialsetup i am here=====!!!!\n"); TrialSetup(); StateNext(STATE_HOME); } break; case STATE_HOME: // Start trial when robot in home position (and stationary and active). if (RobotNotMoving() && RobotHome() && RobotActive()) { StateNext(STATE_START); break; } break; case STATE_START: // Start trial. TrialStart(); StateNext(STATE_DELAY); break; case STATE_DELAY: // Delay period before go signal. if (StateTimer.ExpiredSeconds(TrialDelay)) { StateNext(STATE_GO); break; } if (MovementStarted()) { ErrorMoveTooSoon(); TrialAbort(); MissTrial(); } break; case STATE_GO: // Wait until graphics state matches. if (State != StateGraphics) { break; } StateNext(STATE_TARGETWAIT); break; case STATE_TARGETWAIT: // Wait for estimated target display delay. if (GraphicsTargetTimer.ExpiredSeconds(GRAPHICS_DisplayDelayTarget(TargetPosition))) { // Target should be displayed now (within a few milliseconds). TriggerOn(); MovementReactionTimer.Reset(); BeepGo(); StateNext(STATE_MOVEWAIT); } break; case STATE_MOVEWAIT: // Process in the robot forces function (LoopTask) break; case STATE_MOVING: // Process in the robot forces function (LoopTask) break; case STATE_FINISH: // Trial has finished so stop trial. TrialStop(); // Save the data for this trial. if (!TrialSave()) { printf("Cannot save Trial %d.\n", Trial); StateNext(STATE_EXIT); break; } // Catch too-slow trials. if (MovementDurationTime >= MovementDurationTimeOut) { ErrorMoveTimeOut(); BeepError(); InterTrialDelayTimer.Reset(); } // Go to next trial, if there is one. if (TrialNext()) { StateNext(STATE_INTERTRIAL); } else { StateNext(STATE_EXIT); } break; case STATE_INTERTRIAL: // Wait for the intertrial delay to expire. if (!InterTrialDelayTimer.ExpiredSeconds(InterTrialDelay)) { break; } MessageClear(); // Optional rest between blocks of trials. if (RestTrials != 0) { // Rest every X number of trials. if ((Trial % RestTrials) == 0) { StateNext(STATE_REST); break; } } StateNext(STATE_SETUP); break; case STATE_EXIT: ProgramExit(); break; case STATE_TIMEOUT: switch (StateLast) // Which state had the timeout? { case STATE_MOVEWAIT: ErrorMoveWaitTimeOut(); break; case STATE_MOVING: ErrorMoveTimeOut(); break; default: ErrorMessage(STR_stringf("%s TimeOut", StateText[StateLast])); break; } TrialAbort(); // Abort the current trial. MissTrial(); // Generate miss trial. break; case STATE_ERROR: if (StateTimer.ExpiredSeconds(ErrorWait)) { ErrorResume(); } break; case STATE_REST: if (StateTimer.ExpiredSeconds(RestWait)) { StateNext(STATE_SETUP); } break; } }
BOOL TrialList(void) { int item, i; BOOL ok = TRUE; TotalTrials = 0; // Single or multiple configuration file paradigm? if (ConfigFiles == 1) { TotalTrials = Trials; ConfigIndex = 0; } else { // Loop over configuration files, counting the number of trials. for (ok = TRUE, ConfigIndex = 1; (ok && (ConfigIndex < ConfigFiles)); ConfigIndex++) { if (!ConfigLoad(ConfigFile[ConfigIndex])) { ok = FALSE; continue; } TotalTrials += Trials; printf("%d %s Trials=%d TotalTrials=%d\n", ConfigIndex, ConfigFile[ConfigIndex], Trials, TotalTrials); } ConfigIndex = 1; } if ((TotalTrials == 0) || !ok) { return(FALSE); } // Set rows of TrialData to the number of trials. TrialData.SetRows(TotalTrials); printf("Making list of %d trials (ESCape to abort)...\n", TotalTrials); TotalTrials = 0; TotalNullTrials = 0; TotalExposureTrials = 0; TotalCatchTrials = 0; // Loop over configuration files, appending each to growing trial list. for (ok = TRUE; (ok && (ConfigIndex < ConfigFiles)); ConfigIndex++) { if (ConfigIndex > 0) { if (!ConfigLoad(ConfigFile[ConfigIndex])) { ok = FALSE; continue; } } // Create subset of trials for this configuration file. if (!TrialListSubset()) { ok = FALSE; continue; } TotalTrials += Trials; TotalNullTrials += NullTrial; TotalExposureTrials += ExposureTrial; TotalCatchTrials += CatchTrial; printf("%d %s Trials=%d TotalTrials=%d\n", ConfigIndex, ConfigFile[ConfigIndex], Trials, TotalTrials); } if (!ok) { return(FALSE); } printf("%d Total Trials, %d Null, %d Exposure, %d Catch.\n", TotalTrials, TotalNullTrials, TotalExposureTrials, TotalCatchTrials); // Total number of trails. Trials = TotalTrials; // Save trial list to file. ok = DATAFILE_Save(TrialListFile, TrialData); printf("%s %s Trials=%d.\n", TrialListFile, STR_OkFailed(ok), TrialData.GetRows()); // Reset trial number, etc. Trial = 1; TrialSetup(); ExperimentTimer.Reset(); StateNext(STATE_INITIALIZE); return(TRUE); }