static void gear(GLfloat inner_radius, GLfloat outer_radius, GLfloat width, GLint teeth, GLfloat tooth_depth) { GLint i; GLfloat r0, r1, r2; GLfloat angle, da; GLfloat u, v, len; r0 = inner_radius; r1 = outer_radius - tooth_depth / 2.0; r2 = outer_radius + tooth_depth / 2.0; da = 2.0 * M_PI / teeth / 4.0; glShadeModel(GL_FLAT); glNormal3f(0.0, 0.0, 1.0); /* draw front face */ glBegin(GL_QUAD_STRIP); for (i = 0; i <= teeth; i++) { angle = i * 2.0 * M_PI / teeth; glVertex3f(r0 * cos(angle), r0 * sin(angle), width * 0.5); glVertex3f(r1 * cos(angle), r1 * sin(angle), width * 0.5); if (i < teeth) { glVertex3f(r0 * cos(angle), r0 * sin(angle), width * 0.5); glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), width * 0.5); } } glEnd(); /* draw front sides of teeth */ glBegin(GL_QUADS); da = 2.0 * M_PI / teeth / 4.0; for (i = 0; i < teeth; i++) { angle = i * 2.0 * M_PI / teeth; glVertex3f(r1 * cos(angle), r1 * sin(angle), width * 0.5); glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), width * 0.5); glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da), width * 0.5); glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), width * 0.5); } glEnd(); glNormal3f(0.0, 0.0, -1.0); /* draw back face */ glBegin(GL_QUAD_STRIP); for (i = 0; i <= teeth; i++) { angle = i * 2.0 * M_PI / teeth; glVertex3f(r1 * cos(angle), r1 * sin(angle), -width * 0.5); glVertex3f(r0 * cos(angle), r0 * sin(angle), -width * 0.5); if (i < teeth) { glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), -width * 0.5); glVertex3f(r0 * cos(angle), r0 * sin(angle), -width * 0.5); } } glEnd(); /* draw back sides of teeth */ glBegin(GL_QUADS); da = 2.0 * M_PI / teeth / 4.0; for (i = 0; i < teeth; i++) { angle = i * 2.0 * M_PI / teeth; glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), -width * 0.5); glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da), -width * 0.5); glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), -width * 0.5); glVertex3f(r1 * cos(angle), r1 * sin(angle), -width * 0.5); } glEnd(); /* draw outward faces of teeth */ glBegin(GL_QUAD_STRIP); for (i = 0; i < teeth; i++) { angle = i * 2.0 * M_PI / teeth; glVertex3f(r1 * cos(angle), r1 * sin(angle), width * 0.5); glVertex3f(r1 * cos(angle), r1 * sin(angle), -width * 0.5); u = r2 * cos(angle + da) - r1 * cos(angle); v = r2 * sin(angle + da) - r1 * sin(angle); len = sqrt(u * u + v * v); u /= len; v /= len; glNormal3f(v, -u, 0.0); glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), width * 0.5); glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), -width * 0.5); glNormal3f(cos(angle), sin(angle), 0.0); glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da), width * 0.5); glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da), -width * 0.5); u = r1 * cos(angle + 3 * da) - r2 * cos(angle + 2 * da); v = r1 * sin(angle + 3 * da) - r2 * sin(angle + 2 * da); glNormal3f(v, -u, 0.0); glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), width * 0.5); glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), -width * 0.5); glNormal3f(cos(angle), sin(angle), 0.0); } glVertex3f(r1 * cos(0), r1 * sin(0), width * 0.5); glVertex3f(r1 * cos(0), r1 * sin(0), -width * 0.5); glEnd(); glShadeModel(GL_SMOOTH); /* draw inside radius cylinder */ glBegin(GL_QUAD_STRIP); for (i = 0; i <= teeth; i++) { angle = i * 2.0 * M_PI / teeth; glNormal3f(-cos(angle), -sin(angle), 0.0); glVertex3f(r0 * cos(angle), r0 * sin(angle), -width * 0.5); glVertex3f(r0 * cos(angle), r0 * sin(angle), width * 0.5); } glEnd(); }
void display() { glClearColor(0.6, 0.75, 0.85, 1); // sky color is light blue glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); /* Clear The Screen And The Depth Buffer */ if(view==0) { display1(); } else if (view==1) { display2(); } else if(view==2) { // Erase the window and the depth buffer glClearColor(0.6, 0.75, 0.85, 1); // sky color is light blue glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); // Enable Z-buffering in OpenGL glEnable(GL_DEPTH_TEST); glCullFace(GL_BACK); glLoadIdentity(); // Set the look at position for perspective projection gluLookAt( Ex, Ey, Ez, Ex + lx, Ey, Ez+lz, 0.0, 1, 0.0); glShadeModel(GL_SMOOTH); glDisable(GL_DEPTH_TEST); glDepthMask(GL_FALSE); glPushMatrix(); glTranslatef( Ex + lx, 0, Ez+lz-4); Sky(1000); glPopMatrix(); glDepthMask(GL_TRUE); glEnable(GL_DEPTH_TEST); // Light switch if (light) { // Translate intensity to color vectors float Ambient[] = {0.01*ambient ,0.01*ambient ,0.01*ambient ,1.0}; float Diffuse[] = {0.01*diffuse ,0.01*diffuse ,0.01*diffuse ,1.0}; float Specular[] = {0.01*specular,0.01*specular,0.01*specular,1.0}; // Light position float Position[]={0,1000,5000}; // Draw light position as ball (still no lighting here) glColor3f(1,1,1); ball(Position[0],Position[1],Position[2] , 0.2); // OpenGL should normalize normal vectors glEnable(GL_NORMALIZE); // Enable lighting glEnable(GL_LIGHTING); // glColor sets ambient and diffuse color materials glColorMaterial(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE); glEnable(GL_COLOR_MATERIAL); // Enable light 0 glEnable(GL_LIGHT0); // Set ambient, diffuse, specular components and position of light 0 glLightfv(GL_LIGHT0,GL_AMBIENT ,Ambient); glLightfv(GL_LIGHT0,GL_DIFFUSE ,Diffuse); glLightfv(GL_LIGHT0,GL_SPECULAR,Specular); glLightfv(GL_LIGHT0,GL_POSITION,Position); } else glDisable(GL_LIGHTING); if(opt==1) { glPushMatrix(); glTranslatef( Ex + lx,0, Ez+lz-4); glRotatef(90, 1, 0, 0); glRotatef(180, 0, 1, 0); glColor3f(1,1,1); glCallList(car1); glPopMatrix(); int E=Ez+lz-4; if(E<=40) { Ex=0; Ez=1000; lx=0; lz=-1; } } else if(opt==2) { glPushMatrix(); glTranslatef( Ex + lx, 0, Ez+lz-4); glRotatef(90, 1, 0, 0); glRotatef(180, 0, 1, 0); glColor3f(1,1,1); glCallList(car2); glPopMatrix(); int E=Ez+lz-4; if(E<=40) { Ex=0; Ez=1000; lx=0; lz=-1; } } cylinder(); Road(); for(i=0; i<=1000; i+=40) { glPushMatrix(); glTranslated(-50,10,i); glScaled(50,50,50); Tree(); glPopMatrix(); } for(i=0; i<=1000; i+=40) { glPushMatrix(); glTranslated(170,10,i); glScaled(50,50,50); Tree(); glPopMatrix(); } for(i=0; i<=1000; i+=60) { glPushMatrix(); glTranslated(-70,-10,i); glScaled(2,10,10); Lamp(); glPopMatrix(); } for(i=0; i<=1000; i+=60) { glPushMatrix(); glTranslated(70,-10,i); glRotated(90,0,1,0); glScaled(2,10,10); Lamp(); glPopMatrix(); } for(i=-60; i<=1000; i+=60) { glPushMatrix(); glTranslated(-38,86.5,i+43); glScaled(5,5,5); lights(); glPopMatrix(); } for(i=-60; i<=1000; i+=60) { glPushMatrix(); glTranslated(55,87,i+30); glScaled(5,5,5); lights(); glPopMatrix(); } for(i=0; i<=1000; i+=400) { glPushMatrix(); glTranslated(-50,-10,i); glScaled(10,10,10); trafficsignal(); glPopMatrix(); } for(i=0; i<=1000; i+=400) { glPushMatrix(); glTranslated(0,0,i+40); zebracrossing(); glPopMatrix(); } for(i=-60; i<=1000; i+=100) { glPushMatrix(); glTranslated(200,-15,i+30); glScaled(10,15,10); buildings(); glPopMatrix(); } for(i=-60; i<=1000; i+=100) { glPushMatrix(); glTranslated(-250,-15,i+30); glScaled(10,15,10); buildings(); glPopMatrix(); } for(i=-60; i<=1000; i+=100) { glPushMatrix(); glTranslated(350,-15,i+30); glScaled(10,30,10); buildings(); glPopMatrix(); } for(i=-60; i<=1000; i+=100) { glPushMatrix(); glTranslated(-400,-15,i+30); glScaled(10,30,10); buildings(); glPopMatrix(); } for(e=0; e<=1000; e+=155) { if(e%2==0) { glPushMatrix(); glTranslated(-16,-10,e); glScaled(6,6,6); roadpylon(); glPopMatrix(); } else { glPushMatrix(); glTranslated(16,-10,e); glScaled(6,6,6); roadpylon(); glPopMatrix(); } } for(i=0; i<=1000; i+=400) { glPushMatrix(); glTranslated(65,0,i); glScaled(10,10,10); roadsign(); glPopMatrix(); } xpos = xpos + xvel; if(xpos >= 30) { xvel = -xvel; } if( xpos <2) { xvel = -xvel; } glPushMatrix(); glTranslated(0,xpos,900); glRotated(-90,0,0,1); glRotated(-90,0,1,0); glScaled(2,2,2); glColor3f(1,1,1); glCallList(dragon); glPopMatrix(); glWindowPos2i(5,5); glColor3f(1,1,1); Print("Speed=%f",1,jump); } // Render the scene and make it visible ErrCheck("display"); glFlush(); glutSwapBuffers(); }
ENTRYPOINT void draw_gears (ModeInfo *mi) { gears_configuration *bp = &bps[MI_SCREEN(mi)]; Display *dpy = MI_DISPLAY(mi); Window window = MI_WINDOW(mi); int i; if (!bp->glx_context) return; glXMakeCurrent(MI_DISPLAY(mi), MI_WINDOW(mi), *(bp->glx_context)); glShadeModel(GL_SMOOTH); glEnable(GL_DEPTH_TEST); glEnable(GL_NORMALIZE); glEnable(GL_CULL_FACE); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glPushMatrix (); { double x, y, z; get_position (bp->rot, &x, &y, &z, !bp->button_down_p); glTranslatef ((x - 0.5) * 4, (y - 0.5) * 4, (z - 0.5) * 7); /* Do it twice because we don't track the device's orientation. */ glRotatef( current_device_rotation(), 0, 0, 1); gltrackball_rotate (bp->trackball); glRotatef(-current_device_rotation(), 0, 0, 1); get_rotation (bp->rot, &x, &y, &z, !bp->button_down_p); /* add a little rotation for -no-spin mode */ x -= 0.14; y -= 0.06; glRotatef (x * 360, 1.0, 0.0, 0.0); glRotatef (y * 360, 0.0, 1.0, 0.0); glRotatef (z * 360, 0.0, 0.0, 1.0); } /* Center the scene's bounding box in the window, and scale it to fit. */ { GLfloat w = bp->bbox.x2 - bp->bbox.x1; GLfloat h = bp->bbox.y2 - bp->bbox.y1; GLfloat s = 10.0 / (w > h ? w : h); glScalef (s, s, s); glTranslatef (-(bp->bbox.x1 + w/2), -(bp->bbox.y1 + h/2), 0); } mi->polygon_count = 0; for (i = 0; i < bp->ngears; i++) { gear *g = bp->gears[i]; glPushMatrix(); glTranslatef (g->x, g->y, g->z); glRotatef (g->th, 0, 0, 1); glCallList (g->dlist); mi->polygon_count += g->polygons; glPopMatrix (); } if (bp->planetary_p) { glCallList (bp->armature_dlist); mi->polygon_count += bp->armature_polygons; } glPopMatrix (); /* spin gears */ if (!bp->button_down_p) for (i = 0; i < bp->ngears; i++) { gear *g = bp->gears[i]; double off = g->ratio * 5 * speed; if (g->th > 0) g->th += off; else g->th -= off; } if (mi->fps_p) do_fps (mi); glFinish(); glXSwapBuffers(dpy, window); }
int main( ) { int running = GL_TRUE; CDLGetCurrentDirectory(); // Initialize GLFW if( !glfwInit() ) { exit( EXIT_FAILURE ); } glShadeModel(GL_SMOOTH); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glDisable(GL_DEPTH_TEST); //glEnable(GL_TEXTURE_2D); // Finally we can Open an OpenGL window if(!glfwOpenWindow ( 1024, 768, 1,0,0,0,0,0, GLFW_WINDOW )) { glfwTerminate(); exit( EXIT_FAILURE ); } glfwSetWindowTitle( TITLE );//Sets the Windows Name glfwSetWindowSizeCallback(handleResize); //callback function of GLFW to handle window resize glfwSetKeyCallback(handleKeypress); //callback function to handle key press glClearColor( 0.0f, 0.0f, 0.0f, 0.0f ); //clear background screen to black // Main loop while( running ) { //Clear information from last draw glClear( GL_COLOR_BUFFER_BIT| GL_DEPTH_BUFFER_BIT); glPushAttrib(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_MODELVIEW); //Switch to the drawing perspective glLoadIdentity(); //Reset the drawing perspective glBegin(GL_QUADS); glTexCoord2f(0,1); glVertex3f(-1, 1, -1); glTexCoord2f(1,1); glVertex3f( 1, 1, -1); glTexCoord2f(1,0); glVertex3f( 1,-1, -1); glTexCoord2f(0,0); glVertex3f(-1,-1, -1); glEnd(); //glDisable(GL_TEXTURE_2D); glPopAttrib(); glFlush(); glfwSwapBuffers(); // Check if ESC key was pressed or window was closed running = glfwGetWindowParam( GLFW_OPENED ); } // Close window and terminate GLFW glfwTerminate(); // Exit program exit( EXIT_SUCCESS ); }
bool World::Initialize(unsigned int windowWidth, unsigned int windowHeight, String windowName, bool antiAliasing, bool fullScreen, bool resizable) { if (_initialized) { return false; } _running = true; // Windows DLL locations #if defined(WIN32) && defined(NDEBUG) String bitsPath = "bits"; char currentDir[MAX_PATH]; _getcwd(currentDir, MAX_PATH); String currDir(currentDir); StringList libs; #if !ANGEL_DISABLE_DEVIL libs.push_back("DevIL.dll"); libs.push_back("ILU.dll"); libs.push_back("ILUT.dll"); #endif #if ANGEL_DISABLE_FMOD libs.push_back("OpenAL32.dll"); #else libs.push_back("fmodex.dll"); #endif for (int i=0; i < libs.size(); i++) { String libstring = currDir + "\\" + bitsPath + "\\" + libs[i]; HMODULE work = LoadLibrary(libstring.c_str()); if (work == 0) { DWORD err = GetLastError(); _com_error error(err); LPCSTR errorText = error.ErrorMessage(); sysLog.Printf("ERROR: Couldn't load DLL (%s); %s", libs[i].c_str(), errorText); } } // does bits directory exist? DWORD dwAttrib = GetFileAttributes(bitsPath.c_str()); if (dwAttrib != INVALID_FILE_ATTRIBUTES && dwAttrib & FILE_ATTRIBUTE_DIRECTORY) { _chdir(bitsPath.c_str()); } #endif // General windowing initialization #if !ANGEL_MOBILE glfwInit(); #endif #if defined(__APPLE__) // Set up paths correctly in the .app bundle #if !ANGEL_MOBILE CFBundleRef mainBundle = CFBundleGetMainBundle(); CFURLRef resourcesURL = CFBundleCopyResourcesDirectoryURL(mainBundle); char path[PATH_MAX]; if (!CFURLGetFileSystemRepresentation(resourcesURL, TRUE, (UInt8 *)path, PATH_MAX)) { sysLog.Log("ERROR: Problem setting up working directory! Probably nothing will work!"); } CFRelease(resourcesURL); chdir(path); chdir(".."); #if DEBUG // set paths to the local resources rather than the copied ones String fileName = __FILE__; String dirPath = fileName.substr(0, fileName.size() - String("Angel/Infrastructure/World.cpp").size()); CFURLRef exeURL = CFBundleCopyExecutableURL(mainBundle); char exePath[PATH_MAX]; if (!CFURLGetFileSystemRepresentation(exeURL, TRUE, (UInt8 *)exePath, PATH_MAX)) { sysLog.Log("ERROR: Problem setting up working directory! Probably nothing will work!"); } CFRelease(exeURL); chdir(dirPath.c_str()); StringList pathElements = SplitString(exePath, "/"); String exeName = pathElements[pathElements.size()-1]; chdir(exeName.c_str()); #endif #else CFBundleRef mainBundle = CFBundleGetMainBundle(); CFURLRef resourcesURL = CFBundleCopyResourcesDirectoryURL(mainBundle); char path[PATH_MAX]; if (!CFURLGetFileSystemRepresentation(resourcesURL, TRUE, (UInt8 *)path, PATH_MAX)) { std::cout << "Problem setting up working directory! Probably nothing will work!" << std::endl; } CFRelease(resourcesURL); chdir(path); chdir("Angel"); // the iPhone doesn't like having a "Resources" directory in the root of the .app bundle #endif #endif //Start scripting LuaScriptingModule::Prep(); //Reset values based on preferences antiAliasing = thePrefs.OverrideInt("WindowSettings", "antiAliasing", antiAliasing); fullScreen = thePrefs.OverrideInt("WindowSettings", "fullScreen", fullScreen); resizable = thePrefs.OverrideInt("WindowSettings", "resizable", resizable); windowHeight = thePrefs.OverrideInt("WindowSettings", "height", windowHeight); windowWidth = thePrefs.OverrideInt("WindowSettings", "width", windowWidth); windowName = thePrefs.OverrideString("WindowSettings", "name", windowName); //Windowing system setup #if !ANGEL_MOBILE if (antiAliasing) { glfwOpenWindowHint(GLFW_FSAA_SAMPLES, 4); //4x looks pretty good _antiAliased = true; } else { _antiAliased = false; } int windowMode = GLFW_WINDOW; if (fullScreen) { windowMode = GLFW_FULLSCREEN; } if (resizable) { glfwOpenWindowHint(GLFW_WINDOW_NO_RESIZE, GL_FALSE); } else { glfwOpenWindowHint(GLFW_WINDOW_NO_RESIZE, GL_TRUE); } glfwOpenWindow(windowWidth, windowHeight, 8, 8, 8, 8, 8, 1, windowMode); glfwSetWindowTitle(windowName.c_str()); glfwSetWindowPos(50, 50); #if defined(WIN32) glfwSwapInterval(0); // because double-buffering and Windows don't get along apparently #else glfwSwapInterval(1); #endif glfwSetWindowSizeCallback(Camera::ResizeCallback); glfwSetKeyCallback(keyboardInput); glfwSetCharCallback(charInput); glfwDisable(GLFW_KEY_REPEAT); glfwSetMousePosCallback(MouseMotion); glfwSetMouseButtonCallback(MouseButton); glfwSetMouseWheelCallback(MouseWheel); glfwSetWindowCloseCallback(windowClosed); _prevTime = glfwGetTime(); #else struct timeval tv; gettimeofday(&tv, NULL); _currTime = _startTime = tv.tv_sec + (double) tv.tv_usec / 1000000.0; #endif //OpenGL state setup #if !ANGEL_MOBILE glClearDepth(1.0f); glPolygonMode(GL_FRONT, GL_FILL); #else glEnable(GL_POLYGON_OFFSET_FILL); glPolygonOffset(1.0f, -1.0f); #endif glShadeModel(GL_FLAT); glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); glEnable(GL_CULL_FACE); glFrontFace(GL_CCW); glCullFace(GL_BACK); glDepthFunc(GL_LEQUAL); glEnable(GL_DEPTH_TEST); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glClearStencil(0); glClearColor(1.0f, 1.0f, 1.0f, 1.0f); theCamera.ResizeCallback(windowWidth, windowHeight); //Get textures going InitializeTextureLoading(); //Subscribe to camera changes theSwitchboard.SubscribeTo(this, "CameraChange"); //initialize singletons #if !ANGEL_MOBILE theInput; theControllerManager.Setup(); #endif theSound; theSpatialGraph; #if !ANGEL_MOBILE RegisterConsole(new TestConsole()); #else // register fonts, since we don't have the console doing it for us on the phone RegisterFont("Resources/Fonts/Inconsolata.otf", 24, "Console"); RegisterFont("Resources/Fonts/Inconsolata.otf", 18, "ConsoleSmall"); #endif LuaScriptingModule::Initialize(); return _initialized = true; }
static void init (void) { glEnable(GL_DEPTH_TEST); glShadeModel(GL_FLAT); }
void CShadowHandler::CreateShadows() { fb.Bind(); glDisable(GL_BLEND); glDisable(GL_LIGHTING); glDisable(GL_ALPHA_TEST); glDisable(GL_TEXTURE_2D); glShadeModel(GL_FLAT); glColor4f(1.0f, 1.0f, 1.0f, 1.0f); glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); glDepthMask(GL_TRUE); glEnable(GL_DEPTH_TEST); glViewport(0, 0, shadowMapSize, shadowMapSize); // glClearColor(0, 0, 0, 0); // glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClear(GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0, 1, 0, 1, 0, -1); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); const ISkyLight* L = sky->GetLight(); // sun direction is in world-space, invert it sunDirZ = -L->GetLightDir(); sunDirX = (sunDirZ.cross(UpVector)).ANormalize(); sunDirY = (sunDirX.cross(sunDirZ)).ANormalize(); SetShadowMapSizeFactors(); // NOTE: // the xy-scaling factors from CalcMinMaxView do not change linearly // or smoothly with camera movements, creating visible artefacts (eg. // large jumps in shadow resolution) // // therefore, EITHER use "fixed" scaling values such that the entire // map barely fits into the sun's frustum (by pretending it is embedded // in a sphere and taking its diameter), OR variable scaling such that // everything that can be seen by the camera maximally fills the sun's // frustum (choice of projection-style is left to the user and can be // changed at run-time) // // the first option means larger maps will have more blurred/aliased // shadows if the depth buffer is kept at the same size, but no (map) // geometry is ever omitted // // the second option means shadows have higher average resolution, but // become less sharp as the viewing volume increases (through eg.camera // rotations) and geometry can be omitted in some cases // // NOTE: // when DynamicSun is enabled, the orbit is always circular in the xz // plane, instead of elliptical when the map has an aspect-ratio != 1 // const float xyScale = (shadowProMode == SHADOWPROMODE_CAM_CENTER)? GetOrthoProjectedFrustumRadius(camera, centerPos): (shadowProMode == SHADOWPROMODE_MAP_CENTER)? GetOrthoProjectedMapRadius(-sunDirZ, centerPos): 1.0f; const float xScale = xyScale; const float yScale = xyScale; const float zScale = globalRendering->viewRange; shadowMatrix[ 0] = sunDirX.x / xScale; shadowMatrix[ 1] = sunDirY.x / yScale; shadowMatrix[ 2] = sunDirZ.x / zScale; shadowMatrix[ 4] = sunDirX.y / xScale; shadowMatrix[ 5] = sunDirY.y / yScale; shadowMatrix[ 6] = sunDirZ.y / zScale; shadowMatrix[ 8] = sunDirX.z / xScale; shadowMatrix[ 9] = sunDirY.z / yScale; shadowMatrix[10] = sunDirZ.z / zScale; // rotate the target position into sun-space for the translation shadowMatrix[12] = (-sunDirX.dot(centerPos) / xScale); shadowMatrix[13] = (-sunDirY.dot(centerPos) / yScale); shadowMatrix[14] = (-sunDirZ.dot(centerPos) / zScale) + 0.5f; glLoadMatrixf(shadowMatrix.m); // set the shadow-parameter registers // NOTE: so long as any part of Spring rendering still uses // ARB programs at run-time, these lines can not be removed // (all ARB programs share the same environment) glProgramEnvParameter4fARB(GL_VERTEX_PROGRAM_ARB, 16, shadowTexProjCenter.x, shadowTexProjCenter.y, 0.0f, 0.0f); glProgramEnvParameter4fARB(GL_VERTEX_PROGRAM_ARB, 17, shadowTexProjCenter.z, shadowTexProjCenter.z, 0.0f, 0.0f); glProgramEnvParameter4fARB(GL_VERTEX_PROGRAM_ARB, 18, shadowTexProjCenter.w, shadowTexProjCenter.w, 0.0f, 0.0f); if (globalRendering->haveGLSL) { for (int i = 0; i < SHADOWGEN_PROGRAM_LAST; i++) { shadowGenProgs[i]->Enable(); shadowGenProgs[i]->SetUniform4fv(0, &shadowTexProjCenter.x); shadowGenProgs[i]->Disable(); } } if (L->GetLightIntensity() > 0.0f) { // move view into sun-space const float3 oldup = camera->up; camera->right = sunDirX; camera->up = sunDirY; DrawShadowPasses(); camera->up = oldup; } glShadeModel(GL_SMOOTH); glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); // we do this later to save render context switches (this is one of the slowest opengl operations!) // fb.Unbind(); // glViewport(globalRendering->viewPosX,0,globalRendering->viewSizeX,globalRendering->viewSizeY); }
void init(void) { glClearColor (0.0, 0.0, 0.0, 0.0); glShadeModel (GL_FLAT); }
void RendererComponent::Impl::render(Entity& entityTree, RenderTargetComponent& renderTarget) { glShadeModel(GL_SMOOTH); glFrontFace(GL_CCW); // OpenGl use counterclockwise as the default winding glEnable(GL_DEPTH_TEST); glEnable(GL_RESCALE_NORMAL); glEnable(GL_TEXTURE_2D); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); // Tell OpenGl use origin of the eye coordinate rather than simply z axis to calculate the specular angle // Ref: http://gregs-blog.com/2007/12/21/theres-nothing-wrong-with-opengls-specular-lighting/ glLightModelf(GL_LIGHT_MODEL_LOCAL_VIEWER, 1.0f); // Seems make better specular lighting glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SEPARATE_SPECULAR_COLOR); mCurrentRenderTarget = &renderTarget; { // Apply camera CameraComponentPtr camera = renderTarget.cameraComponent; if(!camera) return; Entity* cameraEntity = camera->entity(); if(!cameraEntity) return; mCurrentCamera = camera.getNotNull(); camera->frustum.computeProjection(mProjMatrix.data); mCameraTransform = cameraEntity->worldTransform(); mViewMatrix = mCameraTransform.inverse(); mViewProjMatrix = mProjMatrix * mViewMatrix; glMatrixMode(GL_PROJECTION); glLoadMatrixf(mProjMatrix.data); glMatrixMode(GL_MODELVIEW); glLoadMatrixf(mViewMatrix.data); } // Traverse the Entity tree traverseEntities(entityTree); // Set up lighting static const size_t cMaxHardwareLight = 8; for(size_t i=0; i<cMaxHardwareLight; ++i) { const int iLight = GL_LIGHT0 + i; if(i < mLights.size()) { const LightComponent* light = mLights[i]; MCD_ASSUME(light); glEnable(iLight); const ColorRGBAf ambient(0, 1); const ColorRGBAf diffuse(light->color, 1); glLightfv(iLight, GL_AMBIENT, ambient.rawPointer()); glLightfv(iLight, GL_DIFFUSE, diffuse.rawPointer()); glLightfv(iLight, GL_SPECULAR, diffuse.rawPointer()); Entity* e = light->entity(); MCD_ASSUME(e); const Vec3f pos = e->worldTransform().translation(); GLfloat lightPos[] = { pos.x, pos.y, pos.z, 1.0f }; glLightfv(iLight, GL_POSITION, lightPos); } else glDisable(iLight); } { // Disable lighting if there is no LightComponent if(mLights.empty()) glDisable(GL_LIGHTING); else glEnable(GL_LIGHTING); } { // Render opaque items processRenderItems(mOpaqueQueue, mStatistic.opaque, mStatistic.materialSwitch); } { // Render transparent items glEnable(GL_BLEND); glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glBlendEquationSeparate(GL_FUNC_ADD, GL_FUNC_ADD); glDepthMask(GL_FALSE); processRenderItems(mTransparentQueue, mStatistic.transparent, mStatistic.materialSwitch); glDisable(GL_BLEND); glDepthMask(GL_TRUE); } // Reset the last material if(mLastMaterial) { mLastMaterial->postRender(0, this); mLastMaterial = nullptr; } mLights.clear(); mCurrentCamera = nullptr; mOpaqueQueue.destroyAll(); mTransparentQueue.destroyAll(); }
void init(int argc,char **filename) { count = argc-1; if(count == 0){ exit(0); } if((imageWidth = (GLsizei*)malloc(count * sizeof(GLsizei)))==NULL) { printf("error: could not allocate memory"); exit(0); } if((imageHeight = (GLsizei*)malloc(count * sizeof(GLsizei)))==NULL) { printf("error: could not allocate memory"); exit(0); } if((imageDepth = (GLsizei*)malloc(count * sizeof(GLsizei)))==NULL) { printf("error: could not allocate memory"); exit(0); } if((imageFormat = (GLenum*)malloc(count * sizeof(GLenum)))==NULL) { printf("error: could not allocate memory"); exit(0); } if((texName = (GLuint*)malloc(count * sizeof(GLuint)))==NULL) { printf("error: could not allocate memory"); exit(0); } if((image = (GLubyte**)malloc(count * sizeof(GLubyte*)))==NULL) { printf("error: could not allocate memory"); exit(0); } for (int i; i<count; i++){ image[i] = NULL; } glClearColor (0.0, 0.0, 0.0, 0.0); glShadeModel(GL_FLAT); glEnable(GL_DEPTH_TEST); int i; for (i=0;i<count;i++){ if((image[i] = readJPEGimage(filename[i+1], &imageWidth[i], &imageHeight[i], &imageDepth[i]))== NULL){ fprintf(stderr,"JPEG Image file read Error!!\n"); exit(0); } if(imageDepth[i] >= 4) imageFormat[i] = GL_RGBA; else if(imageDepth[i] == 3) imageFormat[i] = GL_RGB; else imageFormat[i] = GL_LUMINANCE; printf("%s: %d, %d, %d\n",filename[i+1], imageWidth[i], imageHeight[i], imageDepth[i]); } glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glGenTextures(count, texName); for(i=0;i<count;i++){ glBindTexture(GL_TEXTURE_2D, texName[i]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexImage2D(GL_TEXTURE_2D, 0, imageFormat[i], imageWidth[i], imageHeight[i], 0, imageFormat[i], GL_UNSIGNED_BYTE, image[i]); } glEnable(GL_TEXTURE_2D); free(imageHeight);free(imageWidth);free(imageDepth);free(imageFormat);free(image); }
void myinit() { // GLfloat light_ambient[] = { btScalar(0.2), btScalar(0.2), btScalar(0.2), btScalar(1.0) }; GLfloat light_ambient[] = { btScalar(1.0), btScalar(1.2), btScalar(0.2), btScalar(1.0) }; GLfloat light_diffuse[] = { btScalar(1.0), btScalar(1.0), btScalar(1.0), btScalar(1.0) }; GLfloat light_specular[] = { btScalar(1.0), btScalar(1.0), btScalar(1.0), btScalar(1.0 )}; /* light_position is NOT default value */ GLfloat light_position0[] = { btScalar(1000.0), btScalar(1000.0), btScalar(1000.0), btScalar(0.0 )}; GLfloat light_position1[] = { btScalar(-1.0), btScalar(-10.0), btScalar(-1.0), btScalar(0.0) }; glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient); glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse); glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular); glLightfv(GL_LIGHT0, GL_POSITION, light_position0); glLightfv(GL_LIGHT1, GL_AMBIENT, light_ambient); glLightfv(GL_LIGHT1, GL_DIFFUSE, light_diffuse); glLightfv(GL_LIGHT1, GL_SPECULAR, light_specular); glLightfv(GL_LIGHT1, GL_POSITION, light_position1); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glEnable(GL_LIGHT1); // glShadeModel(GL_FLAT);//GL_SMOOTH); glShadeModel(GL_SMOOTH); glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LESS); glClearColor(float(0.7),float(0.7),float(0.7),float(0)); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); static bool m_textureenabled = true; static bool m_textureinitialized = false; if(m_textureenabled) { if(!m_textureinitialized) { glActiveTexture(GL_TEXTURE0); GLubyte* image=new GLubyte[256*256*3]; for(int y=0;y<256;++y) { const int t=y>>5; GLubyte* pi=image+y*256*3; for(int x=0;x<256;++x) { const int s=x>>5; const GLubyte b=180; GLubyte c=b+((s+t&1)&1)*(255-b); pi[0]=255; pi[1]=c; pi[2]=c; pi+=3; } } glGenTextures(1,(GLuint*)&m_texturehandle); glBindTexture(GL_TEXTURE_2D,m_texturehandle); glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MODULATE); glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_LINEAR); glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR_MIPMAP_LINEAR); glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT); glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_REPEAT); gluBuild2DMipmaps(GL_TEXTURE_2D,3,256,256,GL_RGB,GL_UNSIGNED_BYTE,image); delete[] image; m_textureinitialized=true; } // glMatrixMode(GL_TEXTURE); // glLoadIdentity(); // glMatrixMode(GL_MODELVIEW); glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D,m_texturehandle); } else
//Member Functions Renderer::Renderer(int width, int height) : frameCount(0), splash(false), paused(false) { AUX_RGBImageRec* textureImage[4]; score = 0; orbsCaptured = 0; orbsReleased = 0; w = width; h = height; initRoom(); glEnable(GL_DEPTH_TEST | GL_POLYGON_SMOOTH); glEnable(GL_CULL_FACE); //enable culling glCullFace(GL_BACK); //cull back facing polys glShadeModel(GL_SMOOTH); //enable smooth shading glClearColor(0,0,0,1); //black background glClearDepth(1); //depth buffer setup glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glDepthFunc(GL_LEQUAL); glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); glHint(GL_POLYGON_SMOOTH_HINT, GL_NICEST); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(75, (GLfloat)w/(GLfloat)h, 0.1, 200); glMatrixMode(GL_MODELVIEW); //init textures if(textured){ glGenTextures(4, &textureID[0]); //load textures into main memory textureImage[0] = auxDIBImageLoad("tex/bricks.bmp"); textureImage[1] = auxDIBImageLoad("tex/sky.bmp"); textureImage[2] = auxDIBImageLoad("tex/grass.bmp"); textureImage[3] = auxDIBImageLoad("tex/splash.bmp"); for(int i = 0; i < 4; i++){ if(textureImage[i]){ if(textureImage[i]->data){ glBindTexture(GL_TEXTURE_2D, textureID[i]); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER, GL_LINEAR); //load into texture memory glTexImage2D(GL_TEXTURE_2D, 0, //mipmap level GL_RGB, textureImage[i]->sizeX, textureImage[i]->sizeY, 0, //border pixels GL_RGB, //pixel format GL_UNSIGNED_BYTE, textureImage[i]->data); //free main memory free(textureImage[i]->data); } free(textureImage[i]); } } } //init lighting if(lighting){ glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE); glLightModelfv(GL_LIGHT_MODEL_AMBIENT, globalAmbient); glLightfv(GL_LIGHT1, GL_POSITION, light1Position); glLightfv(GL_LIGHT1, GL_DIFFUSE, light1Diffuse); glLightfv(GL_LIGHT1, GL_SPECULAR, light1Specular); glLightfv(GL_LIGHT1, GL_AMBIENT, light1Ambient); glLightf(GL_LIGHT1, GL_SPOT_EXPONENT, 9.0); glLightf(GL_LIGHT1, GL_CONSTANT_ATTENUATION, 0.6); glLightf(GL_LIGHT1, GL_LINEAR_ATTENUATION, 0.05); glLightf(GL_LIGHT1, GL_QUADRATIC_ATTENUATION, 0.0); glLightf(GL_LIGHT1, GL_SPOT_CUTOFF, 45.0); glEnable(GL_LIGHT1); } }
void display(int d) { int i; glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); if(lock) { if(eye[0] < -23.0 - 28.0*tan(M_PI/6)) eye[0] = -23.0 - 28.0*tan(M_PI/6); if(eye[0] > 33.0) eye[0] = 33.0; if(eye[1] < -28.0 - 26.5*tan(M_PI/6)) eye[1] = -28.0 - 26.5*tan(M_PI/6); if(eye[1] > 25.0) eye[1] = 25.0; if(eye[2] < -25.0) eye[2] = -25.0; if(eye[2] > 51.0 + 65.0*tan(M_PI/6)) eye[2] = 51.0 + 65.0*tan(M_PI/6); } if(!helmet) { for(i=0; i < 3; i++) view[i] = (2 * negview * eye[i]); up[0] = 0; up[1] = negup * 1.0; up[2] = 0; } if(d==D_LEFT) { glTranslatef(-2.5, 0.0, 0.0); } else if(d==D_RIGHT) { glTranslatef(2.5, 0.0, 0.0); } gluLookAt(eye[0], eye[1], eye[2], view[0], view[1], view[2], up[0], up[1], up[2]); glTranslatef(global_translate[0], global_translate[1], global_translate[2]); glPushAttrib(GL_ALL_ATTRIB_BITS); glPushMatrix(); /* glRotatef(theta, 0.0, 1.0, 0.0); glRotatef(phi, 1.0, 0.0, 0.0);*/ glColor3f(1.0, 1.0, 1.0); if(wireframe) { glPolygonMode(GL_FRONT, GL_LINE); glDisable(GL_CULL_FACE); } else { glPolygonMode(GL_FRONT, GL_FILL); glEnable(GL_CULL_FACE); } /* Draw coordinate axes */ glDisable(GL_LIGHTING); glDisable(GL_TEXTURE_2D); if(axes) { glPushMatrix(); glTranslatef(-global_translate[0], -global_translate[1], -global_translate[2]); glBegin(GL_LINES); glVertex3f(-100.0, 0.0, 0.0); glVertex3f(100.0, 0.0, 0.0); glVertex3f(0.0, -100.0, 0.0); glVertex3f(0.0, 100.0, 0.0); glVertex3f(0.0, 0.0, -100.0); glVertex3f(0.0, 0.0, 100.0); glEnd(); glPopMatrix(); } if(texture) glEnable(GL_TEXTURE_2D); if(lighting) glEnable(GL_LIGHTING); if(!smooth) {glDisable(GL_SMOOTH); glShadeModel(GL_FLAT); glEnable(GL_FLAT);} else {glDisable(GL_FLAT); glShadeModel(GL_SMOOTH); glEnable(GL_SMOOTH);} if(filtering) { glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); } else { glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); } draw_scene(); glDisable(GL_LIGHTING); glDisable(GL_TEXTURE_2D); if(terrain) draw_terrain(); /* Draw w/o lighting */ if(stars) draw_stars(); glPopMatrix(); glPopAttrib(); /* And swap buffers to display the image */ glutSwapBuffers(); /* if(helmet) child(1);*/ }
int init_gl(void) { int i,j; /* Vamos a preparar las matrices de proyección */ glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(45.0f, (GLfloat) config.SCREEN_SIZE_X / (GLfloat) config.SCREEN_SIZE_Y, 0.01f, 100000.0f); glGetDoublev(GL_PROJECTION_MATRIX,&matriz_proyeccion_A[0][0]); glLoadIdentity(); gluPerspective(45.0f, (GLfloat) config.SCREEN_SIZE_X / (GLfloat) config.SCREEN_SIZE_Y, 0.01f, 100000.0f); glGetDoublev(GL_PROJECTION_MATRIX,&matriz_proyeccion_B[0][0]); glLoadIdentity(); glOrtho(0,config.SCREEN_SIZE_X,0,config.SCREEN_SIZE_Y,-100,100); glGetDoublev(GL_PROJECTION_MATRIX,&matriz_proyeccion_C[0][0]); glLoadMatrixd(&matriz_proyeccion_A[0][0]); fprintf(logs,"Matrices de proyección creadas\n"); /* Esto resetea la matriz de modelado y la de la camara*/ glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glLightfv(GL_LIGHT0, GL_AMBIENT, LightAmbient0); glLightfv(GL_LIGHT0, GL_DIFFUSE, LightDiffuse0); glLightfv(GL_LIGHT0, GL_POSITION, LightPosition0); glLightfv(GL_LIGHT1, GL_AMBIENT, LightAmbient1); glLightfv(GL_LIGHT1, GL_DIFFUSE, LightDiffuse0); glEnable(GL_LIGHT0); glEnable(GL_LIGHT1); glEnable(GL_LIGHTING); /* Inicialización de la matriz camara */ glGetFloatv(GL_MODELVIEW_MATRIX,&camara[0][0]); camara[2][2]=1.0f; camara[3][2]=-1.0f; fprintf(logs,"Camara inicializada\n"); /* Ahora establecemos el color de fondo por defecto. Está en formato RGBA y lo ponemos a negro */ glClearColor(0.0f, 0.0f, 0.0f, 0.0f); /* Estas 3 líneas habilitan del Buffer de profundidad*/ glClearDepth(1.0f); glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LEQUAL); glEnable (GL_BLEND); glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); /* Esta función sirve para optimizar el renderizado, y se utiliza para muchas cosas. En este caso es para hacer un buen cálculo de la perspectiva perdiendo un poco de rendimiento*/ glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); fprintf(logs,"Iniciando carga de texturas...\n"); /* Cargamos la textura */ glEnable(GL_TEXTURE_2D); glPixelStorei ( GL_UNPACK_ALIGNMENT, 1 ); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); if (carga_texturas()!=0) { sys_msg("Las texturas no se ha podido cargar"); } else fprintf(logs,"Texturas cargadas..\n"); glShadeModel(GL_FLAT); /* SMOOTH SHADING */ glEnable(GL_POINT_SMOOTH); glCullFace(GL_BACK); glEnable(GL_CULL_FACE); glLineWidth(5.0f); glEnable(GL_LINE_SMOOTH); disparo_laser.ttl=0; /* Creamos un par de fuentes */ fprintf(logs,"Cargando fuentes..\n"); fuentes[0]=carga_fuente("fuentes/def.tga",15,-6); if (fuentes[0]==NULL) { sys_msg("Error crítico cargando fuentes!"); exit (-1); } fuentes[1]=carga_fuente("fuentes/agulon.tga",16,-4); if (fuentes[1]==NULL) { sys_msg("Error crítico cargando fuentes!"); exit (-1); } fprintf(logs,"Fuentes cargadas..\n"); /* Creando el espacio de entorno */ fprintf(logs,"Creando el espacio\n"); if (!init_espacio()) { sys_msg("Error al crear espacio\n!"); exit (-1); } fprintf(logs,"Fuentes cargadas..\n"); /* Inicializamos OpenAL */ if ( InicializarAudio ( ) != 0 ){ fprintf (logs, "No funciona el sistema de audio\n"); audio_on = 0; } else { fprintf(logs,"OpenAL funcionando\n"); } /* Cargamos sonidos y musica*/ if ( audio_on == 1){ CargaSonido ("ws_datos/sonidos/laser.wav", 0); fprintf(logs,"Cargado sonido del laser\n"); /*CargaSonido ("ws_datos/sonidos/motor_nuestro.wav", 1); fprintf(logs,"Cargado sonido de nuestra nave\n");*/ CargaSonido ("ws_datos/sonidos/sonido_nave_enemiga.wav", 2); fprintf(logs,"Cargado sonido de la nave enemiga\n"); CargarMusica ("ws_datos/musicas/prueba.ogg"); fprintf ( logs, "Cargado musica\n"); } fprintf(logs,"OpenGL inicializado sin errores críticos...\n"); return 0; }
int main(int argc, char **argv) { int i; glutInit(&argc, argv); glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH | GLUT_MULTISAMPLE); for (i=1; i<argc; i++) { if(!strcmp("-noms", argv[i])) { glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH); printf("forcing no multisampling\n"); } else if(!strcmp("-nomipmaps", argv[i])) { useMipmaps = 0; } else if(!strcmp("-nearest", argv[i])) { linearFiltering = 0; } } glutInitWindowPosition(0, 0); glutInitWindowSize(600,300); glutCreateWindow("sprite blast"); glutReshapeFunc(reshape); glutDisplayFunc(redraw); glutMouseFunc(mouse); glutMotionFunc(mouseMotion); glutVisibilityFunc(visible); glutKeyboardFunc(key); glutCreateMenu(menu); glutAddMenuEntry("Reset time", 0); glutAddMenuEntry("Constant", 1); glutAddMenuEntry("Linear", 2); glutAddMenuEntry("Quadratic", 3); glutAddMenuEntry("Blend on", 4); glutAddMenuEntry("Blend off", 5); glutAddMenuEntry("Threshold 1", 6); glutAddMenuEntry("Threshold 10", 7); glutAddMenuEntry("Point smooth on", 8); glutAddMenuEntry("Point smooth off", 9); glutAddMenuEntry("Point size 4", 10); glutAddMenuEntry("Point size 8", 11); glutAddMenuEntry("Point size 16", 12); glutAddMenuEntry("Toggle spin", 13); glutAddMenuEntry("200 points ", 14); glutAddMenuEntry("500 points ", 15); glutAddMenuEntry("1000 points ", 16); glutAddMenuEntry("2000 points ", 17); glutAddMenuEntry("Quit", 666); glutAttachMenu(GLUT_RIGHT_BUTTON); glShadeModel(GL_FLAT); glEnable(GL_DEPTH_TEST); glEnable(GL_POINT_SMOOTH); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glPointSize(16.0); #ifdef GL_ARB_point_parameters glPointParameterfvARB(GL_POINT_DISTANCE_ATTENUATION_ARB, theQuad); #endif makePointList(); makeSprite(); glutMainLoop(); return 0; /* ANSI C requires main to return int. */ }
void motor::Window::open(int width, int height, string title) { this->width = width; this->height = height; if(SDL_Init(SDL_INIT_TIMER) < 0 ) { cout << "Unable to init SDL_TIMER: " << SDL_GetError() << "\nPlease send me a mail with the Error Code\n"; exit(1); } if(SDL_Init(SDL_INIT_VIDEO) < 0 ) { cout << "Unable to init SDL_VIDEO: " << SDL_GetError() << "\nPlease send me a mail with the Error Code\n"; exit(1); } //if(SDL_Init(SDL_INIT_AUDIO) < 0 ) //{ // cout << "Unable to init SDL_VIDEO: " << SDL_GetError() << "\nPlease send me a mail with the Error Code\n"; // exit(1); //} SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24); //SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); //SDL_GL_SetAttribute( SDL_GL_SWAP_CONTROL, 0); screen = SDL_SetVideoMode(width, height, 32, SDL_OPENGL | SDL_DOUBLEBUF | SDL_RESIZABLE); SDL_WM_SetCaption(title.c_str(), NULL); glClearColor(1.f/255.f * 146.f, 1.f/255.f * 161.f, 1.f/255.f * 207.f, 0); glViewport(0, 0, width, height); //glClearDepth(1.0f); // glMatrixMode(GL_PROJECTION); // glLoadIdentity(); //gluOrtho2D(0, width, height, 0); //glOrtho(0, width, height, 0, -1, 1); // gluPerspective(45.0f, float(width/height), near, far); // glMatrixMode(GL_MODELVIEW); // glLoadIdentity(); glEnable(GL_VERTEX_ARRAY); glEnable(GL_TEXTURE_2D); glEnable(GL_CULL_FACE); glCullFace(GL_BACK); glFrontFace(GL_CW); glEnable(GL_DEPTH_TEST); // glDepthRangef(0.0,1.0); //glDepthFunc(GL_LEQUAL); //glDepthMask(GL_TRUE); // glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); glShadeModel(GL_SMOOTH); // glEnable(GL_CULL_FACE); // glCullFace(GL_BACK); glEnable(GL_ALPHA_TEST); //glBlendFunc(GL_SRC_ALPHA,GL_ONE); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_BLEND); // glEnable(GL_BLEND); //glEnable(GL_DEPTH_TEST); //glDepthFunc(GL_LEQUAL); //glClear(GL_COLOR_BUFFER_BIT); //SDL_UpdateRect(screen, 0, 0, 640, 480); //SDL_GL_SwapBuffers(); //glClear(GL_COLOR_BUFFER_BIT); glewInit(); if(!GLEW_VERSION_2_0) { cout << "Dude, your card doesn't supports OpenGL 2.0 (which is bad!)" << endl; cout << "Please update your drivers, or buy a real video card" << endl; cout << endl << "If you are sure you have a real video card and up-to-date drivers, drop me an E-Mail" << endl; cout << "hnnnngh! " << endl; exit(-1); } cout << "sdl and gl initialised! READY FOR WORLD DOMINATION!" << endl; }
void init() { GLint maxBuffers; glGetIntegerv(GL_MAX_COLOR_ATTACHMENTS_EXT, &maxBuffers); printf("MAX_COLOR_ATTACHMENTS: %d\n", maxBuffers); glShadeModel(GL_SMOOTH); glClearColor(0.0f, 0.0f, 0.2f, 0.5f); glClearDepth(1.0f); glEnable(GL_DEPTH_TEST); glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); glDepthFunc(GL_LEQUAL); glViewport(0, 0, sWidth, sHeight); // setup the FBO glGenFramebuffersEXT(1, &fbo); glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo); // create the render buffer for depth glGenRenderbuffersEXT(1, &depthBuffer); glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, depthBuffer); glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT, texWidth, texHeight); // IMAGE TEXTURE glGenTextures(1, &imgTexture); glBindTexture(GL_TEXTURE_2D, imgTexture); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16, texWidth, texHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); // attach texture glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, imgTexture, 0); // DEPTH TEXTURE glGenTextures(1, &depthTexture); glBindTexture(GL_TEXTURE_2D, depthTexture); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16, texWidth, texHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); // Attach the texture to the FBO for rendering glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT1_EXT, GL_TEXTURE_2D, depthTexture, 0); // NORMAL TEXTURE glGenTextures(1, &normalTexture); glBindTexture(GL_TEXTURE_2D, normalTexture); glTexImage2D(GL_TEXTURE_2D, 0,GL_RGBA16, texWidth, texHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); // attach the second texture glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT2_EXT, GL_TEXTURE_2D, normalTexture, 0); // attach the depth buffer to the FBO glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, depthBuffer); // define the render targets GLenum mrt[] = {GL_COLOR_ATTACHMENT0_EXT, GL_COLOR_ATTACHMENT1_EXT, GL_COLOR_ATTACHMENT2_EXT}; glDrawBuffers(3, mrt); // check the FBO status GLenum status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT); if (status != GL_FRAMEBUFFER_COMPLETE_EXT) { printf("ERROR: FBO status not complete\n"); exit(1); } //// setup the FBO //glGenFramebuffersEXT(1, &fbo2); //glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo); //glGenTextures(1, &outlineTexture); //glBindTexture(GL_TEXTURE_2D, outlineTexture); //glTexImage2D(GL_TEXTURE_2D, 0,GL_RGBA16, texWidth, texHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); //glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); //glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); //glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); //glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); //glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, outlineTexture, 0); //glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, depthBuffer); //status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT); //if (status != GL_FRAMEBUFFER_COMPLETE_EXT) //{ // printf("ERROR: FBO status not complete\n"); // exit(1); //} // detach the FBO glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); }
/* * OpenGL (GLUT) calls this routine to display the scene */ void display() { // Erase the window and the depth buffer glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); // Enable Z-buffering in OpenGL glEnable(GL_DEPTH_TEST); // Undo previous transformations glLoadIdentity(); // Orthogonal - set world orientation //glTranslated(pos[0],0,pos[1]); glRotatef(ph,1,0,0); glRotatef(th,0,1,0); // Flat or smooth shading glShadeModel(smooth ? GL_SMOOTH : GL_FLAT); // Add light to the scene if (light) { // Translate intensity to color vectors float Ambient[] = {0.01*ambient ,0.01*ambient ,0.01*ambient ,1.0}; float Diffuse[] = {0.01*diffuse ,0.01*diffuse ,0.01*diffuse ,1.0}; float Specular[] = {0.01*specular,0.01*specular,0.01*specular,1.0}; // Light position float Position[] = {distance*Cos(zh),ylight,distance*Sin(zh),1.0}; // Draw light position as ball (still no lighting here) glColor3f(1,1,1); lightSource(Position[0],Position[1],Position[2] , 0.1); // OpenGL should normalize normal vectors glEnable(GL_NORMALIZE); // Enable lighting glEnable(GL_LIGHTING); // Location of viewer for specular calculations glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER,local); // glColor sets ambient and diffuse color materials glColorMaterial(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE); glEnable(GL_COLOR_MATERIAL); // Enable light 0 glEnable(GL_LIGHT0); // Set ambient, diffuse, specular components and position of light 0 glLightfv(GL_LIGHT0,GL_AMBIENT ,Ambient); glLightfv(GL_LIGHT0,GL_DIFFUSE ,Diffuse); glLightfv(GL_LIGHT0,GL_SPECULAR,Specular); glLightfv(GL_LIGHT0,GL_POSITION,Position); } else glDisable(GL_LIGHTING); // Draw Bell towers bell(8,2,-6,.25); bell(-8,2,-6,.25); for (int i = -9; i <= 9; i+=2){ for (int j = -5; j <= 5; j +=4){ floorTiles(i,-.5,j,1.2,0); } } for (int i = -8; i <= 8; i+=2){ for (int j = -3; j <= 5; j +=4){ floorTiles(i,-.5,j,1.2,.5); } } // Draw Game grid for (int k = -4; k <= -1; k++){ cube(k,0,-4, .5,.5,.5 , 0); cube(k,0,4, .5,.5,.5 , 0); cube(-4,0,k, .5,.5,.5 , 0); cube(4,0,k, .5,.5,.5 , 0); } for (int k = 1; k <= 4; k++){ cube(k,0,-4, .5,.5,.5 , 0); cube(k,0,4, .5,.5,.5 , 0); cube(-4,0,k, .5,.5,.5 , 0); cube(4,0,k, .5,.5,.5 , 0); } for (int k = -10; k <= 10; k++){ cube(k,0,-6, .5,.5,.5 , 0); cube(k,0,6, .5,.5,.5 , 0); } for (int k = -6; k <= 6; k++){ cube(-10,0,k, .5,.5,.5 , 0); cube(10,0,k, .5,.5,.5 , 0); } for (int k = -4; k <= 4; k++){ cube(-8,0,k, .5,.5,.5 , 0); cube(8,0,k, .5,.5,.5 , 0); } for (int k = -6; k <= -5; k++){ cube(-6,0,k, .5,.5,.5 , 0); cube(6,0,k, .5,.5,.5 , 0); } for (int k = -3; k <= 3; k++){ cube(-6,0,k, .5,.5,.5 , 0); cube(6,0,k, .5,.5,.5 , 0); } for (int k = 5; k <= 6; k++){ cube(-6,0,k, .5,.5,.5 , 0); cube(6,0,k, .5,.5,.5 , 0); } for (int j = -2; j <= -1; j++){ cube(j,0,-2, .5,.5,.5 , 0); cube(j,0,2, .5,.5,.5 , 0); cube(-2,0,j, .5,.5,.5 , 0); cube(2,0,j, .5,.5,.5 , 0); } for (int l = 1; l <= 2; l++){ cube(l,0,-2, .5,.5,.5 , 0); cube(l,0,2, .5,.5,.5 , 0); cube(-2,0,l, .5,.5,.5 , 0); cube(2,0,l, .5,.5,.5 , 0); } for (int i = -6; i <= 6; i++){ for (int j = -10; j <= 10; j++){ if (balls[i+6][j+10] == 1){ ball(j,0,i, 0.1,4); } } } // Draw ghosts and animate movement //Red Ghost Movement if (redTrack == 0){ posx1 += dx; ghost(posx1,0,-5 , 0.4, 0, 0); if (posx1 >= -7){ redTrack = 1; } glutIdleFunc(idle); } else if (redTrack == 1){ posz1 += dx; ghost(-7,0,posz1 , 0.4, 0, 0); if (posz1 >= 5){ redTrack = 2; } glutIdleFunc(idle); } else if (redTrack == 2){ posx1 -= dx; ghost(posx1,0,5 , 0.4, 0, 0); if (posx1 <= -9){ redTrack = 3; } glutIdleFunc(idle); } else if (redTrack == 3){ posz1 -= dx; ghost(-9,0,posz1 , 0.4, 0, 0); if (posz1 <= -5){ redTrack = 0; } glutIdleFunc(idle); } //Blue Ghost Movement if (blueTrack == 0){ posx2 += dx; ghost(posx2,0,-5 , 0.4, 0, 1); if (posx2 >= 5){ blueTrack = 1; } glutIdleFunc(idle); } else if (blueTrack == 1){ posz2 += dx; ghost(5,0,posz2 , 0.4, 0, 1); if (posz2 >= 5){ blueTrack = 2; } glutIdleFunc(idle); } else if (blueTrack == 2){ posx2 -= dx; ghost(posx2,0,5 , 0.4, 0, 1); if (posx2 <= -5){ blueTrack = 3; } glutIdleFunc(idle); } else if (blueTrack == 3){ posz2 -= dx; ghost(-5,0,posz2 , 0.4, 0, 1); if (posz2 <= -5){ blueTrack = 0; } glutIdleFunc(idle); } //Pink Ghost Movement if (pinkTrack == 0){ posx3 += dx; ghost(posx3,0,-5 , 0.4, 0, 2); if (posx3 >= 9){ pinkTrack = 1; } glutIdleFunc(idle); } else if (pinkTrack == 1){ posz3 += dx; ghost(9,0,posz3 , 0.4, 0, 2); if (posz3 >= 5){ pinkTrack = 2; } glutIdleFunc(idle); } else if (pinkTrack == 2){ posx3 -= dx; ghost(posx3,0,5 , 0.4, 0, 2); if (posx3 <= 7){ pinkTrack = 3; } glutIdleFunc(idle); } else if (pinkTrack == 3){ posz3 -= dx; ghost(7,0,posz3 , 0.4, 0, 2); if (posz1 <= -5){ pinkTrack = 0; } glutIdleFunc(idle); } //Orange Ghost Movement if (orangeTrack == 0){ posx4 += dx; ghost(posx4,0,-3 , 0.4, 0, 3); if (posx4 >= 3){ orangeTrack = 1; } glutIdleFunc(idle); } else if (orangeTrack == 1){ posz4 += dx; ghost(3,0,posz4 , 0.4, 0, 3); if (posz4 >= 0){ orangeTrack = 2; } glutIdleFunc(idle); } else if (orangeTrack == 2){ posx4 += dx; ghost(posx4,0,0 , 0.4, 0, 3); if (posx4 >= 5){ orangeTrack = 3; } glutIdleFunc(idle); } else if (orangeTrack == 3){ posz4 -= dx; ghost(5,0,posz4 , 0.4, 0, 3); if (posz4 <= -4){ orangeTrack = 4; } glutIdleFunc(idle); } else if (orangeTrack == 4){ posx4 += dx; ghost(posx4,0,-4 , 0.4, 0, 3); if (posx4 >= 7){ orangeTrack = 5; } glutIdleFunc(idle); } else if (orangeTrack == 5){ posz4 += dx; ghost(7,0,posz4 , 0.4, 0, 3); if (posz4 >= 4){ orangeTrack = 6; } glutIdleFunc(idle); } else if (orangeTrack == 6){ posx4 -= dx; ghost(posx4,0,4 , 0.4, 0, 3); if (posx4 <= 5){ orangeTrack = 7; } glutIdleFunc(idle); } else if (orangeTrack == 7){ posz4 += dx; ghost(5,0,posz4 , 0.4, 0, 3); if (posz4 >= 5){ orangeTrack = 8; } glutIdleFunc(idle); } else if (orangeTrack == 8){ posx4 -= dx; ghost(posx4,0,5 , 0.4, 0, 3); if (posx4 <= -5){ orangeTrack = 9; } glutIdleFunc(idle); } else if (orangeTrack == 9){ posz4 -= dx; ghost(-5,0,posz4 , 0.4, 0, 3); if (posz4 <= 4){ orangeTrack = 10; } glutIdleFunc(idle); } else if (orangeTrack == 10){ posx4 -= dx; ghost(posx4,0,4 , 0.4, 0, 3); if (posx4 <= -7){ orangeTrack = 11; } glutIdleFunc(idle); } else if (orangeTrack == 11){ posz4 -= dx; ghost(-7,0,posz4 , 0.4, 0, 3); if (posz4 <= -4){ orangeTrack = 12; } glutIdleFunc(idle); } else if (orangeTrack == 12){ posx4 += dx; ghost(posx4,0,-4 , 0.4, 0, 3); if (posx4 >= -5){ orangeTrack = 13; } glutIdleFunc(idle); } else if (orangeTrack == 13){ posz4 += dx; ghost(-5,0,posz4 , 0.4, 0, 3); if (posz4 >= 0){ orangeTrack = 14; } glutIdleFunc(idle); } else if (orangeTrack == 14){ posx4 += dx; ghost(posx4,0,0 , 0.4, 0, 3); if (posx4 >= -3){ orangeTrack = 15; } glutIdleFunc(idle); } else if (orangeTrack == 15){ posz4 -= dx; ghost(-3,0,posz4 , 0.4, 0, 3); if (posz4 <= -3){ orangeTrack = 16; } glutIdleFunc(idle); } else if (orangeTrack == 16){ posx4 += dx; ghost(posx4,0,-3 , 0.4, 0, 3); if (posx4 >= 0){ orangeTrack = 0; } glutIdleFunc(idle); } // Win condition if (score == 132){ glPopMatrix(); glDisable(GL_LIGHTING); // Display parameters glColor3f(1,1,1); glWindowPos2i(400,400); Print("Congratulations: You Win"); pos[0] = 0; pos[1] = 0; } // Detect ghost collision if ((pos[0] == posx1 && pos[1] == posz1) || (pos[0] == posx2 && pos[1] == posz2) || (pos[0] == posx3 && pos[1] == posz3) || (pos[0] == posx4 && pos[1] == posz4)){ lives--; dead = 1; if (lives == 0){ done = 1; } } // Draw Pacman if (dead == 0){ pacman(pos[0],0,pos[1], .4,0,press); } else if (done == 1){ glPopMatrix(); glDisable(GL_LIGHTING); // Display parameters glColor3f(1,1,1); glWindowPos2i(400,400); Print("Game Over"); pos[0] = 0; pos[1] = 0; } else{ pos[0] = 0; pos[1] = 0; dead = 0; pacman(pos[0],0,pos[1], .4,0,press); glutPostRedisplay(); } glPopMatrix(); glDisable(GL_LIGHTING); // Display parameters glColor3f(1,1,1); glWindowPos2i(5,5); Print("Lives:%i Score=%i",lives,score); // Render the scene and make it visible glFlush(); glutSwapBuffers(); }
/* ======================================================================================================================= Display function. Where the magic happens and everything is drawn. ======================================================================================================================= */ void display(void) { glMatrixMode(GL_PROJECTION); glLoadIdentity(); /* adjust for zoom value */ gluPerspective(50 * zoom, (float) glutGet(GLUT_WINDOW_WIDTH) / (float) glutGet(GLUT_WINDOW_HEIGHT), 0.001, 40.0); glMatrixMode(GL_MODELVIEW); /* do rotation things */ alpha = alpha + (float) inc; if(alpha > (float) 360.0) alpha -= (float) 360.0; beta = beta + (float) inc2; if(beta > (float) 360.0) beta -= (float) 360.0; /* normalise any normals which aren't in unit form */ glEnable(GL_NORMALIZE); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); /* draw the fog */ fog(); glPushMatrix(); /* translate whole scene so we can actually see it */ glTranslatef((float) 0.0, -(float) 0.5, -(float) 5); /* rotate by rotation values */ glRotatef(beta, (float) 1.0, (float) 0.0, (float) 0.0); glRotatef(-alpha, (float) 0.0, (float) 1.0, (float) 0.0); /* it was a bit big... */ glScalef(0.50, 0.50, 0.50); /* set shade mode */ glShadeModel(shademode); glPushMatrix(); /* draw the floor */ glScalef(scale * 5, scale * 5, scale * 5); glRotatef(180, 0, 1.0, 1.0); drawCheck(20, 20, BLUE, YELLOW); /* draw ground */ glPopMatrix(); /* set up the lights */ glTranslatef(0.3, 0, 1.25); glEnable(GL_LIGHTING); /* this is a positioned light */ glEnable(GL_LIGHT0); /* this is a directed light */ glEnable(GL_LIGHT1); /* this is a spotlight (not initiated til later) */ glEnable(GL_LIGHT2); /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ /* set the ambient light */ GLfloat ambientColor[] = { 0.2, 0.2, 0.2, 1.0 }; /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambientColor); /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ GLfloat lightColor0[] = { 0.5, 0.5, 0.5, 1.0 }; GLfloat lightPos0[] = { 0.0f, 1.5f, -1.0f, 0.0f }; /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ glLightfv(GL_LIGHT0, GL_DIFFUSE, lightColor0); glLightfv(GL_LIGHT0, GL_POSITION, lightPos0); /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ GLfloat lightColor1[] = { 0.8f, 0.8f, 0.8f, 1.0f }; GLfloat lightPos1[] = { 1.0f, 2.0f, -2.0f, 0.0f }; /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ glLightfv(GL_LIGHT1, GL_DIFFUSE, lightColor1); glLightfv(GL_LIGHT1, GL_POSITION, lightPos1); /* draw the table */ glPushMatrix(); glTranslatef(-0.3, 0, -1.25); glRotatef(180, 0, 1.0, 1.0); /*~~~~~~~~~~~~~~~~~~~~~~~*/ float cylbase = 0.60; float cyltop = 0.15; float cylheight = 1.0; float tableheight = 0.10; float tablecirc = 0.90; /*~~~~~~~~~~~~~~~~~~~~~~~*/ setMaterial(finTable); setColor(TABLE2); gluCylinder(quadratic, cylbase, cyltop, cylheight, splines * LOD, splines * LOD); glTranslatef(0, 0, cylheight); gluDisk(quadratic, 0.0, cyltop, splines * LOD, splines * LOD); gluCylinder(quadratic, tablecirc, tablecirc, tableheight, splines * LOD, splines * LOD); gluDisk(quadratic, 0.0, tablecirc, splines * LOD, splines * LOD); glTranslatef(0, 0, tableheight); gluDisk(quadratic, 0.0, tablecirc, splines * LOD, splines * LOD); setMaterial(finDefault); glPopMatrix(); glPushMatrix(); /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ /* initiate the spotlight */ GLfloat light_ambient2[] = { 0.0, 0.0, 0.0, 1.0 }; GLfloat light_diffuse2[] = { 0.0, 0.3, 0, 1.0 }; GLfloat light_specular2[] = { 0.0, 0.3, 0, 1.0 }; GLfloat lightPos2[] = { 0.0f, 3.0f, 0.0f, 0.0f }; GLfloat spot_direction[] = { 0, -1.0, 0 }; /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ glLightfv(GL_LIGHT2, GL_AMBIENT, light_ambient2); glLightfv(GL_LIGHT2, GL_DIFFUSE, light_diffuse2); glLightfv(GL_LIGHT2, GL_SPECULAR, light_specular2); glLightf(GL_LIGHT2, GL_SPOT_CUTOFF, 30.0); glLightfv(GL_LIGHT2, GL_POSITION, lightPos2); glLightfv(GL_LIGHT2, GL_SPOT_DIRECTION, spot_direction); /* draw the chairs and rotate them around the table */ glRotatef(270, 0.0, 1.0, 0.0); glTranslatef(-1.5, 0, 1.5); glPushMatrix(); glRotatef(90, 0, 1.0, 0.0); chair(); glPopMatrix(); glPushMatrix(); glTranslatef(0.3, 0, -1.25); glRotatef(90, 0, 1.0, 0.0); glTranslatef(-0.3, 0, 1.25); glRotatef(90, 0, 1.0, 0.0); chair(); glPopMatrix(); glPushMatrix(); glTranslatef(0.3, 0, -1.25); glRotatef(180, 0, 1.0, 0.0); glTranslatef(-0.3, 0, 1.25); glRotatef(90, 0, 1.0, 0.0); chair(); glPopMatrix(); glPushMatrix(); glTranslatef(0.3, 0, -1.25); glRotatef(270, 0, 1.0, 0.0); glTranslatef(-0.3, 0, 1.25); glRotatef(90, 0, 1.0, 0.0); chair(); glPopMatrix(); /* draw the cups/forks and rotate around the table */ glPushMatrix(); glTranslatef(0.35, 1.1, -0.25); cups(); glPushMatrix(); glTranslatef(-0.05, 0, -1.0); glRotatef(90, 0, 1.0, 0); glTranslatef(0.05, 0, 1.0); cups(); glPopMatrix(); glPushMatrix(); glTranslatef(-0.05, 0, -1.0); glRotatef(180, 0, 1.0, 0); glTranslatef(0.05, 0, 1.0); cups(); glPopMatrix(); glPushMatrix(); glTranslatef(-0.05, 0, -1.0); glRotatef(270, 0, 1.0, 0); glTranslatef(0.05, 0, 1.0); cups(); glPopMatrix(); glPopMatrix(); /* draw the teapot */ glPushMatrix(); /* put on table */ glTranslatef(0.3, 1.3, -1.25); /*~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ /* trans values for animation */ static int rotateval = 1; static int rotatevalx = 0; static float transvaly = 0; static float transvalx = 0; /* clock values for animation */ static int beginslow = 0; static int slowclock = 0; static int pourclock = 0; /*~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ /* only animate when playing */ if(ani_play) { { /*~~~*/ int ii; /*~~~*/ for(ii = 0; ii < speed; ii++) { { /* section where teapot slows */ if((beginslow)) { { if(((20 - slowclock / 10) > 0)) { rotateval = rotateval + (20 - slowclock / 10); slowclock++; } else { { /* section where teapot is pouring */ if(pourclock < 90) { { rotatevalx = pourclock / 2; transvaly = ((double) pourclock) / (double) 200; transvalx = ((double) pourclock) / (double) 400; } } else if(pourclock < 135) { /* teapot in mid air */ rotatevalx = 45; transvaly = 90.0 / 200; transvalx = 90.0 / 400; } else if(pourclock < 225) { { /* teapot is being set down */ rotatevalx = 45 - (pourclock - 135) / 2; transvaly = 90.0 / 200 - ((double) pourclock - 135) / (double) 200; transvalx = 90.0 / 400 - ((double) pourclock - 135) / (double) 400; } } else if(pourclock < 300) { /* teapot is back on table */ rotatevalx = 0; transvaly = 0; transvalx = 0; } else { { /* reset variables for next play */ ani_play = 0; ani_clock = 0; rotateval = 1; ani_direction = 0; slowclock = 0; pourclock = -speed; beginslow = 0; rotatevalx = 0; transvaly = 0; transvalx = 0; } } pourclock++; } } } } else if(ani_clock < 200) { /* teapot is speeding up it's spin */ rotateval = rotateval + ani_clock / 10; } else if(ani_clock < 500) { { /* teapot is at constant spin */ rotateval = rotateval + 20; if(ani_clock == 300) { /* choose the cup it will stop at */ ani_direction = rand() % 4 + 1; } } } if(rotateval > 360) rotateval -= 360; if ( (!beginslow) && (ani_direction != 0) && ( ( (rotateval >= ani_direction * 90 - SLOWMAGIC - 20) && (rotateval <= ani_direction * 90 - SLOWMAGIC) ) || ( (rotateval >= ani_direction * 90 - SLOWMAGIC + 340) && (rotateval <= ani_direction * 90 - SLOWMAGIC + 360) ) ) ) { /* choose opportune moment to slow down */ beginslow = 1; rotateval = ani_direction * 90 - SLOWMAGIC + 360; if(rotateval > 360) rotateval -= 360; } ani_clock++; } } } /* apply transformations */ } glRotatef(rotateval, 0, 1.0, 0); glTranslatef(transvalx, transvaly, 0); glRotatef(-rotatevalx, 0, 0, 1.0); /* apply texture */ glBindTexture(GL_TEXTURE_2D, texture[1]); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); glEnable(GL_TEXTURE_2D); /* apply finish */ setMaterial(finPot); glutSolidTeapot(0.2); setMaterial(finDefault); glDisable(GL_TEXTURE_2D); glPopMatrix(); glPopMatrix(); glPopMatrix(); /* 3D stuff is done */ glFlush(); /* draw text overlay */ glDisable(GL_NORMALIZE); glDisable(GL_LIGHTING); glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); glOrtho(0, glutGet(GLUT_WINDOW_WIDTH), glutGet(GLUT_WINDOW_HEIGHT), 0, -1, 1); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ char speedstring[20]; char str[500] = "<Z> and <z>: zoom in/out\n<X> or <x>: Start/Stop X rotation\n<Y> or <y> Start/Stop Y Rotation\n<A> or <a>: Start animation\n<F> or <f>: Speed up animation\n<S> or <s>: Slow down animation\n<T> or <t>: Pause animation\n<C> or <c>: Resume the animation\n<p>: switch the rendering to the flat shaded polygonization.\n<P> switch the rendering to the smooth shaded polygonization.\n<q> or <Q>: change fog mode\nspeed: "; /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ sprintf(speedstring, "%d", speed); strcat(str, speedstring); strcat(str, "\nLOD: "); sprintf(speedstring, "%d", LOD); strcat(str, speedstring); strcat(str, "\nFog Mode: "); switch(fogfilter) { { case 0: strcat(str, "GL_EXP"); break; case 1: strcat(str, "GL_EXP2"); break; case 2: strcat(str, "GL_LINEAR"); break; case 3: strcat(str, "NO FOG"); break; } } bitmap_output(30, 30, str, GLUT_BITMAP_HELVETICA_12); glPopMatrix(); glMatrixMode(GL_PROJECTION); glPopMatrix(); /* draw transparent box for text */ glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); glOrtho(0, glutGet(GLUT_WINDOW_WIDTH), glutGet(GLUT_WINDOW_HEIGHT), 0, -1, 1); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glColor4f((float) 0, (float) 0, (float) 0, (float) 0.6); glRecti(30 - 10, 30 - 20, 40 + 350, 30 + 250); glPopMatrix(); glMatrixMode(GL_PROJECTION); glPopMatrix(); glFlush(); glutSwapBuffers(); }
static void init(ModeInfo *mi) { static const GLfloat light_ambient[] = { 0.0, 0.0, 0.0, 1.0 }; static const GLfloat light_diffuse[] = { 1.0, 1.0, 1.0, 1.0 }; static const GLfloat light_specular[] = { 1.0, 1.0, 1.0, 1.0 }; static const GLfloat light_position[] = { 1.0, 1.0, 1.0, 0.0 }; static const GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 }; projectiveplanestruct *pp = &projectiveplane[MI_SCREEN(mi)]; if (walk_speed == 0.0) walk_speed = 20.0; if (view == VIEW_TURN) { pp->alpha = frand(360.0); pp->beta = frand(360.0); pp->delta = frand(360.0); pp->zeta = 0.0; pp->eta = 0.0; pp->theta = 0.0; } else { pp->alpha = 0.0; pp->beta = 0.0; pp->delta = 0.0; pp->zeta = 120.0; pp->eta = 180.0; pp->theta = 90.0; } pp->umove = frand(2.0*M_PI); pp->vmove = frand(2.0*M_PI); pp->dumove = 0.0; pp->dvmove = 0.0; pp->side = 1; if (sin(walk_direction*M_PI/180.0) >= 0.0) pp->dir = 1; else pp->dir = -1; pp->offset4d[0] = 0.0; pp->offset4d[1] = 0.0; pp->offset4d[2] = 0.0; pp->offset4d[3] = 1.2; pp->offset3d[0] = 0.0; pp->offset3d[1] = 0.0; pp->offset3d[2] = -1.2; pp->offset3d[3] = 0.0; gen_texture(mi); setup_projective_plane(mi,0.0,2.0*M_PI,0.0,2.0*M_PI); if (marks) glEnable(GL_TEXTURE_2D); else glDisable(GL_TEXTURE_2D); glMatrixMode(GL_PROJECTION); glLoadIdentity(); if (projection_3d == DISP_3D_PERSPECTIVE || view == VIEW_WALK || view == VIEW_WALKTURN) { if (view == VIEW_WALK || view == VIEW_WALKTURN) gluPerspective(60.0,1.0,0.01,10.0); else gluPerspective(60.0,1.0,0.1,10.0); } else { glOrtho(-0.6,0.6,-0.6,0.6,0.1,10.0); } glMatrixMode(GL_MODELVIEW); glLoadIdentity(); # ifdef HAVE_JWZGLES /* #### glPolygonMode other than GL_FILL unimplemented */ if (display_mode == DISP_WIREFRAME) display_mode = DISP_SURFACE; # endif if (display_mode == DISP_SURFACE) { glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LESS); glShadeModel(GL_SMOOTH); glPolygonMode(GL_FRONT_AND_BACK,GL_FILL); glLightModeli(GL_LIGHT_MODEL_TWO_SIDE,GL_TRUE); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glLightfv(GL_LIGHT0,GL_AMBIENT,light_ambient); glLightfv(GL_LIGHT0,GL_DIFFUSE,light_diffuse); glLightfv(GL_LIGHT0,GL_SPECULAR,light_specular); glLightfv(GL_LIGHT0,GL_POSITION,light_position); glMaterialfv(GL_FRONT_AND_BACK,GL_SPECULAR,mat_specular); glMaterialf(GL_FRONT_AND_BACK,GL_SHININESS,50.0); glDepthMask(GL_TRUE); glDisable(GL_BLEND); } else if (display_mode == DISP_TRANSPARENT) { glDisable(GL_DEPTH_TEST); glShadeModel(GL_SMOOTH); glPolygonMode(GL_FRONT_AND_BACK,GL_FILL); glLightModeli(GL_LIGHT_MODEL_TWO_SIDE,GL_TRUE); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glLightfv(GL_LIGHT0,GL_AMBIENT,light_ambient); glLightfv(GL_LIGHT0,GL_DIFFUSE,light_diffuse); glLightfv(GL_LIGHT0,GL_SPECULAR,light_specular); glLightfv(GL_LIGHT0,GL_POSITION,light_position); glMaterialfv(GL_FRONT_AND_BACK,GL_SPECULAR,mat_specular); glMaterialf(GL_FRONT_AND_BACK,GL_SHININESS,50.0); glDepthMask(GL_FALSE); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA,GL_ONE); } else /* display_mode == DISP_WIREFRAME */ { glDisable(GL_DEPTH_TEST); glShadeModel(GL_FLAT); glPolygonMode(GL_FRONT_AND_BACK,GL_LINE); glDisable(GL_LIGHTING); glDisable(GL_LIGHT0); glDisable(GL_BLEND); } }
/******************************************************************************* * Function Name : InitView * Inputs : * Returns : true if no error occured * Description : Code in InitView() will be called by the Shell upon a change * in the rendering context. * Used to initialize variables that are dependant on the rendering * context (e.g. textures, vertex buffers, etc.) *******************************************************************************/ bool OGLESOptimizeMesh::InitView() { SPVRTContext sContext; bool bRotate = PVRShellGet(prefIsRotated) && PVRShellGet(prefFullScreen); // Init Print3D to display text on screen if(m_Print3D.SetTextures(&sContext, PVRShellGet(prefWidth), PVRShellGet(prefHeight), bRotate) != PVR_SUCCESS) { PVRShellSet(prefExitMessage, "ERROR: Cannot initialise Print3D.\n"); return false; } /********************************* ** View and Projection Matrices ** *********************************/ // Get Camera info from POD file PVRTVec3 From, To; // View m_mView = PVRTMat4::LookAtRH(From, To, PVRTVec3(0.0f, 1.0f, 0.0f)); // Projection m_mProj = PVRTMat4::PerspectiveFovRH(PVRT_PIf / 6, (float) PVRShellGet(prefWidth) / (float) PVRShellGet(prefHeight), g_fCameraNear, g_fCameraFar, PVRTMat4::OGL, bRotate); glMatrixMode(GL_PROJECTION); glLoadMatrixf(m_mProj.f); /****************************** ** GENERIC RENDER STATES ** ******************************/ // The Type Of Depth Test To Do glDepthFunc(GL_LEQUAL); // Enables Depth Testing glEnable(GL_DEPTH_TEST); // Enables Smooth Color Shading glShadeModel(GL_SMOOTH); // Define front faces glFrontFace(GL_CW); // Sets the clear colour glClearColor(0.6f, 0.8f, 1.0f, 1.0f); // Reset the model view matrix to position the light glMatrixMode(GL_MODELVIEW); glLoadIdentity(); // Setup timing variables m_ui32LastTime = PVRShellGetTime(); m_ui32FPSFrameCnt = 0; m_fFPS = 0; m_fViewAngle = 0; m_ui32SwitchTimeDiff = 0; LoadVbos(); return true; }
void GLBox::initializeGL() { qglClearColor(Qt::black); // Let OpenGL clear to black object = makeObject(); // Generate an OpenGL display list glShadeModel( GL_FLAT ); }
static void draw_textured_begin(Scene *scene, View3D *v3d, RegionView3D *rv3d, Object *ob) { unsigned char obcol[4]; bool is_tex, solidtex; Mesh *me = ob->data; ImagePaintSettings *imapaint = &scene->toolsettings->imapaint; /* XXX scene->obedit warning */ /* texture draw is abused for mask selection mode, do this so wire draw * with face selection in weight paint is not lit. */ if ((v3d->drawtype <= OB_WIRE) && (ob->mode & (OB_MODE_VERTEX_PAINT | OB_MODE_WEIGHT_PAINT))) { solidtex = false; Gtexdraw.is_lit = 0; } else if ((ob->mode & OB_MODE_TEXTURE_PAINT) && BKE_scene_use_new_shading_nodes(scene)) { solidtex = true; if (v3d->flag2 & V3D_SHADELESS_TEX) Gtexdraw.is_lit = 0; else Gtexdraw.is_lit = -1; } else if ((v3d->drawtype == OB_SOLID) || ((ob->mode & OB_MODE_EDIT) && (v3d->drawtype != OB_TEXTURE))) { /* draw with default lights in solid draw mode and edit mode */ solidtex = true; Gtexdraw.is_lit = -1; } else { /* draw with lights in the scene otherwise */ solidtex = false; if (v3d->flag2 & V3D_SHADELESS_TEX) Gtexdraw.is_lit = 0; else Gtexdraw.is_lit = GPU_scene_object_lights(scene, ob, v3d->lay, rv3d->viewmat, !rv3d->is_persp); } rgba_float_to_uchar(obcol, ob->col); if (solidtex || v3d->drawtype == OB_TEXTURE) is_tex = true; else is_tex = false; Gtexdraw.ob = ob; Gtexdraw.stencil = (imapaint->flag & IMAGEPAINT_PROJECT_LAYER_STENCIL) ? imapaint->stencil : NULL; Gtexdraw.is_texpaint = (ob->mode == OB_MODE_TEXTURE_PAINT); Gtexdraw.texpaint_material = (imapaint->mode == IMAGEPAINT_MODE_MATERIAL); Gtexdraw.canvas = (Gtexdraw.texpaint_material) ? NULL : imapaint->canvas; Gtexdraw.is_tex = is_tex; /* naughty multitexturing hacks to quickly support stencil + shading + alpha blending * in new texpaint code. The better solution here would be to support GLSL */ if (Gtexdraw.is_texpaint) { glActiveTexture(GL_TEXTURE1); glEnable(GL_TEXTURE_2D); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE); glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_INTERPOLATE); glTexEnvi(GL_TEXTURE_ENV, GL_SRC0_RGB, GL_PREVIOUS); glTexEnvi(GL_TEXTURE_ENV, GL_SRC1_RGB, GL_PRIMARY_COLOR); glTexEnvi(GL_TEXTURE_ENV, GL_SRC2_RGB, GL_PREVIOUS); glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_RGB, GL_SRC_ALPHA); glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_REPLACE); glTexEnvi(GL_TEXTURE_ENV, GL_SRC0_ALPHA, GL_PREVIOUS); /* load the stencil texture here */ if (Gtexdraw.stencil != NULL) { glActiveTexture(GL_TEXTURE2); if (GPU_verify_image(Gtexdraw.stencil, NULL, GL_TEXTURE_2D, false, false, false, false)) { float col[4] = {imapaint->stencil_col[0], imapaint->stencil_col[1], imapaint->stencil_col[2], 1.0f}; glEnable(GL_TEXTURE_2D); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE); glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_INTERPOLATE); glTexEnvi(GL_TEXTURE_ENV, GL_SRC0_RGB, GL_PREVIOUS); glTexEnvi(GL_TEXTURE_ENV, GL_SRC1_RGB, GL_CONSTANT); glTexEnvi(GL_TEXTURE_ENV, GL_SRC2_RGB, GL_TEXTURE); glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_MODULATE); glTexEnvi(GL_TEXTURE_ENV, GL_SRC0_ALPHA, GL_PREVIOUS); glTexEnvi(GL_TEXTURE_ENV, GL_SRC1_ALPHA, GL_TEXTURE); glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, col); if ((imapaint->flag & IMAGEPAINT_PROJECT_LAYER_STENCIL_INV) == 0) { glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_RGB, GL_ONE_MINUS_SRC_COLOR); } else { glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_RGB, GL_SRC_COLOR); } } } glActiveTexture(GL_TEXTURE0); } Gtexdraw.color_profile = BKE_scene_check_color_management_enabled(scene); Gtexdraw.use_game_mat = (RE_engines_find(scene->r.engine)->flag & RE_GAME) != 0; Gtexdraw.use_backface_culling = (v3d->flag2 & V3D_BACKFACE_CULLING) != 0; Gtexdraw.two_sided_lighting = (me->flag & ME_TWOSIDED); memcpy(Gtexdraw.obcol, obcol, sizeof(obcol)); set_draw_settings_cached(1, NULL, NULL, Gtexdraw); glShadeModel(GL_SMOOTH); glCullFace(GL_BACK); }
ENTRYPOINT void draw_cube (ModeInfo *mi) { cube_configuration *cc = &ccs[MI_SCREEN(mi)]; int wire = MI_IS_WIREFRAME(mi); Display *dpy = MI_DISPLAY(mi); Window window = MI_WINDOW(mi); int i; if (!cc->glx_context) return; mi->polygon_count = 0; glXMakeCurrent(MI_DISPLAY(mi), MI_WINDOW(mi), *cc->glx_context); interference (mi); animate_cubes (mi); glShadeModel(GL_FLAT); glEnable(GL_DEPTH_TEST); glEnable(GL_NORMALIZE); glEnable(GL_CULL_FACE); /* glEnable (GL_POLYGON_OFFSET_FILL); */ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glPushMatrix (); glRotatef(current_device_rotation(), 0, 0, 1); gltrackball_rotate (cc->trackball); glRotatef (-180, 1, 0, 0); { GLfloat s = 15; glScalef (s, s, s); } glRotatef (-90, 1, 0, 0); glTranslatef (-0.18, 0, -0.18); glRotatef (37, 1, 0, 0); glRotatef (20, 0, 0, 1); glScalef (2.1, 2.1, 2.1); /* Position lights after device rotation. */ if (!wire) { static const GLfloat pos[4] = {0.0, 0.25, -1.0, 0.0}; static const GLfloat amb[4] = {0.2, 0.2, 0.2, 1.0}; static const GLfloat dif[4] = {1.0, 1.0, 1.0, 1.0}; glLightfv(GL_LIGHT0, GL_POSITION, pos); glLightfv(GL_LIGHT0, GL_AMBIENT, amb); glLightfv(GL_LIGHT0, GL_DIFFUSE, dif); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glEnable(GL_DEPTH_TEST); glEnable(GL_CULL_FACE); } glBegin (wire ? GL_LINES : GL_QUADS); for (i = 0; i < cc->ncubes; i++) { cube *cube = &cc->cubes[i]; GLfloat cth = cube->cth; GLfloat sth = cube->sth; GLfloat x = cth*cube->x + sth*cube->y; GLfloat y = -sth*cube->x + cth*cube->y; GLfloat w = cube->w/2; GLfloat h = cube->h/2; GLfloat d = cube->d/2; GLfloat bottom = 5; GLfloat xw = cth*w, xd = sth*d; GLfloat yw = -sth*w, yd = cth*d; GLfloat color[4]; int c = cube->h * cc->ncolors * 0.7; c %= cc->ncolors; color[0] = cc->colors[c].red / 65536.0; color[1] = cc->colors[c].green / 65536.0; color[2] = cc->colors[c].blue / 65536.0; color[3] = 1.0; glMaterialfv (GL_FRONT, GL_AMBIENT_AND_DIFFUSE, color); /* Putting this in a display list makes no performance difference. */ if (! wire) { glNormal3f (0, 0, -1); /* top */ glVertex3f (x+xw+xd, y+yw+yd, -h); glVertex3f (x+xw-xd, y+yw-yd, -h); glVertex3f (x-xw-xd, y-yw-yd, -h); glVertex3f (x-xw+xd, y-yw+yd, -h); mi->polygon_count++; glNormal3f (sth, cth, 0); /* front */ glVertex3f (x+xw+xd, y+yw+yd, bottom); glVertex3f (x+xw+xd, y+yw+yd, -h); glVertex3f (x-xw+xd, y-yw+yd, -h); glVertex3f (x-xw+xd, y-yw+yd, bottom); mi->polygon_count++; glNormal3f (cth, -sth, 0); /* right */ glVertex3f (x+xw-xd, y+yw-yd, -h); glVertex3f (x+xw+xd, y+yw+yd, -h); glVertex3f (x+xw+xd, y+yw+yd, bottom); glVertex3f (x+xw-xd, y+yw-yd, bottom); mi->polygon_count++; # if 0 /* Omitting these makes no performance difference. */ glNormal3f (-cth, sth, 0); /* left */ glVertex3f (x-xw+xd, y-yw+yd, -h); glVertex3f (x-xw-xd, y-yw-yd, -h); glVertex3f (x-xw-xd, y-yw-yd, bottom); glVertex3f (x-xw+xd, y-yw+yd, bottom); mi->polygon_count++; glNormal3f (-sth, -cth, 0); /* back */ glVertex3f (x-xw-xd, y-yw-yd, bottom); glVertex3f (x-xw-xd, y-yw-yd, -h); glVertex3f (x+xw-xd, y+yw-yd, -h); glVertex3f (x+xw-xd, y+yw-yd, bottom); mi->polygon_count++; # endif } else { glNormal3f (0, 0, -1); /* top */ glVertex3f (x+xw+xd, y+yw+yd, -h); glVertex3f (x+xw-xd, y+yw-yd, -h); glVertex3f (x+xw-xd, y+yw-yd, -h); glVertex3f (x-xw-xd, y-yw-yd, -h); glVertex3f (x-xw-xd, y-yw-yd, -h); glVertex3f (x-xw+xd, y-yw+yd, -h); glVertex3f (x-xw+xd, y-yw+yd, -h); glVertex3f (x+xw+xd, y+yw+yd, -h); mi->polygon_count++; } } glEnd(); glPolygonOffset (0, 0); # if 0 glDisable(GL_DEPTH_TEST); /* Outline the playfield */ glColor3f(1,1,1); glBegin(GL_LINE_LOOP); glVertex3f (-0.5, -0.5, 0); glVertex3f (-0.5, 0.5, 0); glVertex3f ( 0.5, 0.5, 0); glVertex3f ( 0.5, -0.5, 0); glEnd(); # endif glPopMatrix(); if (mi->fps_p) do_fps (mi); glFinish(); glXSwapBuffers(dpy, window); }
static void gearGL(GLfloat inner_radius, GLfloat outer_radius, GLfloat width, GLint teeth, GLfloat tooth_depth) { GLint i; GLfloat r0, r1, r2; GLfloat angle, da; GLfloat u, v, len; const double pi = 3.14159264; r0 = inner_radius; r1 = (float)(outer_radius - tooth_depth/2.0); r2 = (float)(outer_radius + tooth_depth/2.0); da = (float)(2.0*pi / teeth / 4.0); glShadeModel(GL_FLAT); glNormal3f(0.0, 0.0, 1.0); /* draw front face */ glBegin(GL_QUAD_STRIP); for (i=0;i<=teeth;i++) { angle = (float)(i * 2.0*pi / teeth); glVertex3f((float)(r0*cos(angle)), (float)(r0*sin(angle)), (float)(width*0.5)); glVertex3f((float)(r1*cos(angle)), (float)(r1*sin(angle)), (float)(width*0.5)); glVertex3f((float)(r0*cos(angle)), (float)(r0*sin(angle)), (float)(width*0.5)); glVertex3f((float)(r1*cos(angle+3*da)), (float)(r1*sin(angle+3*da)), (float)(width*0.5)); } glEnd(); /* draw front sides of teeth */ glBegin(GL_QUADS); da = (float)(2.0*pi / teeth / 4.0); for (i=0;i<teeth;i++) { angle = (float)(i * 2.0*pi / teeth); glVertex3f((float)(r1*cos(angle)), (float)(r1*sin(angle)), (float)(width*0.5)); glVertex3f((float)(r2*cos(angle+da)), (float)(r2*sin(angle+da)), (float)(width*0.5)); glVertex3f((float)(r2*cos(angle+2*da)), (float)(r2*sin(angle+2*da)), (float)(width*0.5)); glVertex3f((float)(r1*cos(angle+3*da)), (float)(r1*sin(angle+3*da)), (float)(width*0.5)); } glEnd(); glNormal3f(0.0, 0.0, -1.0); /* draw back face */ glBegin(GL_QUAD_STRIP); for (i=0;i<=teeth;i++) { angle = (float)(i * 2.0*pi / teeth); glVertex3f((float)(r1*cos(angle)), (float)(r1*sin(angle)), (float)(-width*0.5)); glVertex3f((float)(r0*cos(angle)), (float)(r0*sin(angle)), (float)(-width*0.5)); glVertex3f((float)(r1*cos(angle+3*da)), (float)(r1*sin(angle+3*da)), (float)(-width*0.5)); glVertex3f((float)(r0*cos(angle)), (float)(r0*sin(angle)), (float)(-width*0.5)); } glEnd(); /* draw back sides of teeth */ glBegin(GL_QUADS); da = (float)(2.0*pi / teeth / 4.0); for (i=0;i<teeth;i++) { angle = (float)(i * 2.0*pi / teeth); glVertex3f((float)(r1*cos(angle+3*da)), (float)(r1*sin(angle+3*da)), (float)(-width*0.5)); glVertex3f((float)(r2*cos(angle+2*da)), (float)(r2*sin(angle+2*da)), (float)(-width*0.5)); glVertex3f((float)(r2*cos(angle+da)), (float)(r2*sin(angle+da)), (float)(-width*0.5)); glVertex3f((float)(r1*cos(angle)), (float)(r1*sin(angle)), (float)(-width*0.5)); } glEnd(); /* draw outward faces of teeth */ glBegin(GL_QUAD_STRIP); for (i=0;i<teeth;i++) { angle = (float)(i * 2.0*pi / teeth); glVertex3f((float)(r1*cos(angle)), (float)(r1*sin(angle)), (float)(width*0.5)); glVertex3f((float)(r1*cos(angle)), (float)(r1*sin(angle)), (float)(-width*0.5)); u = (float)(r2*cos(angle+da) - r1*cos(angle)); v = (float)(r2*sin(angle+da) - r1*sin(angle)); len = (float)(sqrt(u*u + v*v)); u /= len; v /= len; glNormal3f(v, -u, 0.0); glVertex3f((float)(r2*cos(angle+da)), (float)(r2*sin(angle+da)), (float)(width*0.5)); glVertex3f((float)(r2*cos(angle+da)), (float)(r2*sin(angle+da)), (float)(-width*0.5)); glNormal3f((float)(cos(angle)), (float)(sin(angle)), 0.0); glVertex3f((float)(r2*cos(angle+2*da)), (float)(r2*sin(angle+2*da)), (float)(width*0.5)); glVertex3f((float)(r2*cos(angle+2*da)), (float)(r2*sin(angle+2*da)), (float)(-width*0.5)); u = (float)(r1*cos(angle+3*da) - r2*cos(angle+2*da)); v = (float)(r1*sin(angle+3*da) - r2*sin(angle+2*da)); glNormal3f(v, -u, 0.0); glVertex3f((float)(r1*cos(angle+3*da)), (float)(r1*sin(angle+3*da)), (float)(width*0.5)); glVertex3f((float)(r1*cos(angle+3*da)), (float)(r1*sin(angle+3*da)), (float)(-width*0.5)); glNormal3f((float)(cos(angle)), (float)(sin(angle)), 0.0); } glVertex3f((float)(r1*cos(0.0)), (float)(r1*sin(0.0)), (float)(width*0.5)); glVertex3f((float)(r1*cos(0.0)), (float)(r1*sin(0.0)), (float)(-width*0.5)); glEnd(); glShadeModel(GL_SMOOTH); /* draw inside radius cylinder */ glBegin(GL_QUAD_STRIP); for (i=0;i<=teeth;i++) { angle = (float)(i * 2.0*pi / teeth); glNormal3f((float)(-cos(angle)), (float)(-sin(angle)), 0.0); glVertex3f((float)(r0*cos(angle)), (float)(r0*sin(angle)), (float)(-width*0.5)); glVertex3f((float)(r0*cos(angle)), (float)(r0*sin(angle)), (float)(width*0.5)); } glEnd(); }
bool BootAnimation::android() { initTexture(&mAndroid[0], mAssets, "images/android-logo-mask.png"); initTexture(&mAndroid[1], mAssets, "images/android-logo-shine.png"); // clear screen glShadeModel(GL_FLAT); glDisable(GL_DITHER); glDisable(GL_SCISSOR_TEST); glClearColor(0,0,0,1); glClear(GL_COLOR_BUFFER_BIT); eglSwapBuffers(mDisplay, mSurface); glEnable(GL_TEXTURE_2D); glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); const GLint xc = (mWidth - mAndroid[0].w) / 2; const GLint yc = (mHeight - mAndroid[0].h) / 2; const Rect updateRect(xc, yc, xc + mAndroid[0].w, yc + mAndroid[0].h); glScissor(updateRect.left, mHeight - updateRect.bottom, updateRect.width(), updateRect.height()); // Blend state glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); const nsecs_t startTime = systemTime(); do { nsecs_t now = systemTime(); double time = now - startTime; float t = 4.0f * float(time / us2ns(16667)) / mAndroid[1].w; GLint offset = (1 - (t - floorf(t))) * mAndroid[1].w; GLint x = xc - offset; glDisable(GL_SCISSOR_TEST); glClear(GL_COLOR_BUFFER_BIT); glEnable(GL_SCISSOR_TEST); glDisable(GL_BLEND); glBindTexture(GL_TEXTURE_2D, mAndroid[1].name); glDrawTexiOES(x, yc, 0, mAndroid[1].w, mAndroid[1].h); glDrawTexiOES(x + mAndroid[1].w, yc, 0, mAndroid[1].w, mAndroid[1].h); glEnable(GL_BLEND); glBindTexture(GL_TEXTURE_2D, mAndroid[0].name); glDrawTexiOES(xc, yc, 0, mAndroid[0].w, mAndroid[0].h); EGLBoolean res = eglSwapBuffers(mDisplay, mSurface); if (res == EGL_FALSE) break; // 12fps: don't animate too fast to preserve CPU const nsecs_t sleepTime = 83333 - ns2us(systemTime() - now); if (sleepTime > 0) usleep(sleepTime); checkExit(); } while (!exitPending()); glDeleteTextures(1, &mAndroid[0].name); glDeleteTextures(1, &mAndroid[1].name); return false; }
static int arm (GLfloat length, GLfloat width1, GLfloat height1, GLfloat width2, GLfloat height2, Bool wire) { int polys = 0; glShadeModel(GL_FLAT); #if 0 /* don't need these - they're embedded in other objects */ /* draw end 1 */ glFrontFace(GL_CW); glNormal3f(-1, 0, 0); glBegin(wire ? GL_LINE_LOOP : GL_QUADS); glVertex3f(-length/2, -width1/2, -height1/2); glVertex3f(-length/2, width1/2, -height1/2); glVertex3f(-length/2, width1/2, height1/2); glVertex3f(-length/2, -width1/2, height1/2); polys++; glEnd(); /* draw end 2 */ glFrontFace(GL_CCW); glNormal3f(1, 0, 0); glBegin(wire ? GL_LINE_LOOP : GL_QUADS); glVertex3f(length/2, -width2/2, -height2/2); glVertex3f(length/2, width2/2, -height2/2); glVertex3f(length/2, width2/2, height2/2); glVertex3f(length/2, -width2/2, height2/2); polys++; glEnd(); #endif /* draw top */ glFrontFace(GL_CCW); glNormal3f(0, 0, -1); glBegin(wire ? GL_LINE_LOOP : GL_QUADS); glVertex3f(-length/2, -width1/2, -height1/2); glVertex3f(-length/2, width1/2, -height1/2); glVertex3f( length/2, width2/2, -height2/2); glVertex3f( length/2, -width2/2, -height2/2); polys++; glEnd(); /* draw bottom */ glFrontFace(GL_CW); glNormal3f(0, 0, 1); glBegin(wire ? GL_LINE_LOOP : GL_QUADS); glVertex3f(-length/2, -width1/2, height1/2); glVertex3f(-length/2, width1/2, height1/2); glVertex3f( length/2, width2/2, height2/2); glVertex3f( length/2, -width2/2, height2/2); polys++; glEnd(); /* draw left */ glFrontFace(GL_CW); glNormal3f(0, -1, 0); glBegin(wire ? GL_LINE_LOOP : GL_QUADS); glVertex3f(-length/2, -width1/2, -height1/2); glVertex3f(-length/2, -width1/2, height1/2); glVertex3f( length/2, -width2/2, height2/2); glVertex3f( length/2, -width2/2, -height2/2); polys++; glEnd(); /* draw right */ glFrontFace(GL_CCW); glNormal3f(0, 1, 0); glBegin(wire ? GL_LINE_LOOP : GL_QUADS); glVertex3f(-length/2, width1/2, -height1/2); glVertex3f(-length/2, width1/2, height1/2); glVertex3f( length/2, width2/2, height2/2); glVertex3f( length/2, width2/2, -height2/2); polys++; glEnd(); glFrontFace(GL_CCW); return polys; }
bool BootAnimation::movie() { char bootenabled[PROPERTY_VALUE_MAX]; char bootsound[PROPERTY_VALUE_MAX]; char bootvolume[PROPERTY_VALUE_MAX]; property_get("persist.sys.boot_enabled", bootenabled, "1"); property_get("persist.sys.boot_sound", bootsound, "1"); property_get("persist.sys.boot_volume", bootvolume, "0.2"); bool bootEnabled = atoi(bootenabled) != 0; bool enableSound = atoi(bootsound) != 0; float bootVolume = strtof(bootvolume, NULL); if(!bootEnabled) { return false; } if(enableSound){ sp<MediaPlayer> mediaplay = new MediaPlayer(); mediaplay->setDataSource ("/system/media/audio.mp3", NULL); mediaplay->setVolume (bootVolume, bootVolume); mediaplay->prepare(); mediaplay->start(); } ZipFileRO& zip(mZip); size_t numEntries = zip.getNumEntries(); ZipEntryRO desc = zip.findEntryByName("desc.txt"); FileMap* descMap = zip.createEntryFileMap(desc); ALOGE_IF(!descMap, "descMap is null"); if (!descMap) { return false; } String8 desString((char const*)descMap->getDataPtr(), descMap->getDataLength()); char const* s = desString.string(); Animation animation; float r = 0.0f; float g = 0.0f; float b = 0.0f; // Parse the description file for (;;) { const char* endl = strstr(s, "\n"); if (!endl) break; String8 line(s, endl - s); const char* l = line.string(); int fps, width, height, count, pause, red, green, blue; char path[256]; char pathType; if (sscanf(l, "%d %d %d %d %d %d", &width, &height, &fps, &red, &green, &blue) == 6) { //ALOGD("> w=%d, h=%d, fps=%d, rgb=(%d, %d, %d)", width, height, fps, red, green, blue); animation.width = width; animation.height = height; animation.fps = fps; r = (float) red / 255.0f; g = (float) green / 255.0f; b = (float) blue / 255.0f; } else if (sscanf(l, "%d %d %d", &width, &height, &fps) == 3) { //LOGD("> w=%d, h=%d, fps=%d", width, height, fps); animation.width = width; animation.height = height; animation.fps = fps; } else if (sscanf(l, " %c %d %d %s", &pathType, &count, &pause, path) == 4) { //LOGD("> type=%c, count=%d, pause=%d, path=%s", pathType, count, pause, path); Animation::Part part; part.playUntilComplete = pathType == 'c'; part.count = count; part.pause = pause; part.path = path; animation.parts.add(part); } s = ++endl; } // read all the data structures const size_t pcount = animation.parts.size(); for (size_t i=0 ; i<numEntries ; i++) { char name[256]; ZipEntryRO entry = zip.findEntryByIndex(i); if (zip.getEntryFileName(entry, name, 256) == 0) { const String8 entryName(name); const String8 path(entryName.getPathDir()); const String8 leaf(entryName.getPathLeaf()); if (leaf.size() > 0) { for (size_t j=0 ; j<pcount ; j++) { if (path == animation.parts[j].path) { int method; // supports only stored png files if (zip.getEntryInfo(entry, &method, 0, 0, 0, 0, 0)) { if (method == ZipFileRO::kCompressStored) { FileMap* map = zip.createEntryFileMap(entry); if (map) { Animation::Frame frame; frame.name = leaf; frame.map = map; Animation::Part& part(animation.parts.editItemAt(j)); part.frames.add(frame); } } } } } } } } #ifndef CONTINUOUS_SPLASH // clear screen glShadeModel(GL_FLAT); glDisable(GL_DITHER); glDisable(GL_SCISSOR_TEST); glDisable(GL_BLEND); glClearColor(r,g,b,1); glClear(GL_COLOR_BUFFER_BIT); eglSwapBuffers(mDisplay, mSurface); #endif glBindTexture(GL_TEXTURE_2D, 0); glEnable(GL_TEXTURE_2D); glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); const int xc = (mWidth - animation.width) / 2; const int yc = ((mHeight - animation.height) / 2); nsecs_t lastFrame = systemTime(); nsecs_t frameDuration = s2ns(1) / animation.fps; Region clearReg(Rect(mWidth, mHeight)); clearReg.subtractSelf(Rect(xc, yc, xc+animation.width, yc+animation.height)); for (int i=0 ; i<pcount ; i++) { const Animation::Part& part(animation.parts[i]); const size_t fcount = part.frames.size(); // can be 1, 0, or not set #ifdef NO_TEXTURE_CACHE const int noTextureCache = NO_TEXTURE_CACHE; #else const int noTextureCache = ((animation.width * animation.height * fcount) > 48 * 1024 * 1024) ? 1 : 0; #endif glBindTexture(GL_TEXTURE_2D, 0); for (int r=0 ; !part.count || r<part.count ; r++) { // Exit any non playuntil complete parts immediately if(exitPending() && !part.playUntilComplete) break; for (int j=0 ; j<fcount && (!exitPending() || part.playUntilComplete) ; j++) { const Animation::Frame& frame(part.frames[j]); nsecs_t lastFrame = systemTime(); if (r > 0 && !noTextureCache) { glBindTexture(GL_TEXTURE_2D, frame.tid); } else { if (part.count != 1) { glGenTextures(1, &frame.tid); glBindTexture(GL_TEXTURE_2D, frame.tid); glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); } initTexture( frame.map->getDataPtr(), frame.map->getDataLength()); } if (!clearReg.isEmpty()) { Region::const_iterator head(clearReg.begin()); Region::const_iterator tail(clearReg.end()); glEnable(GL_SCISSOR_TEST); while (head != tail) { const Rect& r(*head++); glScissor(r.left, mHeight - r.bottom, r.width(), r.height()); glClear(GL_COLOR_BUFFER_BIT); } glDisable(GL_SCISSOR_TEST); } glDrawTexiOES(xc, yc, 0, animation.width, animation.height); eglSwapBuffers(mDisplay, mSurface); nsecs_t now = systemTime(); nsecs_t delay = frameDuration - (now - lastFrame); //ALOGD("%lld, %lld", ns2ms(now - lastFrame), ns2ms(delay)); lastFrame = now; if (delay > 0) { struct timespec spec; spec.tv_sec = (now + delay) / 1000000000; spec.tv_nsec = (now + delay) % 1000000000; int err; do { err = clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, &spec, NULL); } while (err<0 && errno == EINTR); } checkExit(); if (noTextureCache) glDeleteTextures(1, &frame.tid); } usleep(part.pause * ns2us(frameDuration)); // For infinite parts, we've now played them at least once, so perhaps exit if(exitPending() && !part.count) break; } // free the textures for this part if (part.count != 1 && !noTextureCache) { for (size_t j=0 ; j<fcount ; j++) { const Animation::Frame& frame(part.frames[j]); glDeleteTextures(1, &frame.tid); } } } return false; }
void Engine::initDisplay() { // initialize OpenGL ES and EGL /* * Here specify the attributes of the desired configuration. * Below, we select an EGLConfig with at least 8 bits per color * component compatible with on-screen windows */ const EGLint attribs[] = { EGL_SURFACE_TYPE, EGL_WINDOW_BIT, EGL_BLUE_SIZE, 8, EGL_GREEN_SIZE, 8, EGL_RED_SIZE, 8, EGL_NONE }; EGLint w, h, dummy, format; EGLint numConfigs; EGLConfig config; EGLSurface surface; EGLContext context; EGLDisplay display = eglGetDisplay(EGL_DEFAULT_DISPLAY); eglInitialize(display, 0, 0); /* Here, the application chooses the configuration it desires. In this * sample, we have a very simplified selection process, where we pick * the first EGLConfig that matches our criteria */ eglChooseConfig(display, attribs, &config, 1, &numConfigs); /* EGL_NATIVE_VISUAL_ID is an attribute of the EGLConfig that is * guaranteed to be accepted by ANativeWindow_setBuffersGeometry(). * As soon as we picked a EGLConfig, we can safely reconfigure the * ANativeWindow buffers to match, using EGL_NATIVE_VISUAL_ID. */ eglGetConfigAttrib(display, config, EGL_NATIVE_VISUAL_ID, &format); ANativeWindow_setBuffersGeometry(app->window, 0, 0, format); surface = eglCreateWindowSurface(display, config, app->window, NULL); context = eglCreateContext(display, config, NULL, NULL); if (eglMakeCurrent(display, surface, surface, context) == EGL_FALSE) { LOGD("Unable to eglMakeCurrent"); return; } eglQuerySurface(display, surface, EGL_WIDTH, &w); eglQuerySurface(display, surface, EGL_HEIGHT, &h); this->display = display; this->context = context; this->surface = surface; width = w; height = h; // Initialize GL state. glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST); glEnable(GL_CULL_FACE); glShadeModel(GL_SMOOTH); glDisable(GL_DEPTH_TEST); }
/*********************************************************** * Name: init_ogl * * Arguments: * CUBE_STATE_T *state - holds OGLES model info * * Description: Sets the display, OpenGL|ES context and screen stuff * * Returns: void * ***********************************************************/ static void init_ogl(CUBE_STATE_T *state) { int32_t success = 0; EGLBoolean result; EGLint num_config; static EGL_DISPMANX_WINDOW_T nativewindow; DISPMANX_ELEMENT_HANDLE_T dispman_element; DISPMANX_DISPLAY_HANDLE_T dispman_display; DISPMANX_UPDATE_HANDLE_T dispman_update; VC_RECT_T dst_rect; VC_RECT_T src_rect; static const EGLint attribute_list[] = { EGL_RED_SIZE, 8, EGL_GREEN_SIZE, 8, EGL_BLUE_SIZE, 8, EGL_ALPHA_SIZE, 8, EGL_DEPTH_SIZE, 16, //EGL_SAMPLES, 4, EGL_SURFACE_TYPE, EGL_WINDOW_BIT, EGL_NONE }; EGLConfig config; // get an EGL display connection state->display = eglGetDisplay(EGL_DEFAULT_DISPLAY); assert(state->display!=EGL_NO_DISPLAY); // initialize the EGL display connection result = eglInitialize(state->display, NULL, NULL); assert(EGL_FALSE != result); // get an appropriate EGL frame buffer configuration // this uses a BRCM extension that gets the closest match, rather than standard which returns anything that matches result = eglSaneChooseConfigBRCM(state->display, attribute_list, &config, 1, &num_config); assert(EGL_FALSE != result); // create an EGL rendering context state->context = eglCreateContext(state->display, config, EGL_NO_CONTEXT, NULL); assert(state->context!=EGL_NO_CONTEXT); // create an EGL window surface success = graphics_get_display_size(0 /* LCD */, &state->screen_width, &state->screen_height); assert( success >= 0 ); dst_rect.x = 0; dst_rect.y = 0; dst_rect.width = state->screen_width; dst_rect.height = state->screen_height; src_rect.x = 0; src_rect.y = 0; src_rect.width = state->screen_width << 16; src_rect.height = state->screen_height << 16; dispman_display = vc_dispmanx_display_open( 0 /* LCD */); dispman_update = vc_dispmanx_update_start( 0 ); dispman_element = vc_dispmanx_element_add ( dispman_update, dispman_display, 0/*layer*/, &dst_rect, 0/*src*/, &src_rect, DISPMANX_PROTECTION_NONE, 0 /*alpha*/, 0/*clamp*/, 0/*transform*/); nativewindow.element = dispman_element; nativewindow.width = state->screen_width; nativewindow.height = state->screen_height; vc_dispmanx_update_submit_sync( dispman_update ); state->surface = eglCreateWindowSurface( state->display, config, &nativewindow, NULL ); assert(state->surface != EGL_NO_SURFACE); // connect the context to the surface result = eglMakeCurrent(state->display, state->surface, state->surface, state->context); assert(EGL_FALSE != result); // Set background color and clear buffers glClearColor(0.15f, 0.25f, 0.35f, 1.0f); glClear( GL_COLOR_BUFFER_BIT ); glClear( GL_DEPTH_BUFFER_BIT ); glShadeModel(GL_FLAT); // Enable back face culling. glEnable(GL_CULL_FACE); }