// // pie_SetFogStatus(bool val) // // Toggle fog on and off for rendering objects inside or outside the 3D world // void pie_SetFogStatus(bool val) { float fog_colour[4]; if (rendStates.fogEnabled) { //fog enabled so toggle if required if (rendStates.fog != val) { rendStates.fog = val; if (rendStates.fog) { PIELIGHT fog = pie_GetFogColour(); fog_colour[0] = fog.byte.r / 255.0f; fog_colour[1] = fog.byte.g / 255.0f; fog_colour[2] = fog.byte.b / 255.0f; fog_colour[3] = fog.byte.a / 255.0f; glFogi(GL_FOG_MODE, GL_LINEAR); glFogfv(GL_FOG_COLOR, fog_colour); glFogf(GL_FOG_DENSITY, 0.35f); glHint(GL_FOG_HINT, GL_DONT_CARE); glEnable(GL_FOG); } else { glDisable(GL_FOG); } } } else { //fog disabled so turn it off if not off already if (rendStates.fog != false) { rendStates.fog = false; } } }
int InitGL(GLvoid) { GLfloat LightAmbientA[]= { 0.5f, 0.5f, 0.5f, 1.0f }; GLfloat LightDiffuseA[]= { 0.4f, 0.4f, 0.4f, 1.0f }; GLfloat LightSpecularA[]= { 0.7f, 0.7f, 0.5f, 1.0f }; GLfloat LightPositionA[]= { 0.0f, 15.0f, 0.0f, 1.0f }; GLfloat fgcolor[]= { 0.0f,0.0f,0.0f }; if (!LoadGLTextures()) { return FALSE; } Init(); Auto->reloadTextures(); // Load tekstur model Ruota->reloadTextures(); // Loads tekstur model glShadeModel(GL_SMOOTH); glClearColor(0.0f, 0.0f, 0.0f, 0.5f); glClearDepth(1.0f); glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LEQUAL); glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); glLightfv(GL_LIGHT0, GL_AMBIENT, LightAmbientA); // Setup cahaya ambient glLightfv(GL_LIGHT0, GL_DIFFUSE, LightDiffuseA); // Setup cahaya Diffuse glLightfv(GL_LIGHT0, GL_POSITION,LightPositionA); // Posisi cahaya glLightfv(GL_LIGHT0, GL_SPECULAR, LightSpecularA); // Setup cahaya Ambient glEnable(GL_LIGHT0); glFogfv(GL_FOG_COLOR,fgcolor); glFogf(GL_FOG_START,120.0f); glFogf(GL_FOG_END,200.0f); glFogf(GL_FOG_MODE,GL_LINEAR); // glEnable(GL_FOG); return TRUE; }
void Init() { glClearColor(1, 1, 1,1); glewExperimental = GL_TRUE; glewInit (); glMatrixMode( GL_PROJECTION); glLoadIdentity(); gluPerspective(45, 1366.0/768.0, 0.1, 1000); glMatrixMode( GL_MODELVIEW); glLoadIdentity(); //glHint ( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST ); //glEnable ( GL_CULL_FACE ); //glShadeModel ( GL_FLAT ); //glCullFace ( GL_BACK ); //glEnable(GL_DEPTH); //glEnable( GL_LIGHTING); //glEnable( GL_LIGHT0); //glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); //glHint( GL_LINE_SMOOTH_HINT, GL_NICEST); //glEnable( GL_BLEND); // glEnable( GL_LINE_SMOOTH); //glLineWidth(1.0f); eng = new Game(288,512); eng->StartDraw(); GLfloat FogColor[4]={1,1,1,1}; glEnable(GL_FOG); glFogi(GL_FOG_MODE,GL_LINEAR); glFogf(GL_FOG_START,60.0); glFogf(GL_FOG_END,150.0); glFogfv(GL_FOG_COLOR,FogColor); }
void Fog::SetFog(float colorR, float colorG, float colorB, float fStart, float fEnd, float Density) { GLfloat newfogColor[4]; newfogColor[0] = colorR; newfogColor[1] = colorG; newfogColor[2] = colorB; newfogColor[3] = 1; fogStart = fStart; fogEnd = fEnd; fogDensity = Density; fogMode = GL_LINEAR; glFogi(GL_FOG_MODE, fogMode); glFogfv(GL_FOG_COLOR, newfogColor); glFogf(GL_FOG_DENSITY, fogDensity); glFogi(GL_FOG_HINT, GL_DONT_CARE); glFogf(GL_FOG_START, fogStart); glFogf(GL_FOG_END, fogEnd); glEnable(GL_FOG); }
void CFarTextureHandler::Draw() { if (queuedForRender.empty()) { return; } //! create new faricons for (GML_VECTOR<const CSolidObject*>::iterator it = queuedForRender.begin(); it != queuedForRender.end(); ++it) { const CSolidObject& obj = **it; if (cache.size()<=obj.team || cache[obj.team].size()<=obj.model->id || !cache[obj.team][obj.model->id]) { CreateFarTexture(*it); } } glEnable(GL_ALPHA_TEST); glAlphaFunc(GL_GREATER, 0.5f); glActiveTexture(GL_TEXTURE0); glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, farTexture); glColor4f(1.0f, 1.0f, 1.0f, 1.0f); glNormal3fv((const GLfloat*) &unitDrawer->camNorm.x); if (globalRendering->drawFog) { glFogfv(GL_FOG_COLOR, mapInfo->atmosphere.fogColor); glEnable(GL_FOG); } CVertexArray* va = GetVertexArray(); va->Initialize(); va->EnlargeArrays(queuedForRender.size() * 4, 0, VA_SIZE_T); for (GML_VECTOR<const CSolidObject*>::iterator it = queuedForRender.begin(); it != queuedForRender.end(); ++it) { DrawFarTexture(*it, va); } va->DrawArrayT(GL_QUADS); glDisable(GL_ALPHA_TEST); queuedForRender.clear(); }
/* * R_EnableFog */ void R_EnableFog(boolean_t enable) { if (!r_fog->value || r_state.fog_enabled == enable) return; r_state.fog_enabled = false; if (enable) { if ((r_view.weather & WEATHER_FOG) || r_fog->integer == 2) { r_state.fog_enabled = true; glFogfv(GL_FOG_COLOR, r_view.fog_color); glFogf(GL_FOG_DENSITY, 1.0); glEnable(GL_FOG); } } else { glFogf(GL_FOG_DENSITY, 0.0); glDisable(GL_FOG); } }
void ObjectView::EnforceState() { glShadeModel(fGouraud ? GL_SMOOTH : GL_FLAT); if (fZbuf) glEnable(GL_DEPTH_TEST); else glDisable(GL_DEPTH_TEST); if (fCulling) glEnable(GL_CULL_FACE); else glDisable(GL_CULL_FACE); if (fLighting) glEnable(GL_LIGHTING); else glDisable(GL_LIGHTING); if (fFilled) glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); else glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); if (fFog) { glFogf(GL_FOG_START, 10.0); glFogf(GL_FOG_DENSITY, 0.2); glFogf(GL_FOG_END, depthOfView); glFogfv(GL_FOG_COLOR, foggy); glEnable(GL_FOG); bgColor = foggy; glClearColor(bgColor[0], bgColor[1], bgColor[2], 1.0); } else { glDisable(GL_FOG); bgColor = black; glClearColor(bgColor[0], bgColor[1], bgColor[2], 1.0); } }
void VisorOpenGL::initializeGL() { glClearColor(1.0,1.0,1.0,1.0); glShadeModel(GL_FLAT); glEnable(GL_DEPTH_TEST); glEnable(GL_CULL_FACE); //glEnable(GL_NORMALIZE); //Configurar signal idle timer = new QTimer(this); connect(timer, SIGNAL(timeout()), this, SLOT(idle())); timer->start(); // Configurar niebla GLfloat density = 0.0020; density = 0.0016;//0.006; GLfloat fogColor[4] = {0.5f, 0.5f, 0.5f, 1.0f}; glFogi (GL_FOG_MODE, GL_EXP2); glFogfv (GL_FOG_COLOR, fogColor); glFogf (GL_FOG_DENSITY, density); glHint (GL_FOG_HINT, GL_NICEST); //glEnable (GL_FOG); }
//============================================================================== void cFog::render(cRenderOptions& a_options) { #ifdef C_USE_OPENGL if ((!m_enabled) || (a_options.m_creating_shadow_map)) { // fog is disabled glDisable(GL_FOG); return; } // enable fog and define attributes glEnable(GL_FOG); glFogi(GL_FOG_MODE, m_fogMode); glFogfv(GL_FOG_COLOR, m_color.pColor()); glFogf(GL_FOG_DENSITY, m_density); glHint(GL_FOG_HINT, GL_NICEST); glFogf(GL_FOG_START, m_start); glFogf(GL_FOG_END, m_end); #endif }
void myinit (void) { glShadeModel (GL_SMOOTH); glFrontFace(GL_CCW); glEnable(GL_DEPTH_TEST); glClearColor(fogcol[0], fogcol[1], fogcol[2], fogcol[3]); glLightfv(GL_LIGHT0, GL_POSITION, lightpos); glLightfv(GL_LIGHT0, GL_AMBIENT, lightamb); glLightfv(GL_LIGHT0, GL_DIFFUSE, lightdif); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glColor3f(1.0, 1.0, 1.0); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); #ifdef FOG /* fog */ glEnable(GL_FOG); glFogi(GL_FOG_MODE, GL_LINEAR); glFogfv(GL_FOG_COLOR, fogcol); glFogf(GL_FOG_DENSITY, 0.01); glFogf(GL_FOG_START, 0.01); glFogf(GL_FOG_END, 55.0); glHint(GL_FOG_HINT, GL_NICEST); #endif make_texture(); init_wheel(); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); /* glTexImage2D(GL_TEXTURE_2D, 0, 3, 32, 32, 0, GL_RGB, GL_UNSIGNED_BYTE, &texture[0][0][0]); */ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); }
//____________________________________________________________________________ void Camera::setViewFogMode(bool trigger, float red, float green, float blue, float alpha, float density, float start, float end, GLint fogmode, GLint glhint_target,GLint glhint_mode ) { // Nebel: zuerst Nebelfarbe im RGBA Format also {R,G,B,alpha} -->z.Z.Schwarz float fogColor[4] = {red,green,blue,alpha}; /* : fog mode:The params parameter is a single integer or floating-point value that specifies the equation to be used to compute the fog blend factor, f. Three symbolic constants are accepted: GL_LINEAR, GL_EXP, and GL_EXP2. The equations corresponding to these symbolic constants are defined in the following Remarks section. The default fog mode is GL_EXP */ glFogi(GL_FOG_MODE,fogmode); // unser fogColor wird uebergeben glFogfv(GL_FOG_COLOR, fogColor); // Dichte :default ist 1.0 glFogf(GL_FOG_DENSITY,density); /* Die Qualitaet des Nebels parameter siehe camera.h */ glHint(glhint_target,glhint_mode); // der Anfang des Nebels von der Camera aus! glFogf(GL_FOG_START,start); // "das Ende des Sichtbaren Bereiches" e.g. bei 30 beginnt der Nebel und ab 60 ist nichts mehr zusehen glFogf(GL_FOG_END, end); // und Feuer --> zum abschalten glDisable(GL_FOG); if (trigger == true){ glEnable(GL_FOG);} else {glDisable(GL_FOG);}; }
void FogPlane::setup() { if ( !m_isOn || getparam_disable_fog() ) { glDisable( GL_FOG ); return; } glEnable( GL_FOG ); glFogi( GL_FOG_MODE, m_mode ); glFogf( GL_FOG_DENSITY, m_density ); glFogf( GL_FOG_START, m_start ); glFogf( GL_FOG_END, m_end ); glFogfv( GL_FOG_COLOR, m_color ); if ( getparam_nice_fog() ) { glHint( GL_FOG_HINT, GL_NICEST ); } else { glHint( GL_FOG_HINT, GL_FASTEST ); } }
void CFog6_7::init() { CLearnOpenGLBase::init(); GLfloat position[] = { 0.5, 0.5, 3.0, 0.0 }; glLightfv(GL_LIGHT0, GL_POSITION, position); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); { GLfloat mat[3] = { 0.1745, 0.01175, 0.01175 }; glMaterialfv(GL_FRONT, GL_AMBIENT, mat); mat[0] = 0.61424; mat[1] = 0.04136; mat[2] = 0.04136; glMaterialfv(GL_FRONT, GL_DIFFUSE, mat); mat[0] = 0.727811; mat[1] = 0.626959; mat[2] = 0.626959; glMaterialfv(GL_FRONT, GL_SPECULAR, mat); glMaterialf(GL_FRONT, GL_SHININESS, 0.6 * 128.0); } glEnable(GL_FOG); { GLfloat fogColor[4] = { 0.5, 0.5, 0.5, 1.0 }; glFogi(GL_FOG_MODE, m_efogMode); glFogfv(GL_FOG_COLOR, fogColor); glFogf(GL_FOG_DENSITY, 0.35); glHint(GL_FOG_HINT, GL_DONT_CARE); glFogf(GL_FOG_START, 1.0); glFogf(GL_FOG_END, 5.0); } glClearColor(0.5, 0.5, 0.5, 1.0); }
void draw_gl(Evas_Object *obj) { ELEMENTARY_GLVIEW_USE(obj); struct { GLint x, y, width, height; } viewPort; glGetIntegerv(GL_VIEWPORT, (GLint*)&viewPort); { const double PI = 3.141592; static double hue = 0.0; float r = (1.0f + static_cast<float>(sin(hue - 2.0 * PI / 3.0))) / 3.0f; float g = (1.0f + static_cast<float>(sin(hue) )) / 3.0f; float b = (1.0f + static_cast<float>(sin(hue + 2.0 * PI / 3.0))) / 3.0f; GLfloat fogColor[4] = { r, g, b, 1.0f }; glFogfv(GL_FOG_COLOR, fogColor); glClearColorEx(GetGlUnit(r), GetGlUnit(g), GetGlUnit(b), GetGlUnit(1.0f)); hue += 0.03; } glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); GlesCube11_DrawCube1(obj); GlesCube11_DrawCube2(obj); }
/* --- functions --- */ void renderer_scene_setup() { gfloat LightAmbient[]= {1.0f, 1.0f, 1.0f, 1.0f}; gfloat LightDiffuse[]= {1.0f, 1.0f, 0.99f, 1.0f}; gfloat lightPos[] = {0.0f, 0.0f, 0.0f, 1.0f}; gfloat fogColor[4] = {0.0f, 0.0f, 0.0f, 1.0f}; glShadeModel(GL_SMOOTH); glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); glDepthFunc(GL_LEQUAL); glEnable(GL_DEPTH_TEST); glCullFace(GL_BACK); glEnable(GL_CULL_FACE); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glDisable(GL_BLEND); glClearColor(fogColor[0], fogColor[1], fogColor[2], fogColor[3]); glClearDepth(1.0f); glLightfv(GL_LIGHT0, GL_AMBIENT, LightAmbient); glLightfv(GL_LIGHT0, GL_DIFFUSE, LightDiffuse); glLightfv(GL_LIGHT0, GL_POSITION, lightPos); glEnable(GL_LIGHT0); glHint(GL_FOG_HINT, GL_DONT_CARE); glFogi(GL_FOG_MODE, GL_EXP); glFogi(GL_FOG_COORD_SRC, GL_FRAGMENT_DEPTH); glFogfv(GL_FOG_COLOR, fogColor); glFogf(GL_FOG_DENSITY, 0.15f); glEnable(GL_FOG); glColor4f(1.0f, 1.0f, 1.0f, 1.0f); }
void myInit() { glActiveTexture(GL_TEXTURE0); //make the background look like the sky float blue[4] = {0.5,0.5,1.0,0.0}; glClearColor(0.5, 0.5, 1.0, 0.0); glShadeModel(GL_SMOOTH); glEnable(GL_FOG); glFogfv(GL_FOG_COLOR,blue); glFogf(GL_FOG_MODE, GL_EXP2); glFogf(GL_FOG_START, 200); glFogf(GL_FOG_END, 1000); glFogf(GL_FOG_DENSITY, gFogDensity); //initial terrain myTerrain.initializeTerrain("../Data/Texture/Terrain/sand.tga", "../Data/Texture/Terrain/cactus.tga"); //initial ground collision square groundCollSquare.setParameters(TVector(0.0, 1.0, 0.0), gCenterPoint); //initial tank tankHeightPos = myTerrain.GetHeight(gCenterPoint.X()+100.0, gCenterPoint.Z()); myTank.setParameters("T-90.3DS", "../T-90/",TVector(gCenterPoint.X()-600.0, tankHeightPos + 9.0, gCenterPoint.Z()-20), 0.0, &myTerrain, &collisionBoxArray, &wall); myTank.initTank(); unsigned int brickTexture; createTexture("../Data/Texture/Brick/brick.bmp", brickTexture); wall.Init(myTank.getPosition().X() + 50, myTank.getPosition().Y()-8, myTank.getPosition().Z() + 20, NUM_BRICKS, brickTexture, &myTerrain); }
virtual void render() { // Enable fog if (fog) { glEnable(GL_FOG); GLfloat fogColor[] = {0.2, 0.2, 0.2, 1}; glFogfv(GL_FOG_COLOR, fogColor); glFogf(GL_FOG_MODE, GL_EXP); glFogf(GL_FOG_DENSITY, 0.02); //glFogf(GL_FOG_START, 6); //glFogf(GL_FOG_END, 20); } else { glDisable(GL_FOG); } // Prepare lighting LightManager::resetLights(); GLfloat ambLight[] = {0.1, 0.1, 0.1, 1.0}; //GLfloat moonLight[] = {1, 1, 1, 1.0}; //GLfloat moonDir[] = {1, 1, 0.1, 0}; // TODO: toggle via keyboard //glEnable(GL_LIGHTING); // ambient int amb = LightManager::getNextLight(); if (amb > 0) { glLightfv(amb, GL_AMBIENT, ambLight); } // moonlight //glLightfv(GL_LIGHT1, GL_DIFFUSE, moonLight); //glLightfv(GL_LIGHT1, GL_POSITION, moonDir); glEnable(GL_TEXTURE_2D); // defer to super Scene::render(); glDisable(GL_TEXTURE_2D); }
static void init( void ) { float fogcolor[4]={0.6,0.7,0.7,1.0}; glClearColor(fogcolor[0],fogcolor[1],fogcolor[2],fogcolor[3]); glClearDepth(1.0); glDepthFunc(GL_LEQUAL); glShadeModel(GL_SMOOTH); glEnable(GL_DEPTH_TEST); glEnable(GL_CULL_FACE); glDisable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_FOG); glFogi(GL_FOG_MODE,GL_EXP2); glFogfv(GL_FOG_COLOR,fogcolor); glFogf(GL_FOG_DENSITY,0.0007); #ifdef FX glHint(GL_FOG_HINT,GL_NICEST); #endif reshape(scrwidth,scrheight); }
void initialise() { glClearColor(0.0f, 1.0f, 1.0f, 1.0f); projection = glm::perspective(glm::degrees(glm::quarter_pi<float>()), 800.0f/600.0f, 0.1f, 10000.0f); glEnable(GL_DEPTH_TEST); glEnable(GL_VERTEX_ARRAY); shaders[0] = loadShader("diffuse.vert", GL_VERTEX_SHADER); shaders[1] = loadShader("diffuse.frag", GL_FRAGMENT_SHADER); if (shaders[0] && shaders[1]) { program = createProgram(shaders, 2); if (!program) exit(EXIT_FAILURE); } else exit(EXIT_FAILURE); MVPuniform = glGetUniformLocation(program, "modelViewProjection"); MITuniform = glGetUniformLocation(program, "modelInverseTranspose"); diffuseMaterialUniform = glGetUniformLocation(program, "diffuseMaterial"); diffuseLightUniform = glGetUniformLocation(program, "diffuseLight"); lightDirUniform = glGetUniformLocation(program, "lightDir"); object.geometry = createBox(); glFogi(GL_FOG_MODE, fogMode[fogfilter]); glFogfv(GL_FOG_COLOR, fogColour); glFogf(GL_FOG_DENSITY, 0.35f); glHint(GL_FOG_HINT, GL_DONT_CARE); glFogf(GL_FOG_START, 1.0f); glFogf(GL_FOG_END, 5.0f); glEnable(GL_FOG); }
// selfDraw draws in 3D using the default ofEasyCamera // you can change the camera by returning getCameraRef() void CloudsVisualSystemMazeGenerator::selfDraw() { ofPushStyle(); glDisable(GL_CULL_FACE); ofEnableDepthTest(); // draw fog ofFloatColor fc = settings.getFogColor(); GLfloat fogColor[4] = {fc.r, fc.g, fc.b, 1.0}; glFogfv (GL_FOG_COLOR, fogColor); glFogi(GL_FOG_COORD_SRC, GL_FRAGMENT_DEPTH); glFogi(GL_FOG_MODE, GL_LINEAR); glHint(GL_FOG_HINT, GL_DONT_CARE); glFogf(GL_FOG_DENSITY, powf(settings.fogDensity, 2)); glFogf(GL_FOG_START, settings.fogStart); glFogf(GL_FOG_END, settings.fogEnd); glEnable(GL_FOG); if (bLights) { light->enable(); } maze[0]->draw(&mazeCam, lightPos); if (bLights) { light->disable(); } // disable fog glDisable(GL_FOG); ofPopStyle(); }
/* Initialize depth buffer, fog, light source, * material property, and lighting model. */ static void initFog(void) { GLfloat position[] = { 0.5, 0.5, 3.0, 0.0 }; glEnable(GL_DEPTH_TEST); glLightfv(GL_LIGHT0, GL_POSITION, position); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); { GLfloat mat[3] = { 0.1745, 0.01175, 0.01175 }; glMaterialfv(GL_FRONT, GL_AMBIENT, mat); mat[0] = 0.61424; mat[1] = 0.04136; mat[2] = 0.04136; glMaterialfv(GL_FRONT, GL_DIFFUSE, mat); mat[0] = 0.727811; mat[1] = 0.626959; mat[2] = 0.626959; glMaterialfv(GL_FRONT, GL_SPECULAR, mat); glMaterialf(GL_FRONT, GL_SHININESS, 0.6 * 128.0); } glEnable(GL_FOG); { GLfloat fogColor[4] = { 0.5, 0.5, 0.5, 1.0 }; fogMode = GL_EXP; glFogi(GL_FOG_MODE, fogMode); glFogfv(GL_FOG_COLOR, fogColor); glFogf(GL_FOG_DENSITY, 0.35); glHint(GL_FOG_HINT, GL_DONT_CARE); glFogf(GL_FOG_START, 1.0); glFogf(GL_FOG_END, 5.0); } glClearColor(0.5, 0.5, 0.5, 1.0); /* fog color */ }
void ingame_level1_setup(Game* game){ audioplayer_set_next(game->audio,"music/Goto80_gopho_level1.ogg"); glClearColor(1,1,1,1); // game->player->x=0; // game->player->y=0; // game->player->z=0; // game->player->theta=0; game->update=ingame_level1_update; game->render=ingame_level1_render; game->weapon=1; set_time_(0); glEnable(GL_FOG); glFogi(GL_FOG_MODE, GL_LINEAR);//GL_EXP, GL_EXP2, GL_LINEAR glFogf(GL_FOG_START, 20); glFogf(GL_FOG_END, 300); // glFogi(GL_FOG_MODE, GL_EXP);//GL_EXP, GL_EXP2, GL_LINEAR // glFogi(GL_FOG_MODE, GL_EXP2);//GL_EXP, GL_EXP2, GL_LINEAR // glFogf(GL_FOG_START, 2000); // glFogf(GL_FOG_END, 3000); GLfloat fogColor[4]= {1,1, 1, 1}; glFogfv(GL_FOG_COLOR, fogColor); glFogf(GL_FOG_DENSITY, 0.35f); glHint(GL_FOG_HINT, GL_DONT_CARE); glFogf(GL_FOG_START, 20); glFogf(GL_FOG_END, 50); level1_spawn_mechants(game); }
void Fog :: On() { // set the fog type if(type==FogExp) glFogi(GL_FOG_MODE,GL_EXP); else if(type==FogExp2) glFogi(GL_FOG_MODE,GL_EXP2); else glFogi(GL_FOG_MODE,GL_LINEAR); // set fog colour float glcol[4] = { col.red , col.green, col.blue , 1.0f }; glFogfv(GL_FOG_COLOR,glcol); // set density glFogf(GL_FOG_DENSITY,density); // set extents glFogf(GL_FOG_START,fnear); glFogf(GL_FOG_END,ffar); // set hint glHint(GL_FOG_HINT,GL_DONT_CARE); // and switch on fog glEnable(GL_FOG); }
void CGraphics::initGL() { //interpolem colors glShadeModel(GL_SMOOTH); //color per borrar la pantalla i profunditat glClearColor(0.0f,0.0f,0.0f,1.0f); glClearDepth( 1.0f ); //parametres de la boira float fogColor[4]; fogColor[0] = 0.0f; fogColor[1] = 0.0f; fogColor[2] = 0.0f; fogColor[3] = 1.0f; //parametres de la boira glFogi(GL_FOG_MODE, GL_LINEAR); glFogfv(GL_FOG_COLOR, fogColor); glFogf(GL_FOG_DENSITY, 0.15f); glHint(GL_FOG_HINT, GL_NICEST); glFogf(GL_FOG_START, 50.0f); glFogf(GL_FOG_END, 230.0f); glEnable(GL_FOG); fogActive = true; //activem el test de profunditat glEnable( GL_DEPTH_TEST ); glDepthFunc( GL_LEQUAL ); //activem la funcio de blending glBlendFunc( GL_ONE, GL_ONE ); //bona correccio de perspectiva glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST ); }
void FRenderState::Apply(bool forcenoshader) { if (!gl_direct_state_change) { if (mSrcBlend != glSrcBlend || mDstBlend != glDstBlend) { glSrcBlend = mSrcBlend; glDstBlend = mDstBlend; glBlendFunc(mSrcBlend, mDstBlend); } if (mAlphaFunc != glAlphaFunc || mAlphaThreshold != glAlphaThreshold) { glAlphaFunc = mAlphaFunc; glAlphaThreshold = mAlphaThreshold; ::glAlphaFunc(mAlphaFunc, mAlphaThreshold); } if (mAlphaTest != glAlphaTest) { glAlphaTest = mAlphaTest; if (mAlphaTest) glEnable(GL_ALPHA_TEST); else glDisable(GL_ALPHA_TEST); } if (mBlendEquation != glBlendEquation) { glBlendEquation = mBlendEquation; ::glBlendEquation(mBlendEquation); } } if (forcenoshader || !ApplyShader()) { GLRenderer->mShaderManager->SetActiveShader(NULL); if (mTextureMode != ffTextureMode) { gl_SetTextureMode((ffTextureMode = mTextureMode)); } if (mTextureEnabled != ffTextureEnabled) { if ((ffTextureEnabled = mTextureEnabled)) glEnable(GL_TEXTURE_2D); else glDisable(GL_TEXTURE_2D); } if (mFogEnabled != ffFogEnabled) { if ((ffFogEnabled = mFogEnabled)) { glEnable(GL_FOG); } else glDisable(GL_FOG); } if (mFogEnabled) { if (ffFogColor != mFogColor) { ffFogColor = mFogColor; GLfloat FogColor[4]={mFogColor.r/255.0f,mFogColor.g/255.0f,mFogColor.b/255.0f,0.0f}; glFogfv(GL_FOG_COLOR, FogColor); } if (ffFogDensity != mFogDensity) { glFogf(GL_FOG_DENSITY, mFogDensity/64000.f); ffFogDensity=mFogDensity; } } if (mSpecialEffect != ffSpecialEffect) { switch (ffSpecialEffect) { case EFF_SPHEREMAP: glDisable(GL_TEXTURE_GEN_T); glDisable(GL_TEXTURE_GEN_S); default: break; } switch (mSpecialEffect) { case EFF_SPHEREMAP: // Use sphere mapping for this glEnable(GL_TEXTURE_GEN_T); glEnable(GL_TEXTURE_GEN_S); glTexGeni(GL_S,GL_TEXTURE_GEN_MODE,GL_SPHERE_MAP); glTexGeni(GL_T,GL_TEXTURE_GEN_MODE,GL_SPHERE_MAP); break; default: break; } ffSpecialEffect = mSpecialEffect; } } }
int main(int /*argc*/, char** /*argv*/) { // Init SDL if (SDL_Init(SDL_INIT_EVERYTHING) != 0) { printf("Could not initialise SDL\n"); return -1; } // Center window char env[] = "SDL_VIDEO_CENTERED=1"; putenv(env); // Init OpenGL SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24); SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8); //#ifndef WIN32 SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1); SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 4); //#endif const SDL_VideoInfo* vi = SDL_GetVideoInfo(); bool presentationMode = false; int width, height; SDL_Surface* screen = 0; if (presentationMode) { width = 1700; height = 1000; screen = SDL_SetVideoMode(width, height, 0, SDL_OPENGL|SDL_FULLSCREEN); } else { width = 1700; height = 1000; screen = SDL_SetVideoMode(width, height, 0, SDL_OPENGL); } if (!screen) { printf("Could not initialise SDL opengl\n"); return -1; } glEnable(GL_MULTISAMPLE); SDL_WM_SetCaption("Recast Demo", 0); if (!imguiRenderGLInit("DroidSans.ttf")) { printf("Could not init GUI renderer.\n"); SDL_Quit(); return -1; } float t = 0.0f; float timeAcc = 0.0f; Uint32 lastTime = SDL_GetTicks(); int mx = 0, my = 0; float rx = 45; float ry = -45; float moveW = 0, moveS = 0, moveA = 0, moveD = 0; float camx = 0, camy = 0, camz = 0, camr = 1000; float origrx = 0, origry = 0; int origx = 0, origy = 0; float scrollZoom = 0; bool rotate = false; bool movedDuringRotate = false; float rays[3], raye[3]; bool mouseOverMenu = false; bool showMenu = !presentationMode; bool showLog = false; bool showTools = true; bool showLevels = false; bool showSample = false; bool showTestCases = false; int propScroll = 0; int logScroll = 0; int toolsScroll = 0; char sampleName[64] = "Choose Sample..."; FileList files; char meshName[128] = "Choose Mesh..."; float mpos[3] = {0,0,0}; bool mposSet = false; SlideShow slideShow; slideShow.init("slides/"); InputGeom* geom = 0; Sample* sample = 0; TestCase* test = 0; BuildContext ctx; glEnable(GL_CULL_FACE); float fogCol[4] = { 0.32f, 0.31f, 0.30f, 1.0f }; glEnable(GL_FOG); glFogi(GL_FOG_MODE, GL_LINEAR); glFogf(GL_FOG_START, camr*0.1f); glFogf(GL_FOG_END, camr*1.25f); glFogfv(GL_FOG_COLOR, fogCol); glDepthFunc(GL_LEQUAL); bool done = false; while(!done) { // Handle input events. int mscroll = 0; bool processHitTest = false; bool processHitTestShift = false; SDL_Event event; while (SDL_PollEvent(&event)) { switch (event.type) { case SDL_KEYDOWN: // Handle any key presses here. if (event.key.keysym.sym == SDLK_ESCAPE) { done = true; } else if (event.key.keysym.sym == SDLK_t) { showLevels = false; showSample = false; showTestCases = true; scanDirectory("Tests", ".txt", files); } else if (event.key.keysym.sym == SDLK_TAB) { showMenu = !showMenu; } else if (event.key.keysym.sym == SDLK_SPACE) { if (sample) sample->handleToggle(); } else if (event.key.keysym.sym == SDLK_1) { if (sample) sample->handleStep(); } else if (event.key.keysym.sym == SDLK_9) { if (geom) geom->save("geomset.txt"); } else if (event.key.keysym.sym == SDLK_0) { delete geom; geom = new InputGeom; if (!geom || !geom->load(&ctx, "geomset.txt")) { delete geom; geom = 0; showLog = true; logScroll = 0; ctx.dumpLog("Geom load log %s:", meshName); } if (sample && geom) { sample->handleMeshChanged(geom); } if (geom || sample) { const float* bmin = 0; const float* bmax = 0; if (sample) { bmin = sample->getBoundsMin(); bmax = sample->getBoundsMax(); } else if (geom) { bmin = geom->getMeshBoundsMin(); bmax = geom->getMeshBoundsMax(); } // Reset camera and fog to match the mesh bounds. if (bmin && bmax) { camr = sqrtf(rcSqr(bmax[0]-bmin[0]) + rcSqr(bmax[1]-bmin[1]) + rcSqr(bmax[2]-bmin[2])) / 2; camx = (bmax[0] + bmin[0]) / 2 + camr; camy = (bmax[1] + bmin[1]) / 2 + camr; camz = (bmax[2] + bmin[2]) / 2 + camr; camr *= 3; } rx = 45; ry = -45; glFogf(GL_FOG_START, camr*0.2f); glFogf(GL_FOG_END, camr*1.25f); } } else if (event.key.keysym.sym == SDLK_RIGHT) { slideShow.nextSlide(); } else if (event.key.keysym.sym == SDLK_LEFT) { slideShow.prevSlide(); } break; case SDL_MOUSEBUTTONDOWN: if (event.button.button == SDL_BUTTON_RIGHT) { if (!mouseOverMenu) { // Rotate view rotate = true; movedDuringRotate = false; origx = mx; origy = my; origrx = rx; origry = ry; } } else if (event.button.button == SDL_BUTTON_WHEELUP) { if (mouseOverMenu) mscroll--; else scrollZoom -= 1.0f; } else if (event.button.button == SDL_BUTTON_WHEELDOWN) { if (mouseOverMenu) mscroll++; else scrollZoom += 1.0f; } break; case SDL_MOUSEBUTTONUP: // Handle mouse clicks here. if (event.button.button == SDL_BUTTON_RIGHT) { rotate = false; if (!mouseOverMenu) { if (!movedDuringRotate) { processHitTest = true; processHitTestShift = true; } } } else if (event.button.button == SDL_BUTTON_LEFT) { if (!mouseOverMenu) { processHitTest = true; processHitTestShift = (SDL_GetModState() & KMOD_SHIFT) ? true : false; } } break; case SDL_MOUSEMOTION: mx = event.motion.x; my = height-1 - event.motion.y; if (rotate) { int dx = mx - origx; int dy = my - origy; rx = origrx - dy*0.25f; ry = origry + dx*0.25f; if (dx*dx+dy*dy > 3*3) movedDuringRotate = true; } break; case SDL_QUIT: done = true; break; default: break; } } unsigned char mbut = 0; if (SDL_GetMouseState(0,0) & SDL_BUTTON_LMASK) mbut |= IMGUI_MBUT_LEFT; if (SDL_GetMouseState(0,0) & SDL_BUTTON_RMASK) mbut |= IMGUI_MBUT_RIGHT; Uint32 time = SDL_GetTicks(); float dt = (time - lastTime) / 1000.0f; lastTime = time; t += dt; // Hit test mesh. if (processHitTest && geom && sample) { float hitt; bool hit = geom->raycastMesh(rays, raye, hitt); if (hit) { if (SDL_GetModState() & KMOD_CTRL) { // Marker mposSet = true; mpos[0] = rays[0] + (raye[0] - rays[0])*hitt; mpos[1] = rays[1] + (raye[1] - rays[1])*hitt; mpos[2] = rays[2] + (raye[2] - rays[2])*hitt; } else { float pos[3]; pos[0] = rays[0] + (raye[0] - rays[0])*hitt; pos[1] = rays[1] + (raye[1] - rays[1])*hitt; pos[2] = rays[2] + (raye[2] - rays[2])*hitt; sample->handleClick(rays, pos, processHitTestShift); } } else { if (SDL_GetModState() & KMOD_CTRL) { // Marker mposSet = false; } } } // Update sample simulation. const float SIM_RATE = 20; const float DELTA_TIME = 1.0f/SIM_RATE; timeAcc = rcClamp(timeAcc+dt, -1.0f, 1.0f); int simIter = 0; while (timeAcc > DELTA_TIME) { timeAcc -= DELTA_TIME; if (simIter < 5) { if (sample) sample->handleUpdate(DELTA_TIME); } simIter++; } // Clamp the framerate so that we do not hog all the CPU. const float MIN_FRAME_TIME = 1.0f/40.0f; if (dt < MIN_FRAME_TIME) { int ms = (int)((MIN_FRAME_TIME - dt)*1000.0f); if (ms > 10) ms = 10; if (ms >= 0) SDL_Delay(ms); } // Update and render glViewport(0, 0, width, height); glClearColor(0.3f, 0.3f, 0.32f, 1.0f); glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glDisable(GL_TEXTURE_2D); // Render 3d glEnable(GL_DEPTH_TEST); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(50.0f, (float)width/(float)height, 1.0f, camr); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glRotatef(rx,1,0,0); glRotatef(ry,0,1,0); glTranslatef(-camx, -camy, -camz); // Get hit ray position and direction. GLdouble proj[16]; GLdouble model[16]; GLint view[4]; glGetDoublev(GL_PROJECTION_MATRIX, proj); glGetDoublev(GL_MODELVIEW_MATRIX, model); glGetIntegerv(GL_VIEWPORT, view); GLdouble x, y, z; gluUnProject(mx, my, 0.0f, model, proj, view, &x, &y, &z); rays[0] = (float)x; rays[1] = (float)y; rays[2] = (float)z; gluUnProject(mx, my, 1.0f, model, proj, view, &x, &y, &z); raye[0] = (float)x; raye[1] = (float)y; raye[2] = (float)z; // Handle keyboard movement. Uint8* keystate = SDL_GetKeyState(NULL); moveW = rcClamp(moveW + dt * 4 * (keystate[SDLK_w] ? 1 : -1), 0.0f, 1.0f); moveS = rcClamp(moveS + dt * 4 * (keystate[SDLK_s] ? 1 : -1), 0.0f, 1.0f); moveA = rcClamp(moveA + dt * 4 * (keystate[SDLK_a] ? 1 : -1), 0.0f, 1.0f); moveD = rcClamp(moveD + dt * 4 * (keystate[SDLK_d] ? 1 : -1), 0.0f, 1.0f); float keybSpeed = 22.0f; if (SDL_GetModState() & KMOD_SHIFT) keybSpeed *= 4.0f; float movex = (moveD - moveA) * keybSpeed * dt; float movey = (moveS - moveW) * keybSpeed * dt; movey += scrollZoom * 2.0f; scrollZoom = 0; camx += movex * (float)model[0]; camy += movex * (float)model[4]; camz += movex * (float)model[8]; camx += movey * (float)model[2]; camy += movey * (float)model[6]; camz += movey * (float)model[10]; glEnable(GL_FOG); if (sample) sample->handleRender(); if (test) test->handleRender(); glDisable(GL_FOG); // Render GUI glDisable(GL_DEPTH_TEST); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(0, width, 0, height); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); mouseOverMenu = false; imguiBeginFrame(mx,my,mbut,mscroll); if (sample) { sample->handleRenderOverlay((double*)proj, (double*)model, (int*)view); } if (test) { if (test->handleRenderOverlay((double*)proj, (double*)model, (int*)view)) mouseOverMenu = true; } // Help text. if (showMenu) { const char msg[] = "W/S/A/D: Move RMB: Rotate"; imguiDrawText(280, height-20, IMGUI_ALIGN_LEFT, msg, imguiRGBA(255,255,255,128)); } if (showMenu) { if (imguiBeginScrollArea("Properties", width-250-10, 10, 250, height-20, &propScroll)) mouseOverMenu = true; if (imguiCheck("Show Log", showLog)) showLog = !showLog; if (imguiCheck("Show Tools", showTools)) showTools = !showTools; imguiSeparator(); imguiLabel("Sample"); if (imguiButton(sampleName)) { if (showSample) { showSample = false; } else { showSample = true; showLevels = false; showTestCases = false; } } imguiSeparator(); imguiLabel("Input Mesh"); if (imguiButton(meshName)) { if (showLevels) { showLevels = false; } else { showSample = false; showTestCases = false; showLevels = true; scanDirectory("Meshes", ".obj", files); } } if (geom) { char text[64]; snprintf(text, 64, "Verts: %.1fk Tris: %.1fk", geom->getMesh()->getVertCount()/1000.0f, geom->getMesh()->getTriCount()/1000.0f); imguiValue(text); } imguiSeparator(); if (geom && sample) { imguiSeparatorLine(); sample->handleSettings(); if (imguiButton("Build")) { ctx.resetLog(); if (!sample->handleBuild()) { showLog = true; logScroll = 0; } ctx.dumpLog("Build log %s:", meshName); // Clear test. delete test; test = 0; } imguiSeparator(); } if (sample) { imguiSeparatorLine(); sample->handleDebugMode(); } imguiEndScrollArea(); } // Sample selection dialog. if (showSample) { static int levelScroll = 0; if (imguiBeginScrollArea("Choose Sample", width-10-250-10-200, height-10-250, 200, 250, &levelScroll)) mouseOverMenu = true; Sample* newSample = 0; for (int i = 0; i < g_nsamples; ++i) { if (imguiItem(g_samples[i].name)) { newSample = g_samples[i].create(); if (newSample) strcpy(sampleName, g_samples[i].name); } } if (newSample) { delete sample; sample = newSample; sample->setContext(&ctx); if (geom && sample) { sample->handleMeshChanged(geom); } showSample = false; } if (geom || sample) { const float* bmin = 0; const float* bmax = 0; if (sample) { bmin = sample->getBoundsMin(); bmax = sample->getBoundsMax(); } else if (geom) { bmin = geom->getMeshBoundsMin(); bmax = geom->getMeshBoundsMax(); } // Reset camera and fog to match the mesh bounds. if (bmin && bmax) { camr = sqrtf(rcSqr(bmax[0]-bmin[0]) + rcSqr(bmax[1]-bmin[1]) + rcSqr(bmax[2]-bmin[2])) / 2; camx = (bmax[0] + bmin[0]) / 2 + camr; camy = (bmax[1] + bmin[1]) / 2 + camr; camz = (bmax[2] + bmin[2]) / 2 + camr; camr *= 3; } rx = 45; ry = -45; glFogf(GL_FOG_START, camr*0.1f); glFogf(GL_FOG_END, camr*1.25f); } imguiEndScrollArea(); } // Level selection dialog. if (showLevels) { static int levelScroll = 0; if (imguiBeginScrollArea("Choose Level", width-10-250-10-200, height-10-450, 200, 450, &levelScroll)) mouseOverMenu = true; int levelToLoad = -1; for (int i = 0; i < files.size; ++i) { if (imguiItem(files.files[i])) levelToLoad = i; } if (levelToLoad != -1) { strncpy(meshName, files.files[levelToLoad], sizeof(meshName)); meshName[sizeof(meshName)-1] = '\0'; showLevels = false; delete geom; geom = 0; char path[256]; strcpy(path, "Meshes/"); strcat(path, meshName); geom = new InputGeom; if (!geom || !geom->loadMesh(&ctx, path)) { delete geom; geom = 0; showLog = true; logScroll = 0; ctx.dumpLog("Geom load log %s:", meshName); } if (sample && geom) { sample->handleMeshChanged(geom); } if (geom || sample) { const float* bmin = 0; const float* bmax = 0; if (sample) { bmin = sample->getBoundsMin(); bmax = sample->getBoundsMax(); } else if (geom) { bmin = geom->getMeshBoundsMin(); bmax = geom->getMeshBoundsMax(); } // Reset camera and fog to match the mesh bounds. if (bmin && bmax) { camr = sqrtf(rcSqr(bmax[0]-bmin[0]) + rcSqr(bmax[1]-bmin[1]) + rcSqr(bmax[2]-bmin[2])) / 2; camx = (bmax[0] + bmin[0]) / 2 + camr; camy = (bmax[1] + bmin[1]) / 2 + camr; camz = (bmax[2] + bmin[2]) / 2 + camr; camr *= 3; } rx = 45; ry = -45; glFogf(GL_FOG_START, camr*0.1f); glFogf(GL_FOG_END, camr*1.25f); } } imguiEndScrollArea(); } // Test cases if (showTestCases) { static int testScroll = 0; if (imguiBeginScrollArea("Choose Test To Run", width-10-250-10-200, height-10-450, 200, 450, &testScroll)) mouseOverMenu = true; int testToLoad = -1; for (int i = 0; i < files.size; ++i) { if (imguiItem(files.files[i])) testToLoad = i; } if (testToLoad != -1) { char path[256]; strcpy(path, "Tests/"); strcat(path, files.files[testToLoad]); test = new TestCase; if (test) { // Load the test. if (!test->load(path)) { delete test; test = 0; } // Create sample Sample* newSample = 0; for (int i = 0; i < g_nsamples; ++i) { if (strcmp(g_samples[i].name, test->getSampleName()) == 0) { newSample = g_samples[i].create(); if (newSample) strcpy(sampleName, g_samples[i].name); } } if (newSample) { delete sample; sample = newSample; sample->setContext(&ctx); showSample = false; } // Load geom. strcpy(meshName, test->getGeomFileName()); meshName[sizeof(meshName)-1] = '\0'; delete geom; geom = 0; strcpy(path, "Meshes/"); strcat(path, meshName); geom = new InputGeom; if (!geom || !geom->loadMesh(&ctx, path)) { delete geom; geom = 0; showLog = true; logScroll = 0; ctx.dumpLog("Geom load log %s:", meshName); } if (sample && geom) { sample->handleMeshChanged(geom); } // This will ensure that tile & poly bits are updated in tiled sample. if (sample) sample->handleSettings(); ctx.resetLog(); if (sample && !sample->handleBuild()) { ctx.dumpLog("Build log %s:", meshName); } if (geom || sample) { const float* bmin = 0; const float* bmax = 0; if (sample) { bmin = sample->getBoundsMin(); bmax = sample->getBoundsMax(); } else if (geom) { bmin = geom->getMeshBoundsMin(); bmax = geom->getMeshBoundsMax(); } // Reset camera and fog to match the mesh bounds. if (bmin && bmax) { camr = sqrtf(rcSqr(bmax[0]-bmin[0]) + rcSqr(bmax[1]-bmin[1]) + rcSqr(bmax[2]-bmin[2])) / 2; camx = (bmax[0] + bmin[0]) / 2 + camr; camy = (bmax[1] + bmin[1]) / 2 + camr; camz = (bmax[2] + bmin[2]) / 2 + camr; camr *= 3; } rx = 45; ry = -45; glFogf(GL_FOG_START, camr*0.2f); glFogf(GL_FOG_END, camr*1.25f); } // Do the tests. if (sample) test->doTests(sample->getNavMesh(), sample->getNavMeshQuery()); } } imguiEndScrollArea(); } // Log if (showLog && showMenu) { if (imguiBeginScrollArea("Log", 250+20, 10, width - 300 - 250, 200, &logScroll)) mouseOverMenu = true; for (int i = 0; i < ctx.getLogCount(); ++i) imguiLabel(ctx.getLogText(i)); imguiEndScrollArea(); } // Tools if (!showTestCases && showTools && showMenu) // && geom && sample) { if (imguiBeginScrollArea("Tools", 10, 10, 250, height-20, &toolsScroll)) mouseOverMenu = true; if (sample) sample->handleTools(); imguiEndScrollArea(); } slideShow.updateAndDraw(dt, (float)width, (float)height); // Marker if (mposSet && gluProject((GLdouble)mpos[0], (GLdouble)mpos[1], (GLdouble)mpos[2], model, proj, view, &x, &y, &z)) { // Draw marker circle glLineWidth(5.0f); glColor4ub(240,220,0,196); glBegin(GL_LINE_LOOP); const float r = 25.0f; for (int i = 0; i < 20; ++i) { const float a = (float)i / 20.0f * RC_PI*2; const float fx = (float)x + cosf(a)*r; const float fy = (float)y + sinf(a)*r; glVertex2f(fx,fy); } glEnd(); glLineWidth(1.0f); } imguiEndFrame(); imguiRenderGLDraw(); glEnable(GL_DEPTH_TEST); SDL_GL_SwapBuffers(); } imguiRenderGLDestroy(); SDL_Quit(); delete sample; delete geom; return 0; }
void hack_init (xstuff_t * XStuff) { int i, j, k; hack_reshape (XStuff); if (dTexture == 9) /* Choose random texture */ dTexture = rsRandi (9); if (dTexture != 2 && dTexture != 6) /* No z-buffering for crystal or ghostly */ glEnable (GL_DEPTH_TEST); if (dTexture != 3 && dTexture != 4 && dTexture != 6) { /* No lighting for chrome, brass, or ghostly */ float ambient[4] = { 0.0f, 0.0f, 0.0f, 0.0f }; float diffuse[4] = { 1.0f, 1.0f, 1.0f, 0.0f }; float specular[4] = { 1.0f, 1.0f, 1.0f, 0.0f }; float position[4] = { 400.0f, 300.0f, 500.0f, 0.0f }; /* float position[4] = {0.0f, 0.0f, 0.0f, 1.0f}; */ glEnable (GL_LIGHTING); glEnable (GL_LIGHT0); glLightModeli (GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE); glLightfv (GL_LIGHT0, GL_AMBIENT, ambient); glLightfv (GL_LIGHT0, GL_DIFFUSE, diffuse); glLightfv (GL_LIGHT0, GL_SPECULAR, specular); glLightfv (GL_LIGHT0, GL_POSITION, position); } glEnable (GL_COLOR_MATERIAL); if (dTexture == 0 || dTexture == 5 || dTexture >= 7) { glMaterialf (GL_FRONT, GL_SHININESS, 50.0f); glColorMaterial (GL_FRONT, GL_SPECULAR); } if (dTexture == 2) { glMaterialf (GL_FRONT, GL_SHININESS, 10.0f); glColorMaterial (GL_FRONT, GL_SPECULAR); } glColorMaterial (GL_FRONT, GL_AMBIENT_AND_DIFFUSE); if (dFog) { float fog_color[4] = { 0.0f, 0.0f, 0.0f, 0.0f }; glEnable (GL_FOG); glFogfv (GL_FOG_COLOR, fog_color); glFogf (GL_FOG_MODE, GL_LINEAR); glFogf (GL_FOG_START, (float)dDrawdepth * 0.3f); glFogf (GL_FOG_END, (float)dDrawdepth - 0.1f); } if (dTexture == 2 || dTexture == 6) { /* Use blending for crystal and ghostly */ glBlendFunc (GL_SRC_ALPHA, GL_ONE); glEnable (GL_BLEND); } if (dTexture == 7) { /* Use blending for circuits */ glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable (GL_BLEND); } if (dTexture) { glEnable (GL_TEXTURE_2D); initTextures (); } /* * Initialize lattice objects and their positions in the lattice array */ makeLatticeObjects (); for (i = 0; i < LATSIZE; i++) { for (j = 0; j < LATSIZE; j++) { for (k = 0; k < LATSIZE; k++) { lattice[i][j][k] = list_base + rsRandi (NUMOBJECTS); } } } /* * Initialize border points horizontal border points */ /* * horizontal border points */ for (i = 0; i < 6; i++) { for (j = 0; j < 6; j++) { bPnt[i][j] = 0.0f; } } bPnt[0][0] = 0.5f; bPnt[0][1] = -0.25f; bPnt[0][2] = 0.25f; bPnt[0][3] = 1.0f; /* right */ bPnt[1][0] = 0.5f; bPnt[1][1] = 0.25f; bPnt[1][2] = -0.25f; bPnt[1][3] = 1.0f; /* right */ bPnt[2][0] = -0.25f; bPnt[2][1] = 0.5f; bPnt[2][2] = 0.25f; bPnt[2][4] = 1.0f; /* top */ bPnt[3][0] = 0.25f; bPnt[3][1] = 0.5f; bPnt[3][2] = -0.25f; bPnt[3][4] = 1.0f; /* top */ bPnt[4][0] = -0.25f; bPnt[4][1] = -0.25f; bPnt[4][2] = 0.5f; bPnt[4][5] = 1.0f; /* front */ bPnt[5][0] = 0.25f; bPnt[5][1] = 0.25f; bPnt[5][2] = 0.5f; bPnt[5][5] = 1.0f; /* front */ /* * diagonal border points */ bPnt[6][0] = 0.5f; bPnt[6][1] = -0.5f; bPnt[6][2] = -0.5f; bPnt[6][3] = 1.0f; bPnt[6][4] = -1.0f; bPnt[6][5] = -1.0f; bPnt[7][0] = 0.5f; bPnt[7][1] = 0.5f; bPnt[7][2] = -0.5f; bPnt[7][3] = 1.0f; bPnt[7][4] = 1.0f; bPnt[7][5] = -1.0f; bPnt[8][0] = 0.5f; bPnt[8][1] = -0.5f; bPnt[8][2] = 0.5f; bPnt[8][3] = 1.0f; bPnt[8][4] = -1.0f; bPnt[8][5] = 1.0f; bPnt[9][0] = 0.5f; bPnt[9][1] = 0.5f; bPnt[9][2] = 0.5f; bPnt[9][3] = 1.0f; bPnt[9][4] = 1.0f; bPnt[9][5] = 1.0f; globalxyz[0] = 0; globalxyz[1] = 0; globalxyz[2] = 0; /* * Set up first path section */ path[0][0] = 0.0f; path[0][1] = 0.0f; path[0][2] = 0.0f; path[0][3] = 0.0f; path[0][4] = 0.0f; path[0][5] = 0.0f; j = rsRandi (12); k = j % 6; for (i = 0; i < 6; i++) path[1][i] = bPnt[k][i]; if (j > 5) { /* If we want to head in a negative direction */ i = k / 2; /* then we need to flip along the appropriate axis */ path[1][i] *= -1.0f; path[1][i + 3] *= -1.0f; } lastBorder = k; segments = 1; }
void glPopAttrib() { //printf("glPopAttrib()\n"); noerrorShim(); if ((state.list.compiling || state.gl_batch) && state.list.active) { NewStage(state.list.active, STAGE_POP); state.list.active->popattribute = true; return; } if (stack == NULL || stack->len == 0) { errorShim(GL_STACK_UNDERFLOW); return; } glstack_t *cur = stack + stack->len-1; if (cur->mask & GL_COLOR_BUFFER_BIT) { enable_disable(GL_ALPHA_TEST, cur->alpha_test); glAlphaFunc(cur->alpha_test_func, cur->alpha_test_ref); enable_disable(GL_BLEND, cur->blend); glBlendFunc(cur->blend_src_func, cur->blend_dst_func); enable_disable(GL_DITHER, cur->dither); enable_disable(GL_COLOR_LOGIC_OP, cur->color_logic_op); glLogicOp(cur->logic_op); GLfloat *c; glClearColor(v4(cur->clear_color)); glColorMask(v4(cur->color_mask)); } if (cur->mask & GL_CURRENT_BIT) { glColor4f(v4(cur->color)); glNormal3f(v3(cur->normal)); glTexCoord2f(v2(cur->tex)); } if (cur->mask & GL_DEPTH_BUFFER_BIT) { enable_disable(GL_DEPTH_TEST, cur->depth_test); glDepthFunc(cur->depth_func); glClearDepth(cur->clear_depth); glDepthMask(cur->depth_mask); } if (cur->mask & GL_ENABLE_BIT) { int i; enable_disable(GL_ALPHA_TEST, cur->alpha_test); enable_disable(GL_AUTO_NORMAL, cur->autonormal); enable_disable(GL_BLEND, cur->blend); GLint max_clip_planes; glGetIntegerv(GL_MAX_CLIP_PLANES, &max_clip_planes); for (i = 0; i < max_clip_planes; i++) { enable_disable(GL_CLIP_PLANE0 + i, *(cur->clip_planes_enabled + i)); } enable_disable(GL_COLOR_MATERIAL, cur->colormaterial); enable_disable(GL_CULL_FACE, cur->cull_face); enable_disable(GL_DEPTH_TEST, cur->depth_test); enable_disable(GL_DITHER, cur->dither); enable_disable(GL_FOG, cur->fog); GLint max_lights; glGetIntegerv(GL_MAX_LIGHTS, &max_lights); for (i = 0; i < max_lights; i++) { enable_disable(GL_LIGHT0 + i, *(cur->lights_enabled + i)); } enable_disable(GL_LIGHTING, cur->lighting); enable_disable(GL_LINE_SMOOTH, cur->line_smooth); enable_disable(GL_LINE_STIPPLE, cur->line_stipple); enable_disable(GL_COLOR_LOGIC_OP, cur->color_logic_op); //TODO: GL_INDEX_LOGIC_OP //TODO: GL_MAP1_x //TODO: GL_MAP2_x enable_disable(GL_MULTISAMPLE, cur->multisample); enable_disable(GL_NORMALIZE, cur->normalize); enable_disable(GL_POINT_SMOOTH, cur->point_smooth); //TODO: GL_POLYGON_OFFSET_LINE enable_disable(GL_POLYGON_OFFSET_FILL, cur->polygon_offset_fill); //TODO: GL_POLYGON_OFFSET_POINT //TODO: GL_POLYGON_SMOOTH //TODO: GL_POLYGON_STIPPLE enable_disable(GL_SAMPLE_ALPHA_TO_COVERAGE, cur->sample_alpha_to_coverage); enable_disable(GL_SAMPLE_ALPHA_TO_ONE, cur->sample_alpha_to_one); enable_disable(GL_SAMPLE_COVERAGE, cur->sample_coverage); enable_disable(GL_SCISSOR_TEST, cur->scissor_test); enable_disable(GL_STENCIL_TEST, cur->stencil_test); int a; int old_tex = state.texture.active; for (a=0; a<MAX_TEX; a++) { if (state.enable.texture_1d[a] != cur->texture_1d[a]) { glActiveTexture(GL_TEXTURE0+a); enable_disable(GL_TEXTURE_1D, cur->texture_1d[a]); } if (state.enable.texture_2d[a] != cur->texture_2d[a]) { glActiveTexture(GL_TEXTURE0+a); enable_disable(GL_TEXTURE_2D, cur->texture_2d[a]); } if (state.enable.texture_3d[a] != cur->texture_3d[a]) { glActiveTexture(GL_TEXTURE0+a); enable_disable(GL_TEXTURE_3D, cur->texture_3d[a]); } state.enable.texgen_r[a] = cur->texgen_r[a]; state.enable.texgen_s[a] = cur->texgen_s[a]; state.enable.texgen_t[a] = cur->texgen_t[a]; } if (state.texture.active != old_tex) glActiveTexture(GL_TEXTURE0+old_tex); } if (cur->mask & GL_FOG_BIT) { enable_disable(GL_FOG, cur->fog); glFogfv(GL_FOG_COLOR, cur->fog_color); glFogf(GL_FOG_DENSITY, cur->fog_density); glFogf(GL_FOG_START, cur->fog_start); glFogf(GL_FOG_END, cur->fog_end); glFogf(GL_FOG_MODE, cur->fog_mode); } if (cur->mask & GL_HINT_BIT) { enable_disable(GL_PERSPECTIVE_CORRECTION_HINT, cur->perspective_hint); enable_disable(GL_POINT_SMOOTH_HINT, cur->point_smooth_hint); enable_disable(GL_LINE_SMOOTH_HINT, cur->line_smooth_hint); enable_disable(GL_FOG_HINT, cur->fog_hint); enable_disable(GL_GENERATE_MIPMAP_HINT, cur->mipmap_hint); } // GL_LIST_BIT if (cur->mask & GL_LIST_BIT) { glListBase(cur->list_base); } if (cur->mask & GL_LINE_BIT) { enable_disable(GL_LINE_SMOOTH, cur->line_smooth); // TODO: stipple stuff here glLineWidth(cur->line_width); } if (cur->mask & GL_MULTISAMPLE_BIT) { enable_disable(GL_MULTISAMPLE, cur->multisample); enable_disable(GL_SAMPLE_ALPHA_TO_COVERAGE, cur->sample_alpha_to_coverage); enable_disable(GL_SAMPLE_ALPHA_TO_ONE, cur->sample_alpha_to_one); enable_disable(GL_SAMPLE_COVERAGE, cur->sample_coverage); } if (cur->mask & GL_POINT_BIT) { enable_disable(GL_POINT_SMOOTH, cur->point_smooth); glPointSize(cur->point_size); } if (cur->mask & GL_SCISSOR_BIT) { enable_disable(GL_SCISSOR_TEST, cur->scissor_test); glScissor(v4(cur->scissor_box)); } if (cur->mask & GL_STENCIL_BUFFER_BIT) { enable_disable(GL_STENCIL_TEST, cur->stencil_test); glStencilFunc(cur->stencil_func, cur->stencil_ref, cur->stencil_mask); //TODO: Stencil value mask glStencilOp(cur->stencil_sfail, cur->stencil_dpfail, cur->stencil_dppass); glClearStencil(cur->stencil_clearvalue); //TODO: Stencil buffer writemask } if (cur->mask & GL_TEXTURE_BIT) { int a; //TODO: Enable bit for the 4 texture coordinates for (a=0; a<MAX_TEX; a++) { state.enable.texgen_r[a] = cur->texgen_r[a]; state.enable.texgen_s[a] = cur->texgen_s[a]; state.enable.texgen_t[a] = cur->texgen_t[a]; state.texgen[a] = cur->texgen[a]; // all mode and planes per texture in 1 line if ((cur->texture[a]==0 && state.texture.bound[a] != 0) || (cur->texture[a]!=0 && state.texture.bound[a]==0)) { glActiveTexture(GL_TEXTURE0+a); glBindTexture(GL_TEXTURE_2D, cur->texture[a]); } } if (state.texture.active!= cur->active) glActiveTexture(GL_TEXTURE0+cur->active); } if (cur->mask & GL_PIXEL_MODE_BIT) { GLenum pixel_name[] = {GL_RED_BIAS, GL_RED_SCALE, GL_GREEN_BIAS, GL_GREEN_SCALE, GL_BLUE_BIAS, GL_BLUE_SCALE, GL_ALPHA_BIAS, GL_ALPHA_SCALE}; int i; for (i=0; i<8; i++) glPixelTransferf(pixel_name[i], cur->pixel_scale_bias[i]); //TODO: GL_DEPTH_BIAS & GL_DEPTH_SCALE (probably difficult) //TODO: GL_INDEX_OFFEST & GL_INDEX_SHIFT //TODO: GL_MAP_COLOR & GL_MAP_STENCIL (probably difficult too) glPixelZoom(cur->pixel_zoomx, cur->pixel_zoomy); } if (cur->mask & GL_TRANSFORM_BIT) { if (!(cur->mask & GL_ENABLE_BIT)) { int i; GLint max_clip_planes; glGetIntegerv(GL_MAX_CLIP_PLANES, &max_clip_planes); for (i = 0; i < max_clip_planes; i++) { enable_disable(GL_CLIP_PLANE0 + i, *(cur->clip_planes_enabled + i)); } } glMatrixMode(cur->matrix_mode); enable_disable(GL_NORMALIZE, cur->normalize_flag); enable_disable(GL_RESCALE_NORMAL, cur->rescale_normal_flag); } if (cur->mask & GL_VIEWPORT_BIT) { glViewport(cur->viewport_size[0], cur->viewport_size[1], cur->viewport_size[2], cur->viewport_size[3]); glDepthRangef(cur->depth_range[0], cur->depth_range[1]); } maybe_free(cur->clip_planes_enabled); maybe_free(cur->clip_planes); maybe_free(cur->lights_enabled); maybe_free(cur->lights); stack->len--; }
void SetupAnimation(int w, int h) { //if (h <= 1080) //{ // _num_stars = 2500; _display_rings = 1; _display_nebulae = 1; //} Width = w / 10; Height = h / 6; GLdouble aspect = ((double)w / (double)h) * 10.0; glShadeModel(GL_FLAT); glViewport(0, 0, (GLint) w, (GLint) h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(aspect, (GLdouble)w/(GLdouble)h,(GLdouble)nearest, (GLdouble)farthest); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt(0.0, 0.0, (GLdouble)(nearest - 20), 0.0, 0.0, 0.0, 0.0, 1.0, 0.0); glFogi(GL_FOG_MODE, GL_LINEAR); // Fog Mode GLfloat fogColor[4]= {0.9f, 0.9f, 0.9f, 1.0f}; // Fog Color glFogfv(GL_FOG_COLOR, fogColor); // Set Fog Color glFogf(GL_FOG_DENSITY, 1.0f); // How Dense Will The Fog Be glHint(GL_FOG_HINT, GL_FASTEST); // Fog Hint Value glFogf(GL_FOG_END, nearest); // Fog Start Depth glFogf(GL_FOG_START, farthest); // Fog End Depth glEnable(GL_FOG); // Enables GL_FOG //camera xyz, the xyz to look at, and the up vector (+y is up) _stars = (_lp_vertex)malloc(_num_stars * sizeof(_vertex)); _rings = (_lp_vertex)malloc(_num_rings * sizeof(_vertex)); _nebulae = (_lp_vertex)malloc(_num_neb * sizeof(_vertex)); _srings = (int*)malloc(_num_rings * sizeof(int)); _sringidx = (int*)malloc(_num_rings * sizeof(int)); LoadTextures(); int i; _lp_vertex _curr = _stars; srand((unsigned)26351024); for (i = 0; i < _num_stars; i++) { _curr->z = nearest + 1; CheckStar(_curr, i); _curr++; } _curr = _rings; for (i = 0; i < _num_rings; i++) { _curr->z = nearest + 1; CheckRing(_curr, i, 1); _curr++; } _curr = _nebulae; for (i = 0; i < _num_neb; i++) { _curr->z = nearest + 1; CheckNebula(_curr, i); _curr++; } SortRings(0); _spin_triggers[0] = SetTrigger(TRIG_SLOWEST, 165); //delta is in frames _spin_triggers[1] = SetTrigger(TRIG_SLOWEST, 200); //delta is in frames _spin_triggers[2] = SetTrigger(TRIG_FASTEST, 1265); //delta is in frames }
void init(void) { dragonmodel.generateBody(); dragonmodel.generateTail(); // Shift values just once dragonmodel.animateDragon(&Pitch,&Yaw,&Roll,1.5); tex_2D = SOIL_load_OGL_texture ( "dragonscales.jpg", SOIL_LOAD_RGBA, SOIL_CREATE_NEW_ID, SOIL_FLAG_NTSC_SAFE_RGB ); // glGenTextures(1,&tex_2D); // glDeleteTextures(1,&tex_2D); ///////////////// fog stuff glEnable (GL_DEPTH_TEST); //enable the depth testing glEnable (GL_FOG); //enable the fog glEnable(GL_BLEND);//enables alpha blend glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glFogi (GL_FOG_MODE, GL_EXP2); //set the fog mode to GL_EXP2 glFogfv (GL_FOG_COLOR, fogColor); //set the fog color to our color chosen above //lFogf (GL_FOG_DENSITY, density); //set the density to the value above glHint (GL_FOG_HINT, GL_NICEST); // set the fog to look the nicest, may slow down on older cards /////////////////////end of fog stuff cam_radius = 100; cam_phi = 0.69; cam_theta = -3.99; wanted_cam_radius = 45; // Setting cam position to origin // It is irreleveant since radius has been set to 10, // therefore, thses values will be recalculated later. cam_position[0] = 10; cam_position[1] = 10; cam_position[2] = 10; // Point camera to center of dragon cam_target[0] = 0; cam_target[1] = 40; cam_target[2] = 0; // Setting camera's Up vector // In this case, Up is the +Yaxis cam_up[0] = 0; cam_up[1] = 1; cam_up[2] = 0; //cam_phi = 0.99; //cam_theta = -3.99; glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(90*zoom, (GLfloat)w/(GLfloat)h, 1.0, 10000.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); //Background Color //Cornflower Blue //Original Code: 100-149-237 //glClearColor (0.390625, 0.58203125, 0.92578125, 0.0); glClearColor(0,0,0,0); glEnable (GL_BLEND); glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_DEPTH_TEST); glShadeModel (GL_SMOOTH); //Sets lighting // glLightfv(GL_LIGHT0, GL_AMBIENT, white); glLightfv(GL_LIGHT0, GL_DIFFUSE, white); glLightfv(GL_LIGHT0, GL_SPECULAR, white); glLightf(GL_LIGHT0, GL_SPOT_EXPONENT, 2.0); // glLightf(GL_LIGHT0, disp, 1.0); // glLightf(GL_LIGHT0, GL_LINEAR_ATTENUATION, 0.0); glLightf(GL_LIGHT0, GL_LINEAR_ATTENUATION, 0.0015); glLightfv(GL_LIGHT7, GL_DIFFUSE, white); glLightfv(GL_LIGHT7, GL_SPECULAR, white); glLightfv(GL_LIGHT5, GL_DIFFUSE, white); glLightfv(GL_LIGHT5, GL_SPECULAR, white); //glLightf(GL_LIGHT5, GL_SPOT_EXPONENT, 2.0); glLightf(GL_LIGHT0, GL_QUADRATIC_ATTENUATION, 0.15); glLightfv(GL_LIGHT1, GL_DIFFUSE, blue); glLightf(GL_LIGHT1, GL_SPOT_EXPONENT, 2.0); // glLightfv(GL_LIGHT2, GL_DIFFUSE, red); // glLightf(GL_LIGHT2, GL_SPOT_EXPONENT, 2.0); // Allows color on models with lighting glEnable(GL_COLOR_MATERIAL); // glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE); //glColorMaterial(GL_FRONT, GL_SPECULAR); //glMaterialf(GL_FRONT, GL_SHININESS, 100); glLightfv(GL_LIGHT4, GL_DIFFUSE, suncolor); glLightf(GL_LIGHT4, GL_LINEAR_ATTENUATION, 0.00); glLightfv(GL_LIGHT0, GL_SPECULAR, white); glEnable(GL_LIGHT0); glEnable(GL_LIGHT4); glEnable(GL_LIGHT7); glEnable(GL_LIGHT5); //glEnable(GL_LIGHT1); //glEnable(GL_LIGHT2); glEnable(GL_LIGHTING); }