void init (void) { glEnable( GL_TEXTURE_2D ); glEnable(GL_DEPTH_TEST); glCreateParticles(); texture[0] = LoadTextureRAW( “particle_mask.raw”,256,256 ); //load our texture texture[1] = LoadTextureRAW( “particle.raw”,256,256); //load our texture }
void init (void) { // If Depth Test is not enabled, I would see my object infront of // my polygon even if my object falls behind polygon. glClearDepth(1); glEnable(GL_DEPTH_TEST); glEnable (GL_BLEND); //glBlendFunc (GL_SRC_ALPHA, GL_ONE); glClearColor (0.0, 0.0, 0.0, 0.0); windvelocity.x = 0.5; windvelocity.y = 0.5; windvelocity.z = 0.5; buildWalls(habcount, num_tri_hab, habitat, habvert); createPredator(1); addObject(20); //buildWalls(tricount, num_triangles, triangle, vert); //cube=loadObject("birds.obj"); cube=loadObject("Fiat509_2.6.obj"); glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glShadeModel (GL_SMOOTH); glEnable (GL_LIGHTING); glEnable (GL_LIGHT0); float col[]={1.0,1.0,1.0,1.0}; //light color is white glLightfv(GL_LIGHT0,GL_DIFFUSE,col); texture[0] = LoadTextureRAW( "wood.bmp",500,334); }
void init (void) { glEnable(GL_DEPTH_TEST); glEnable( GL_TEXTURE_2D ); glDepthFunc(GL_LEQUAL); glCullFace(GL_BACK); glFrontFace(GL_CCW); glEnable(GL_CULL_FACE); texture[0] = LoadTextureRAW( "earth.raw" ); CreateSphere(70,0,0,0); }
void init() { //static GLfloat pointParam[3] = {0.0, 1.0, 0.0}; static GLfloat pointParam[3] = {0.0, 0.0, 0.001}; glEnable(GL_FOG); { GLfloat fogColor[4] = {0.0, 0.2, 0.5,1.0}; glFogi(GL_FOG_MODE, GL_EXP); glFogf(GL_FOG_DENSITY, 0.008); glHint(GL_FOG_HINT,GL_DONT_CARE); glFogf(GL_FOG_START,1.0); glFogf(GL_FOG_END,100.0); glFogfv(GL_FOG_COLOR,fogColor); } glEnable(GL_POINT_SMOOTH); glPointParameterfv(GL_POINT_DISTANCE_ATTENUATION,pointParam); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glClearColor(0.0, 0.2, 0.5, 1.0); texCyl=LoadTextureRAW("rc/plate.raw",256,512,1); texBot=LoadTextureRAW("rc/plate2.raw",256,256,1); texTop=LoadTextureRAW("rc/grate.raw",256,512,1); initNeutrons(optInitNeutrons,optMaxNeutrons,optInitEnergy,optNumTrails,optNumGroups,optCrossSections,optNumBins); frameInit(30.0); wmInit(100,100); wmAddWindow("Status",drawStatus,200,100,WM_WINDOW_LEFT, WM_WINDOW_EXPANDED,WM_WINDOW_UNMOVEABLE,WM_WINDOW_UNCOLLAPSABLE); wmAddWindow("Spectrum",drawSpectrum,400,200,WM_WINDOW_LEFT, WM_WINDOW_COLLAPSED,WM_WINDOW_UNMOVEABLE,WM_WINDOW_COLLAPSABLE); wmAddWindow("Cross Sections",drawCrossSections,400,200,WM_WINDOW_LEFT, WM_WINDOW_COLLAPSED,WM_WINDOW_MOVEABLE,WM_WINDOW_COLLAPSABLE); /*wmAddWindow("Menu",drawMenu,800,50,WM_WINDOW_BOTTOM, WM_WINDOW_EXPANDED,WM_WINDOW_UNMOVEABLE,WM_WINDOW_UNCOLLAPSABLE); */ }
void Renderer::draw() { static bool run_once = false; if (!run_once) { run_once = true; glEnable( GL_TEXTURE_2D ); ground_tex = LoadTextureRAW ("resources/ground.raw", 0); ground_tex2 = LoadTextureRAW ("resources/ground2.raw", 0); quadric = gluNewQuadric(); // Create A Pointer To The Quadric Object ( NEW ) gluQuadricNormals(quadric, GLU_SMOOTH); // Create Smooth Normals ( NEW ) gluQuadricTexture(quadric, GL_TRUE); initialize_arangl_stuff(); } // First time? init viewport, etc. if (!valid()) { valid(1); glViewport(0,0,w(),h()); avd.X = 0; avd.Y = 0; avd.Width = w(); avd.Height = h(); avd.MinZ = 0.01; avd.MaxZ = 10000.0; } // Clear screen glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //update_hero_pos(); //draw_scene_graph(); glDisable(GL_LIGHTING); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(45, double(w()) / h(), 0.01, 1000); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt(0, 0, 2, 0, 0, 0, 0, 1, 0); draw_cone_and_ground(); }
void wmInit(int mainWindowWidth, int mainWindowHeight) { mww=mainWindowWidth; mwh=mainWindowHeight; btnNormalEnd=LoadTextureRAW("rc/button_normal_end.raw",24,24,0); btnNormalMid=LoadTextureRAW("rc/button_normal_mid.raw",24,24,0); btnHoverEnd=LoadTextureRAW("rc/button_hover_end.raw",24,24,0); btnHoverMid=LoadTextureRAW("rc/button_hover_mid.raw",24,24,0); btnPressedEnd=LoadTextureRAW("rc/button_pressed_end.raw",24,24,0); btnPressedMid=LoadTextureRAW("rc/button_pressed_mid.raw",24,24,0); }
//Win32 Main methode (i.p.v. main()); int APIENTRY WinMain(HINSTANCE hCurrentInst, HINSTANCE hPreviousInst,LPSTR lpszCmdLine, int nCmdShow){ HDC hDC; /* device context */ HGLRC hRC; /* opengl context */ HWND hWnd; /* window */ MSG msg; /* message */ GLuint texture; width = rrGame.getCurLevel().getWidth(); //Elk object is 40pixels breed. height = rrGame.getCurLevel().getHeight(); //Creeer het window hWnd = CreateOpenGLWindow("minimal", 0, 0, (width*40), (height*40), PFD_TYPE_RGBA, 0); if (hWnd == NULL) exit(1); hDC = GetDC(hWnd); hRC = wglCreateContext(hDC); wglMakeCurrent(hDC, hRC); //Textures laden texture = LoadTextureRAW( "texture.raw", TRUE ); glEnable( GL_TEXTURE_2D ); glBindTexture( GL_TEXTURE_2D, texture ); //Map de textures ShowWindow(hWnd, nCmdShow); while(GetMessage(&msg, hWnd, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } wglMakeCurrent(NULL, NULL); ReleaseDC(hWnd, hDC); wglDeleteContext(hRC); DestroyWindow(hWnd); return msg.wParam; }
int main(int argc, char **argv) { glutInit(&argc, argv); // Initializes glut // Sets up a double buffer with RGBA components and a depth component glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH | GLUT_RGBA); // Sets the window size to 512*512 square pixels glutInitWindowSize(512, 512); // Sets the window position to the upper left glutInitWindowPosition(0, 0); // Creates a window using internal glut functionality glutCreateWindow("Hello!"); // passes reshape and display functions to the OpenGL machine for callback // glutReshapeFunc(reshape); glutDisplayFunc(display); glutIdleFunc(display); init(); g_texture = LoadTextureRAW("texture.raw", true); if (!g_texture) { printf("texture load error!\n"); return -1; } // Starts the program. glutMainLoop(); FreeTexture(g_texture); return 0; }
/* * Draw the room */ void display(void) { GLfloat no_mat[] = { 0.0, 0.0, 0.0, 1.0 }; GLuint texture; /* Floor properties */ GLfloat floor_diffuse[] = { 0.2, 0.5, 0.8, 1.0 }; GLfloat floor_ambient[] = { 1, 1, 1, 1.0 }; GLfloat floor_specular[] = { 0.2, 0.5, 0.8, 1.0 }; GLfloat high_shininess[] = { 100.0 }; /* Trunk & branch properties */ GLfloat wood_diffuse[] = { 0.5, 0.7, 0.1, 1.0 }; GLfloat wood_ambient[] = { 1, 1, 1, 1 }; GLfloat wood_specular[] = { 0.5, 0.7, 0.1, 1.0 }; /* Clear the output color buffer) */ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); /* Get texture */ texture = LoadTextureRAW("grass-tile.bmp", 1); glBindTexture( GL_TEXTURE_2D, texture ); /* Floor */ glPushMatrix(); glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, floor_ambient); glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, floor_diffuse); glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, floor_specular); glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, high_shininess); glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, no_mat); glBegin(GL_POLYGON); glTexCoord2f(TEX_SCALE, TEX_SCALE); glNormal3i(0, 1, 0); glVertex3i(-100, 0, -100); glTexCoord2f(TEX_SCALE, 0); glNormal3i(0, 1, 0); glVertex3i(25, 0, -100); glTexCoord2f(0, 0); glNormal3i(0, 1, 0); glVertex3i(25, 0, 25); glTexCoord2f(0, TEX_SCALE); glNormal3i(0, 1, 0); glVertex3i(-100, 0, 25); glEnd(); glPopMatrix(); glPushMatrix(); glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, wood_ambient); glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, wood_diffuse); glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, wood_specular); glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, high_shininess); glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, no_mat); glPopMatrix(); for(int i=0; i < NUM_TREES; i++) { float x = trees[i].x; float y = trees[i].y; float z = trees[i].z; #ifdef DEBUG printf("[%2.0d] x, y, z = %0.2f, %2.0f, %0.2f\n", i, x, y, z); #endif glPushMatrix(); glTranslatef(x, 0.0, z); glRotatef(-90.0, 1.0, 0.0, 0.0); glutSolidCone(0.3, y, 60, 40); glPopMatrix(); } glPushMatrix(); glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, wood_ambient); glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, wood_diffuse); glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, wood_specular); glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, high_shininess); glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, no_mat); glPopMatrix(); glutSwapBuffers(); glDeleteTextures( 1, &texture ); }
void initTextures(GLUquadricObj *quadObj) { texWood = LoadTextureRAW("wood4.raw", GL_TRUE); gluQuadricTexture(quadObj, GL_TRUE); }
Tile::Tile(char type, GLint x, GLint z) { this->type = type; this->x = x; this->z = z; Vector eastWall(x+0.5, 0, z); Vector southWall(x, 0, z+0.5); Vector westWall(x-0.5, 0, z); Vector northWall(x, 0, z-0.5); Vector eastNormal(1, 0, 0); Vector southNormal(0, 0, 1); Vector northNormal(0, 0, -1); Vector westNormal(-1, 0, 0); this->eastPlane = Plane(eastWall, eastNormal); this->southPlane = Plane(southWall, southNormal); this->westPlane = Plane(westWall, westNormal); this->northPlane = Plane(northWall, northNormal); this->wallTextureID = LoadTextureRAW(brickTexture, 1, 64, 64); this->pelletTextureID = LoadTextureRAW(pelletTexture, 1, 64, 64); if (rand()%10 > 2) { this->floorTextureID = LoadTextureRAW(floorTexture1, 1, 64, 64); } else { this->floorTextureID = LoadTextureRAW(floorTexture2, 1, 64, 64); } switch (type) { case 'W': /* Init Wall */ this->pellet = false; this->powerPellet = false; this->tile_color[0] = 0.0f; this->tile_color[1] = 0.0f; this->tile_color[2] = 1.0f; this->tile_color[3] = 1.0f; break; case 'Y': /* Init Blank */ this->pellet = false; this->powerPellet = false; this->tile_color[0] = 0.7f; this->tile_color[1] = 0.7f; this->tile_color[2] = 0.7f; this->tile_color[3] = 1.0f; break; case 'Z': /* Init Tile with Pellet */ this->pellet = true; this->powerPellet = false; this->pellet_color[0] = Color(rand()%2); this->pellet_color[1] = Color(rand()%2); this->pellet_color[2] = Color(rand()%2); this->pellet_color[3] = 1.0f; this->tile_color[0] = 0.7f; this->tile_color[1] = 0.7f; this->tile_color[2] = 0.7f; this->tile_color[3] = 1.0f; break; case 'X': /* Init Tile With Power Pellet */ this->pellet = false; this->powerPellet = true; this->pellet_color[0] = Color(rand()%2); this->pellet_color[1] = Color(rand()%2); this->pellet_color[2] = Color(rand()%2); this->pellet_color[3] = 1.0f; this->tile_color[0] = 0.7f; this->tile_color[1] = 0.7f; this->tile_color[2] = 0.7f; this->tile_color[3] = 1.0f; break; default: break; } }
int main(int argc, char **argv) { mtc_init("planet", 7); if (SDL_Init(SDL_INIT_EVERYTHING) != 0) { mtc_err("sdl init error: %s", SDL_GetError()); return 1; } if (TTF_Init() == -1) { mtc_err("ttf init error: %s", TTF_GetError()); return 1; } SDL_Window *win = SDL_CreateWindow("Hello OpenGL!", 100, 100, WIN_WIDTH, WIN_HEIGHT, SDL_WINDOW_SHOWN); if (!win) { mtc_err("SDL_CreateWindow Error: %s", SDL_GetError()); return 1; } m_render = SDL_CreateRenderer(win, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC); if (!m_render) { mtc_err("SDL_CreateRenderer Error: %s", SDL_GetError()); return 1; } set_glversion(); gl_info(); glLoadIdentity(); glOrtho(-10.0, 10.0, -10.0, 10.0, -10.0, 10.0); glEnable(GL_DEPTH_TEST); glEnable( GL_TEXTURE_2D ); glDepthFunc(GL_LEQUAL); //glCullFace(GL_BACK); //glFrontFace(GL_CCW); //glEnable(GL_CULL_FACE); GLuint etex = LoadTextureRAW("earth.raw"); if (etex == 0) { mtc_err("Load texture failure"); return 1; } mutil_create_earth(5, 0, 0, 0); SDL_Event e; bool quit = false; while (!quit) { while (SDL_PollEvent(&e)) { if (e.type == SDL_KEYDOWN) { switch (e.key.keysym.sym) { case SDLK_ESCAPE: quit = true; break; } } } rend_sun(); mutil_rend_earth(etex); SDL_RenderPresent(m_render); } SDL_DestroyRenderer(m_render); SDL_DestroyWindow(win); SDL_Quit(); return 0; }