//Texture Load Function static unsigned int load_texture(const std::string& filename,unsigned int& width,unsigned int& height) { //Check for Bad Window if(glutGetWindow()==0) throw std::runtime_error("msl::load_texture - opengl not loaded, are you loading the texture in the correct place?"); //Load Texture unsigned int return_texture=SOIL_load_OGL_texture(filename.c_str(),SOIL_LOAD_AUTO,SOIL_CREATE_NEW_ID,SOIL_FLAG_MIPMAPS|SOIL_FLAG_DDS_LOAD_DIRECT); //Load Texture Data unsigned char* texture_data=SOIL_load_image(filename.c_str(),reinterpret_cast<int*>(&width),reinterpret_cast<int*>(&height),NULL,SOIL_LOAD_AUTO); //Check for Bad Filename if(return_texture==0||texture_data==NULL) throw std::runtime_error("msl::load_texture - bad filename, is the filename correct?"); //Clean Up delete[] texture_data; //Return Good Texture return return_texture; }
bool NEHE17::LoadGLTextures(const char* dir, int textureID){ /* load an image file directly as a new OpenGL texture */ texture[textureID] = SOIL_load_OGL_texture ( Utils::getAbsoluteDir(dir), SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_INVERT_Y ); if(texture[textureID] == 0){ return false; } // Typical Texture Generation Using Data From The Bitmap glBindTexture(GL_TEXTURE_2D, texture[textureID]); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); return true; }
Renderer::Renderer(Window &parent) : OGLRenderer(parent) { camera = new Camera(0,0,Vector3(0,0,100)); cube = new OBJMesh(MESHDIR"centeredCube.obj"); //A cube surrounding the origin! triangle = Mesh::GenerateTriangle(); //And a triangle to use as the mouse pointer... cube->SetTexture(SOIL_load_OGL_texture(TEXTUREDIR"brick.tga",SOIL_LOAD_AUTO,SOIL_CREATE_NEW_ID, SOIL_FLAG_MIPMAPS)); if(!cube->GetTexture()) { return; } //We don't need to do anything fancy with shaders this time around, so we're //going to borrow the scene shader from tutorial 6 currentShader = new Shader(SHADERDIR"SceneVertex.glsl", SHADERDIR"SceneFragment.glsl"); if(!currentShader->LinkProgram()) { return; } //Our renderer's root node! root = new SceneNode(); root->SetBoundingRadius(0.0f); //To show off picking, we're going to Make a 10 by 10 grid of cubes. //As they're all going to be children of the root node, all 100 //of them will be drawn using a single draw call on the root. for(int x = 0; x < 10; ++x) { for(int z = 0; z < 10; ++z) { SceneNode* n = new SceneNode(); n->SetMesh(cube); n->SetModelScale(Vector3(10,10,10)); n->SetBoundingRadius(10.0f); n->SetTransform(Matrix4::Translation(Vector3(x*50.0f,0,-z*50.0f))); root->AddChild(n); } } glEnable(GL_DEPTH_TEST); init = true; }
/* Constructor, which sets everything to some 'sensible' defaults. */ ParticleEmitter::ParticleEmitter(void) { particleRate = 42.0f; particleLifetime = 500.0f; particleSize = 36.0f; particleVariance = 0.2f; nextParticleTime = 0.0f; particleSpeed = 0.2f; numLaunchParticles = 10; largestSize = 0; /* Each particle is a white dot, which has an alpha fade on it, so the edges fade to 0.0 alpha. */ texture = SOIL_load_OGL_texture("../../Textures/bird.png", SOIL_LOAD_AUTO,SOIL_CREATE_NEW_ID,SOIL_FLAG_COMPRESS_TO_DXT); /*texture = SOIL_load_OGL_texture(TEXTUREDIR"nyan.png", SOIL_LOAD_AUTO,SOIL_CREATE_NEW_ID,SOIL_FLAG_COMPRESS_TO_DXT);*/ }
void ScoreOrb::initialise() { collectableTextureId = SOIL_load_OGL_texture("blue-orb.png", SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_MIPMAPS | SOIL_FLAG_INVERT_Y); posX = (rand() % 10 - 5) * 10; posY = (rand() % 10 - 5) * 10; int minus = -size / 2; int positive = size / 2; objectPolyN.vert[0].x = objectPoly.vert[0].x = minus; objectPolyN.vert[0].y = objectPoly.vert[0].y = minus; objectPolyN.vert[1].x = objectPoly.vert[1].x = positive; objectPolyN.vert[1].y = objectPoly.vert[1].y = minus; objectPolyN.vert[2].x = objectPoly.vert[2].x = positive; objectPolyN.vert[2].y = objectPoly.vert[2].y = positive; objectPolyN.vert[3].x = objectPoly.vert[3].x = minus; objectPolyN.vert[3].y = objectPoly.vert[3].y = positive; }
/** * @brief Загружает изображение из файла * * @param imagePath : путь к картинке * @return Если картинка загрузилась то true, иначе false */ bool Image::LoadFromFile(std::string imagePath) { // Загружаем картинку, чтобы узнать ее ширину и высоту SOIL_load_image(imagePath.c_str(), &width, &height, NULL, SOIL_LOAD_L); // Если изображение имеет формат PNG if (imagePath.find(".png")) // Тогда загружаем изображение с специфичными флагами image = SOIL_load_OGL_texture ( imagePath.c_str(), SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_MIPMAPS | SOIL_FLAG_INVERT_Y | SOIL_FLAG_NTSC_SAFE_RGB | SOIL_FLAG_COMPRESS_TO_DXT | SOIL_FLAG_MULTIPLY_ALPHA ); // Если изображение не получилось загрузить, возвращаем false if (image == 0) isValid = false; else // ?наче возвращаем true isValid = true; return isValid; }
GLuint LoadTexture(const char* pFilename) { printf("--- MIDISYS ENGINE: LoadTexture(\"%s\")", pFilename); GLuint tex_2d = SOIL_load_OGL_texture ( pFilename, SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_MIPMAPS | SOIL_FLAG_INVERT_Y | SOIL_FLAG_NTSC_SAFE_RGB | SOIL_FLAG_COMPRESS_TO_DXT ); if(0 == tex_2d) { printf(" error loading texture from file \"%s\"\n", SOIL_last_result()); exit(1); } printf(" success\n"); return tex_2d; }
void AssimpModel::loadTextures(const std::string& model) { for (unsigned int material = 0 ; material < m_scene->mNumMaterials; material++) { aiString path; unsigned int index = 0; while(AI_SUCCESS == m_scene->mMaterials[material]->GetTexture(aiTextureType_DIFFUSE, index, &path)) { GLuint& texture = m_textures[path.data]; boost::filesystem::path modelPath(model); std::string basepath = modelPath.remove_leaf().string(); std::string fileloc = basepath + "/" + path.C_Str(); texture = SOIL_load_OGL_texture ( fileloc.c_str(), SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_MIPMAPS | SOIL_FLAG_INVERT_Y | SOIL_FLAG_NTSC_SAFE_RGB | SOIL_FLAG_COMPRESS_TO_DXT ); index++; } } }
void Model::setTexture(const char* path) { _texture = SOIL_load_OGL_texture( path, SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_MIPMAPS | SOIL_FLAG_INVERT_Y | SOIL_FLAG_NTSC_SAFE_RGB | SOIL_FLAG_COMPRESS_TO_DXT ); if (0 == _texture) { std::cout << "Error: " << SOIL_last_result(); } glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, _texture); 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_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); // Set environment mode glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); glBindTexture(GL_TEXTURE_2D, 0x0); }
Renderer::Renderer(Window & parent) : OGLRenderer(parent) { heightMap = new HeightMap(TEXTUREDIR"terrain.raw"); CubeRobot::CreateCube(); camera = new Camera(); camera->SetPosition(Vector3(0.0f, 750.0f, 750.0f)); sceneShader=new Shader(SHADERDIR"SceneVertex.glsl", SHADERDIR"SceneFragment.glsl"); currentShader = new Shader(SHADERDIR"LandVertex.glsl", SHADERDIR"LandFragment.glsl"); if (!currentShader->LinkProgram()) { return; } if (!sceneShader->LinkProgram()) { return; } heightMap->SetTexture(SOIL_load_OGL_texture(TEXTUREDIR"BarrenReds.jpg", SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_MIPMAPS)); projMatrix = Matrix4::Perspective(1.0f, 10000.0f, (float)width / (float)height, 45.0f); if (!heightMap->GetTexture()) { return; } SetTextureRepeating(heightMap->GetTexture(), true); projMatrix = Matrix4::Perspective(1.0f, 10000.0f, (float)width / (float)height, 45.0f); root = new SceneNode(); /*for (int i = 0; i < 9; i++) { for (int j = 0; j < 9; j++) { for (int k = 0; k < 9; k++) { CubeRobot * zaku = new CubeRobot(); zaku->SetTransform(Matrix4::Translation(Vector3((i - 4) * 100, (j - 4) * 100, (k - 4) * 100)) * Matrix4::Scale(Vector3(2, 2, 2)));*/ root->AddChild(/*zaku*/new CubeRobot()); /* } } } */ root->SetTransform(root->GetTransform() * Matrix4::Translation(Vector3(15.0f, 200.0f, 0.0f))); glEnable(GL_DEPTH_TEST); glEnable(GL_CULL_FACE);
void MyGLWindow::initializeGL() { init_resources(); // load texture if specified if (_textureName != "") { _texture0 = SOIL_load_OGL_texture ( _textureName.c_str(), SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_MIPMAPS ); /* check for an error during the load process */ if( 0 == _texture0 ) { printf( "SOIL loading error: '%s' '%s'\n", SOIL_last_result(), _textureName.c_str() ); } else { glEnable(GL_TEXTURE_2D); } } // Enable alpha blend // glEnable(GL_BLEND); // glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // set the clear colour glClearColor(1,1,1,1); // Start timer gettimeofday(&_startTime, NULL); }
TextureBatch::TextureBatch(int i_count,...){ va_list vaItems; va_start(vaItems,i_count); unsigned int *images = new unsigned int[i_count]; tbiSubImages = new TexBatchInfo[i_count]; tInfo.width = tInfo.height = 0; //Load and setup texture information for (int i = 0; i < i_count; i++){ char* str = va_arg(vaItems,char*); Logger::Log("Loading %s \n",str); images[i] = SOIL_load_OGL_texture(str,SOIL_LOAD_AUTO,SOIL_CREATE_NEW_ID,0); //Set out texture's size values glGetTexLevelParameteriv(GL_TEXTURE_2D,0,GL_TEXTURE_WIDTH,&tbiSubImages->Info.width); glGetTexLevelParameteriv(GL_TEXTURE_2D,0,GL_TEXTURE_HEIGHT,&tbiSubImages->Info.height); tbiSubImages->Pos = glm::vec2(tInfo.width,tInfo.height); //Set our global texture size Logger::Log("subimage size %i %i \n",tbiSubImages->Info.width,tbiSubImages->Info.height); tInfo.width += tbiSubImages->Info.width; } //Finally setup our UV's for (int i = 0; i < i_count; i++){ } Logger::Log("Batch Width %i \n",tInfo.width); va_end(vaItems); delete[] images; }
/*! * * @param filename * @return */ void MaterialManager::LoadTexture(std::string filename) { glActiveTexture(GL_TEXTURE0); glGenTextures(1, &(m_textures[m_textureCounter]->m_handle)); glBindTexture(GL_TEXTURE_2D, m_textures[m_textureCounter]->m_handle); //! Loading textures with SOIL m_textures[m_textureCounter]->m_handle = SOIL_load_OGL_texture( filename.c_str(), SOIL_LOAD_AUTO, m_textures[m_textureCounter]->m_handle, SOIL_FLAG_DDS_LOAD_DIRECT | SOIL_FLAG_INVERT_Y | SOIL_FLAG_TEXTURE_REPEATS | SOIL_FLAG_COMPRESS_TO_DXT); //! Loading textures with GLFW /* glfwLoadTexture2D(&filename[0], GLFW_BUILD_MIPMAPS_BIT); //! Set texture's clamping glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); //! Set texture's filtering glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_LINEAR); */ }
Renderer :: Renderer ( Window & parent ) : OGLRenderer ( parent ) { heightMap = new HeightMap ("../../Textures/terrain.raw"); camera = new Camera (); currentShader = new Shader ("../../Shaders/TexturedVertex.glsl","../../Shaders/TexturedFragment.glsl"); if (! currentShader -> LinkProgram ()) { return ; } heightMap -> SetTexture ( SOIL_load_OGL_texture ("../../Textures/Barren Reds.JPG", SOIL_LOAD_AUTO , SOIL_CREATE_NEW_ID , SOIL_FLAG_MIPMAPS )); if (! heightMap -> GetTexture ()) { return ; } SetTextureRepeating ( heightMap -> GetTexture () , true ); projMatrix = Matrix4 :: Perspective (1.0f ,10000.0f , ( float ) width /( float ) height ,45.0f ); glEnable ( GL_DEPTH_TEST ); glEnable ( GL_CULL_FACE ); glCullFace ( GL_BACK ); init = true ;
Stem::Stem(PhysicsNode* myN) { srand((unsigned int)time(NULL)); stemSize = rand() % 50 + 50; stemSize = 100; mesh = ExtendingMesh::GenerateExtendingCube(stemSize); mesh->SetTexture(SOIL_load_OGL_texture(TEXTUREDIR"stem.jpg", SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_MIPMAPS)); SetModelScale(Vector3(5, 10, 5)); numBranches = 0; maxBranches = 8; maxLeafs = 1; numLeafs = 0; maxScale = Vector3(10, 10, 10); branchAdd = (((stemSize - (stemSize/maxBranches) )* 24) / maxBranches); myNode = myN; }
GLvoid LoadTexture( char * filename ) { if ((texname=SOIL_load_OGL_texture(filename,SOIL_LOAD_AUTO, texname,SOIL_FLAG_MIPMAPS | SOIL_FLAG_INVERT_Y | SOIL_FLAG_NTSC_SAFE_RGB | SOIL_FLAG_COMPRESS_TO_DXT))==0) { MessageBox(NULL,TEXT("Load Texture Error"),TEXT("Error"),MB_OK); } texTop = SOIL_load_OGL_texture("ceiling.bmp"/*"2TOP.bmp"*/,SOIL_LOAD_AUTO, texTop,SOIL_FLAG_DDS_LOAD_DIRECT); texBack = SOIL_load_OGL_texture("wall.bmp"/*"2RBACK.bmp"*/,SOIL_LOAD_AUTO, texBack,SOIL_FLAG_DDS_LOAD_DIRECT); texLeft = SOIL_load_OGL_texture("wall.bmp"/*"2LEFT.bmp"*/,SOIL_LOAD_AUTO, texLeft,SOIL_FLAG_DDS_LOAD_DIRECT); texRight = SOIL_load_OGL_texture("wall.bmp"/*"2RIGHT.bmp"*/,SOIL_LOAD_AUTO, texRight,SOIL_FLAG_DDS_LOAD_DIRECT); texFront = SOIL_load_OGL_texture("wall.bmp"/*"2FRONT.bmp"*/,SOIL_LOAD_AUTO, texFront,SOIL_FLAG_DDS_LOAD_DIRECT); texcross = SOIL_load_OGL_texture("crosshair.bmp",SOIL_LOAD_AUTO, texcross,SOIL_FLAG_DDS_LOAD_DIRECT); }
/* don't try alpha=GL_FALSE: gluScaleImage implementations seem to be buggy */ GLuint glmLoadTexture(const char *filename, GLboolean alpha, GLboolean repeat, GLboolean filtering, GLboolean mipmaps, GLfloat *texcoordwidth, GLfloat *texcoordheight) { GLuint tex; int width, height,pixelsize; int type; int filter_min, filter_mag; GLubyte *data, *rdata; double xPow2, yPow2; int ixPow2, iyPow2; int xSize2, ySize2; GLint retval; if(glm_do_init) glmImgInit(); #ifdef HAVE_SOIL tex = SOIL_load_OGL_texture(filename, SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_POWER_OF_TWO ); glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &width); glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &height); //glTexEnvf(GL_TEXTURE_2D, GL_TEXTURE_ENV_MODE, GL_REPLACE); *texcoordwidth = width; *texcoordheight = height; return tex; #endif /* fallback solution (PPM only) */ data = glmReadPPM(filename, alpha, &width, &height, &type); if(data != NULL) { DBG_(__glmWarning("glmLoadTexture(): got PPM for %s",filename)); goto DONE; } #ifdef HAVE_DEVIL data = glmReadDevIL(filename, alpha, &width, &height, &type); if(data != NULL) { DBG_(__glmWarning("glmLoadTexture(): got DevIL for %s",filename)); goto DONE; } #endif #ifdef HAVE_LIBJPEG data = glmReadJPG(filename, alpha, &width, &height, &type); if(data != NULL) { DBG_(__glmWarning("glmLoadTexture(): got JPG for %s",filename)); goto DONE; } #endif #ifdef HAVE_LIBPNG data = glmReadPNG(filename, alpha, &width, &height, &type); if(data != NULL) { DBG_(__glmWarning("glmLoadTexture(): got PNG for %s",filename)); goto DONE; } #endif #ifdef HAVE_LIBSDL_IMAGE data = glmReadSDL(filename, alpha, &width, &height, &type); if(data != NULL) { DBG_(__glmWarning("glmLoadTexture(): got SDL for %s",filename)); goto DONE; } #endif #ifdef HAVE_LIBSIMAGE data = glmReadSimage(filename, alpha, &width, &height, &type); if(data != NULL) { DBG_(__glmWarning("glmLoadTexture(): got simage for %s",filename)); goto DONE; } #endif __glmWarning("glmLoadTexture() failed: Unable to load texture from %s!", filename); DBG_(__glmWarning("glmLoadTexture() failed: tried PPM")); #ifdef HAVE_LIBJPEG DBG_(__glmWarning("glmLoadTexture() failed: tried JPEG")); #endif #ifdef HAVE_LIBSDL_IMAGE DBG_(__glmWarning("glmLoadTexture() failed: tried SDL_image")); #endif return 0; DONE: /*#define FORCE_ALPHA*/ #ifdef FORCE_ALPHA if(alpha && type == GL_RGB) { /* if we really want RGBA */ const unsigned int size = width * height; unsigned char *rgbaimage; unsigned char *ptri, *ptro; int i; rgbaimage = (unsigned char*)malloc(sizeof(unsigned char)* size * 4); ptri = data; ptro = rgbaimage; for(i=0; i<size; i++) { *(ptro++) = *(ptri++); *(ptro++) = *(ptri++); *(ptro++) = *(ptri++); *(ptro++) = 255; } free(data); data = rgbaimage; type = GL_RGBA; } #endif /* FORCE_ALPHA */ switch(type) { case GL_LUMINANCE: pixelsize = 1; break; case GL_RGB: case GL_BGR: pixelsize = 3; break; case GL_RGBA: case GL_BGRA: pixelsize = 4; break; default: __glmFatalError( "glmLoadTexture(): unknown type 0x%x", type); pixelsize = 0; break; } if((pixelsize*width) % 4 == 0) glPixelStorei(GL_UNPACK_ALIGNMENT, 4); else glPixelStorei(GL_UNPACK_ALIGNMENT, 1); xSize2 = width; if (xSize2 > gl_max_texture_size) xSize2 = gl_max_texture_size; ySize2 = height; if (ySize2 > gl_max_texture_size) ySize2 = gl_max_texture_size; if (_glmTextureTarget == GL_TEXTURE_2D) { //if(1) { /* scale image to power of 2 in height and width */ xPow2 = log((double)xSize2) / log(2.0); yPow2 = log((double)ySize2) / log(2.0); ixPow2 = (int)xPow2; iyPow2 = (int)yPow2; if (xPow2 != (double)ixPow2) ixPow2++; if (yPow2 != (double)iyPow2) iyPow2++; xSize2 = 1 << ixPow2; ySize2 = 1 << iyPow2; } DBG_(__glmWarning("gl_max_texture_size=%d / width=%d / xSize2=%d / height=%d / ySize2 = %d", gl_max_texture_size, width, xSize2, height, ySize2)); if((width != xSize2) || (height != ySize2)) { /* TODO: use glTexSubImage2D instead */ DBG_(__glmWarning("scaling texture")); rdata = (GLubyte*)malloc(sizeof(GLubyte) * xSize2 * ySize2 * pixelsize); if (!rdata) return 0; retval = gluScaleImage(type, width, height, GL_UNSIGNED_BYTE, data, xSize2, ySize2, GL_UNSIGNED_BYTE, rdata); free(data); data = rdata; } glGenTextures(1, &tex); /* Generate texture ID */ glBindTexture(_glmTextureTarget, tex); DBG_(__glmWarning("building texture %d",tex)); if(mipmaps && _glmTextureTarget != GL_TEXTURE_2D) { DBG_(__glmWarning("mipmaps only work with GL_TEXTURE_2D")); mipmaps = 0; } if(filtering) { filter_min = (mipmaps) ? GL_LINEAR_MIPMAP_LINEAR : GL_LINEAR; filter_mag = GL_LINEAR; } else { filter_min = (mipmaps) ? GL_NEAREST_MIPMAP_NEAREST : GL_NEAREST; filter_mag = GL_NEAREST; } glTexParameteri(_glmTextureTarget, GL_TEXTURE_MIN_FILTER, filter_min); glTexParameteri(_glmTextureTarget, GL_TEXTURE_MAG_FILTER, filter_mag); glTexParameteri(_glmTextureTarget, GL_TEXTURE_WRAP_S, (repeat) ? GL_REPEAT : GL_CLAMP); glTexParameteri(_glmTextureTarget, GL_TEXTURE_WRAP_T, (repeat) ? GL_REPEAT : GL_CLAMP); if(mipmaps && _glmTextureTarget == GL_TEXTURE_2D) { /* only works for GL_TEXTURE_2D */ #ifdef GL_GENERATE_MIPMAP_SGIS if(gl_sgis_generate_mipmap) { DBG_(__glmWarning("sgis mipmapping")); glTexParameteri(_glmTextureTarget, GL_GENERATE_MIPMAP_SGIS, GL_TRUE ); glTexImage2D(_glmTextureTarget, 0, type, xSize2, ySize2, 0, type, GL_UNSIGNED_BYTE, data); } else #endif { DBG_(__glmWarning("glu mipmapping")); gluBuild2DMipmaps(_glmTextureTarget, type, xSize2, ySize2, type, GL_UNSIGNED_BYTE, data); } } else { glTexImage2D(_glmTextureTarget, 0, type, xSize2, ySize2, 0, type, GL_UNSIGNED_BYTE, data); } /* Clean up and return the texture ID */ free(data); if (_glmTextureTarget == GL_TEXTURE_2D) { *texcoordwidth = 1.; /* texcoords are in [0,1] */ *texcoordheight = 1.; } else { *texcoordwidth = xSize2; /* size of texture coords */ *texcoordheight = ySize2; } return tex; }
void NuevoNivel() { int prev_nivel = tiempo_nivel; tiempo_nivel += 20000; for (int n = 0;n < enemigos.size();n++) { enemigos[n].activo = true; enemigos[n].x = limites.right+1; enemigos[n].hp = 5; enemigos[n].material[0] = 1.0f; enemigos[n].material[1] = 1.0f; enemigos[n].material[2] = 1.0f; enemigos[n].material[3] = 1.0f; enemigos[n].disparos.clear(); enemigos[n].ultimo_disparo = 0; enemigos[n].tiempo_disparo -= 20; } for (int n = 0;n < asteroides.size();n++) { asteroides[n].activo = true; asteroides[n].x = limites.right + 0.5; asteroides[n].hp = 5; asteroides[n].material[0] = 1.0f; asteroides[n].material[1] = 1.0f; asteroides[n].material[2] = 1.0f; asteroides[n].material[3] = 1.0f; } for (int n = 0;n < powerups.size();n++) { powerups[n].activo = true; powerups[n].x = limites.right + 0.5; } tex1 = SOIL_load_OGL_texture( "tex1.png", SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_POWER_OF_TWO ); tex2 = SOIL_load_OGL_texture( "tex2.png", SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_POWER_OF_TWO ); tex3 = SOIL_load_OGL_texture( "tex3.png", SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_POWER_OF_TWO | SOIL_FLAG_INVERT_Y ); tex4 = SOIL_load_OGL_texture( "pantalla2.png", SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_POWER_OF_TWO ); tex5 = SOIL_load_OGL_texture( "pantalla1.png", SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_POWER_OF_TWO ); tex6 = SOIL_load_OGL_texture( "pantalla3.png", SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_POWER_OF_TWO ); srand(time(NULL)); powerups.push_back(Powerup(limites.right +3, random(limites.bottom, limites.top), 0, 70, prev_nivel + randomTime(15000))); powerups.push_back(Powerup(limites.right +3, random(limites.bottom, limites.top), 50, 0, prev_nivel + randomTime(15000))); asteroides.push_back(Asteroide(limites.right +3, random(limites.bottom, limites.top), prev_nivel + randomTime(15000), asteroideModel, 0.3)); asteroides.push_back(Asteroide(limites.right +3, random(limites.bottom, limites.top), prev_nivel + randomTime(15000), asteroideModel, 0.4)); asteroides.push_back(Asteroide(limites.right +3, random(limites.bottom, limites.top), prev_nivel + randomTime(15000), asteroideModel, 0.2)); asteroides.push_back(Asteroide(limites.right +3, random(limites.bottom, limites.top), prev_nivel + randomTime(15000), asteroideModel, 0.2)); asteroides.push_back(Asteroide(limites.right +3, random(limites.bottom, limites.top), prev_nivel + randomTime(15000), asteroideModel, 0.3)); asteroides.push_back(Asteroide(limites.right +3, random(limites.bottom, limites.top), prev_nivel + randomTime(15000), asteroideModel, 0.5)); asteroides.push_back(Asteroide(limites.right +3, random(limites.bottom, limites.top), prev_nivel + randomTime(15000), asteroideModel, 0.3)); asteroides.push_back(Asteroide(limites.right +3, random(limites.bottom, limites.top), prev_nivel + randomTime(15000), asteroideModel, 0.4)); enemigos.push_back(Enemigo(limites.right +3, random(limites.bottom, limites.top), prev_nivel + randomTime(15000), enemigoModel)); enemigos.push_back(Enemigo(limites.right +3, random(limites.bottom, limites.top), prev_nivel + randomTime(15000), enemigoModel)); enemigos.push_back(Enemigo(limites.right +3, random(limites.bottom, limites.top), prev_nivel + randomTime(15000), enemigoModel)); enemigos.push_back(Enemigo(limites.right +3, random(limites.bottom, limites.top), prev_nivel + randomTime(15000), enemigoModel)); player.hp = 100; player.municiones = 100; ammo_length = limites.right * 2; hp_length = limites.right * 2; time_begin = glutGet(GLUT_ELAPSED_TIME); time_fin = time_begin + tiempo_nivel; player.x = limites.left / 2; player.y = 0; player.z = 1; }
void Init() { glClearColor(1.0,1.0,1.0,1.0); glEnable(GL_ALPHA); glEnable(GL_DEPTH_TEST); glEnable(GL_TEXTURE_2D); glEnable(GL_LIGHT0); glEnable(GL_LIGHT1); glEnable(GL_LIGHT2); glEnable(GL_LIGHTING); GLfloat lDiff[] = { 1.0f,1.0f,1.0f,1.0f }; GLfloat lSpec[] = { 0.0f,0.0f,1.0f,1.0f }; GLfloat lpos[] = { 0.0,2.5,0.0,1 }; GLfloat lDiff1[] = { 1.0f,1.0f,1.0f,1.0f }; GLfloat lSpec1[] = { 1.0f,0.0f,0.0f,1.0f }; GLfloat lpos1[] = {0.0f,-2.5,1.0,1 }; GLfloat lDiff2[] = { 1.0f,1.0f,1.0f,1.0f }; GLfloat lSpec2[] = { 1.0f,0.0f,1.0f,1.0f }; GLfloat lpos2[] = { 1.5f,0.0,1.0,1 }; glLightfv(GL_LIGHT0, GL_DIFFUSE, lDiff); glLightfv(GL_LIGHT0, GL_SPECULAR, lSpec); glLightfv(GL_LIGHT0, GL_POSITION, lpos); glLightfv(GL_LIGHT1, GL_DIFFUSE, lDiff1); glLightfv(GL_LIGHT1, GL_SPECULAR, lSpec1); glLightfv(GL_LIGHT1, GL_POSITION, lpos1); glLightfv(GL_LIGHT2, GL_DIFFUSE, lDiff2); glLightfv(GL_LIGHT2, GL_SPECULAR, lSpec2); glLightfv(GL_LIGHT2, GL_POSITION, lpos2); tex1 = SOIL_load_OGL_texture( "tex1.png", SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_POWER_OF_TWO ); tex2 = SOIL_load_OGL_texture( "tex2.png", SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_POWER_OF_TWO ); tex3 = SOIL_load_OGL_texture( "tex3.png", SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_POWER_OF_TWO | SOIL_FLAG_INVERT_Y ); tex4 = SOIL_load_OGL_texture( "pantalla2.png", SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_POWER_OF_TWO ); tex5 = SOIL_load_OGL_texture( "pantalla1.png", SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_POWER_OF_TWO ); tex6 = SOIL_load_OGL_texture( "pantalla3.png", SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_POWER_OF_TWO ); player.model = glmReadOBJ("ship.obj"); asteroideModel = glmReadOBJ("Asteroid.obj"); enemigoModel = glmReadOBJ("rtm_metroid_v2.obj"); time_begin = glutGet(GLUT_ELAPSED_TIME); srand(time(NULL)); powerups.push_back(Powerup(limites.right +3, random(limites.bottom,limites.top), 0, 70, time_begin + randomTime(tiempo_nivel - 5000))); powerups.push_back(Powerup(limites.right +3, random(limites.bottom, limites.top), 50, 0, time_begin + randomTime(tiempo_nivel - 5000))); asteroides.push_back(Asteroide(limites.right +3, random(limites.bottom, limites.top), time_begin + randomTime(tiempo_nivel - 5000),asteroideModel,0.3)); asteroides.push_back(Asteroide(limites.right +3, random(limites.bottom, limites.top), time_begin + randomTime(tiempo_nivel - 5000), asteroideModel,0.4)); asteroides.push_back(Asteroide(limites.right +3, random(limites.bottom, limites.top), time_begin + randomTime(tiempo_nivel - 5000), asteroideModel, 0.3)); asteroides.push_back(Asteroide(limites.right +3, random(limites.bottom, limites.top), time_begin + randomTime(tiempo_nivel - 5000), asteroideModel, 0.5)); asteroides.push_back(Asteroide(limites.right +3, random(limites.bottom, limites.top), time_begin + randomTime(tiempo_nivel - 5000), asteroideModel, 0.3)); asteroides.push_back(Asteroide(limites.right +3, random(limites.bottom, limites.top), time_begin + randomTime(tiempo_nivel - 5000), asteroideModel, 0.4)); enemigos.push_back(Enemigo(limites.right +3, random(limites.bottom, limites.top), time_begin + randomTime(tiempo_nivel-5000), enemigoModel)); enemigos.push_back(Enemigo(limites.right +3, random(limites.bottom, limites.top), time_begin + randomTime(tiempo_nivel - 5000), enemigoModel)); enemigos.push_back(Enemigo(limites.right +3, random(limites.bottom, limites.top), time_begin + randomTime(tiempo_nivel - 5000), enemigoModel)); enemigos.push_back(Enemigo(limites.right +3, random(limites.bottom, limites.top), time_begin + randomTime(tiempo_nivel - 5000), enemigoModel)); ammo_length = limites.right * 2; hp_length = limites.right * 2; time_fin = time_begin + tiempo_nivel; player.x = limites.left/2; player.y = 0; player.z = 1; glutReportErrors(); }
Quad::Quad(char* texturePath) { m_TextureID = SOIL_load_OGL_texture(texturePath, 0, 0 /* 0 will specify to let SOIL generate a texture ID for us */, /*SOIL_FLAG_INVERT_Y | */SOIL_FLAG_MIPMAPS); glBindTexture(GL_TEXTURE_2D, m_TextureID); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); //create a shader m_Shader = new Shader("Content/Shaders/vs.glsl", "Content/Shaders/fs.glsl"); m_Shader->setTexture(m_TextureID); //make a quad VertexDefinition* vertices = new VertexDefinition[4]; GLushort* indices = new GLushort[6]; vertices[0].position[0] = -1; vertices[0].position[1] = -1; vertices[0].position[2] = 0; vertices[0].color[0] = 1; vertices[0].color[1] = 1; vertices[0].color[2] = 1; vertices[0].color[3] = 1; vertices[0].uv[0] = 0; vertices[0].uv[1] = 1; vertices[1].position[0] = 1; vertices[1].position[1] = -1; vertices[1].position[2] = 0; vertices[1].color[0] = 1; vertices[1].color[1] = 1; vertices[1].color[2] = 1; vertices[1].color[3] = 1; vertices[1].uv[0] = 1; vertices[1].uv[1] = 1; vertices[2].position[0] = -1; vertices[2].position[1] = 1; vertices[2].position[2] = 0; vertices[2].color[0] = 1; vertices[2].color[1] = 1; vertices[2].color[2] = 1; vertices[2].color[3] = 1; vertices[2].uv[0] = 0; vertices[2].uv[1] = 0; vertices[3].position[0] = 1; vertices[3].position[1] = 1; vertices[3].position[2] = 0; vertices[3].color[0] = 1; vertices[3].color[1] = 1; vertices[3].color[2] = 1; vertices[3].color[3] = 1; vertices[3].uv[0] = 1; vertices[3].uv[1] = 0; indices[0] = 0; indices[1] = 1; indices[2] = 2; indices[3] = 3; indices[4] = 2; indices[5] = 1; m_Quad = new RenderableElements(); m_Quad->setVertexArray(vertices, indices, 6); m_Quad->setShader(m_Shader); m_Quad->setTextureID(m_TextureID); Renderer::getInstance()->addRenderable(m_Quad); Matrix world; world.SetIdentity(); m_Rotation.x = 90; world.Rotate(m_Rotation.x, 1, 0, 0); world.Scale(300, 200, 1); world.SetPosition(0, -20, 0); m_Quad->setWorld(world); }
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); }
GLuint newImage(char *fn) { GLuint ret = SOIL_load_OGL_texture(fn, SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_MIPMAPS|SOIL_FLAG_POWER_OF_TWO); return ret; }
int main(int argc, char *argv[]) { const unsigned largura = 600; const unsigned altura = 600; SDL_Init(SDL_INIT_EVERYTHING); SDL_Surface *tela = SDL_SetVideoMode(largura, altura, 32, SDL_OPENGL); cml::matrix44f_c matProj, matCamera, matCubo; float anguloCubo = 0.0f; glEnable(GL_DEPTH_TEST); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); float posLuz[4] = {+1,+1,+1,0}; float corLuz[4] = {1,1,1,1}; glLightfv(GL_LIGHT0, GL_POSITION, posLuz); glLightfv(GL_LIGHT0, GL_DIFFUSE, corLuz); glEnable(GL_TEXTURE_2D); unsigned texId = SOIL_load_OGL_texture("../dados/teste.png", SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_MIPMAPS); //Pra carregar o arquivo PLY, só isso mesmo Modelo *suzanne = carregaPly("../dados/suzanne.ply"); bool rodando = true; while (rodando) { SDL_Event e; while (SDL_PollEvent(&e)) { if (e.type == SDL_KEYDOWN) if (e.key.keysym.sym == SDLK_ESCAPE) rodando = false; if (e.type == SDL_QUIT) rodando = false; } glClearColor(1,1,1,1); glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); cml::matrix_perspective_yfov_RH(matProj, cml::rad(60.0f), (float)largura/altura, 1.0f, 100.0f, cml::z_clip_neg_one); cml::matrix_look_at_RH(matCamera, cml::vector3f(5,5,5), cml::vector3f(0,0,0), cml::vector3f(0,1,0)); cml::matrix_rotation_world_y(matCubo, anguloCubo); anguloCubo += 0.01f; glMatrixMode(GL_PROJECTION); glLoadMatrixf(matProj.data()); glMatrixMode(GL_MODELVIEW); glLoadMatrixf(matCamera.data()); glMultMatrixf(matCubo.data()); glBindTexture(GL_TEXTURE_2D, texId); //Pra desenhar, só chamar essa função suzanne->desenha(); SDL_GL_SwapBuffers(); SDL_Delay(10); } SDL_Quit(); return 0; }
bool MyScene::InitialiseGL() { m_Camera->SetPosition(Vector3(-6.25f, 2.0f, 10.0f)); PhysicsEngine::Instance()->SetGravity(Vector3(0.0f, 0.0f, 0.0f)); //No Gravity PhysicsEngine::Instance()->SetDampingFactor(1.0f); //No Damping m_TargetTexture = SOIL_load_OGL_texture(TEXTUREDIR"target.tga", SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_MIPMAPS | SOIL_FLAG_NTSC_SAFE_RGB | SOIL_FLAG_COMPRESS_TO_DXT); glBindTexture(GL_TEXTURE_2D, m_TargetTexture); 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_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST); //No linear interpolation to get crisp checkerboard no matter the scalling glBindTexture(GL_TEXTURE_2D, 0); //Create Ground SimpleMeshObject* ground = new SimpleMeshObject("Ground"); ground->SetMesh(CommonMeshes::Cube(), false); ground->SetLocalTransform(Matrix4::Scale(Vector3(80.0f, 0.1f, 2.f))); ground->SetColour(Vector4(0.2f, 1.0f, 0.5f, 1.0f)); ground->SetBoundingRadius(80.0f * 80.f); ground->Physics()->SetPosition(Vector3(-6.25f, -0.2f, 0.0f)); this->AddGameObject(ground); //Create Target SimpleMeshObject* target = new SimpleMeshObject("Target"); target->SetMesh(CommonMeshes::Cube(), false); target->SetTexture(m_TargetTexture, false); target->SetLocalTransform(Matrix4::Scale(Vector3(0.1f, 2.0f, 2.f))); target->SetColour(Vector4(1.0f, 1.0f, 1.0f, 1.0f)); target->SetBoundingRadius(4.0f); target->Physics()->SetPosition(Vector3(0.1f, 2.0f, 0.0f)); this->AddGameObject(target); //Create a projectile m_Sphere = new SimpleMeshObject("Sphere"); m_Sphere->SetMesh(CommonMeshes::Sphere(), false); m_Sphere->SetLocalTransform(Matrix4::Scale(Vector3(0.5f, 0.5f, 0.5f))); m_Sphere->SetColour(Vector4(1.0f, 0.2f, 0.5f, 1.0f)); m_Sphere->SetBoundingRadius(1.0f); m_Sphere->Physics()->SetPosition(Vector3(-12.5f, 2.0f, 0.f)); m_Sphere->Physics()->SetInverseMass(1.f); m_Sphere->Physics()->SetLinearVelocity(Vector3(0.f, 2.5f, 0.0f)); m_Sphere->Physics()->SetForce(Vector3(1.f, -1.f, 0.0f)); this->AddGameObject(m_Sphere); return true; }
GLuint LegacyOpenGLRenderer::LoadTexture(char * Loc, int LoadType, int IdType, int Flags) { GLuint img; img = SOIL_load_OGL_texture(Loc, LoadType, IdType, Flags); return img; }
void DragonBreath::create(GLuint program) { glGenVertexArrays(1, &ID.VertexArray); glBindVertexArray(ID.VertexArray); ID.program = program; glUseProgram(ID.program); // The VBO containing the 4 vertices of the particles. // Thanks to instancing, they will be shared by all particles. static const GLfloat g_vertex_buffer_data[] = { -0.5f, -0.5f, 0.0f, 0.5f, -0.5f, 0.0f, -0.5f, 0.5f, 0.0f, 0.5f, 0.5f, 0.0f, }; g_particule_position_size_data = new GLfloat[MaxParticles * 4]; g_particule_color_data = new GLubyte[MaxParticles * 4]; for (int i = 0; i<MaxParticles; i++){ ParticlesContainer[i].life = -1.0f; ParticlesContainer[i].cameradistance = -1.0f; } glGenBuffers(1, &buffer.vertex); glBindBuffer(GL_ARRAY_BUFFER, buffer.vertex); glBufferData(GL_ARRAY_BUFFER, sizeof(g_vertex_buffer_data), g_vertex_buffer_data, GL_STATIC_DRAW); // The VBO containing the positions and sizes of the particles glGenBuffers(1, &buffer.position); glBindBuffer(GL_ARRAY_BUFFER, buffer.position); // Initialize with empty (NULL) buffer : it will be updated later, each frame. glBufferData(GL_ARRAY_BUFFER, MaxParticles * 4 * sizeof(GLfloat), NULL, GL_STREAM_DRAW); // The VBO containing the colors of the particles glGenBuffers(1, &buffer.colour); glBindBuffer(GL_ARRAY_BUFFER, buffer.colour); // Initialize with empty (NULL) buffer : it will be updated later, each frame. glBufferData(GL_ARRAY_BUFFER, MaxParticles * 4 * sizeof(GLubyte), NULL, GL_STREAM_DRAW); glBindBuffer(GL_ARRAY_BUFFER, 0); // Vertex shader GLuint CameraRight_worldspace_ID = glGetUniformLocation(ID.program, "CameraRight_worldspace"); GLuint CameraUp_worldspace_ID = glGetUniformLocation(ID.program, "CameraUp_worldspace"); GLuint ViewProjMatrixID = glGetUniformLocation(ID.program, "VP"); /* load an image file directly as a new OpenGL texture */ Texture = SOIL_load_OGL_texture("images/explosiontex2.PNG", SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_MIPMAPS | SOIL_FLAG_INVERT_Y | SOIL_FLAG_NTSC_SAFE_RGB | SOIL_FLAG_COMPRESS_TO_DXT); /* check for an error during the load process */ if (Texture == 0) { printf("TexID SOIL loading error: '%s'\n", SOIL_last_result()); } // Enable depth test glEnable(GL_DEPTH_TEST); // Accept fragment if it closer to the camera than the former one glDepthFunc(GL_LESS); /* Define the uniform variables */ defineUniforms(); lastTime = glfwGetTime(); }
MyGame::MyGame() { //Init variables ammo = 0; force = 0; waveno=0; cube = new OBJMesh(MESHDIR"cube.obj"); cube->SetTexture(SOIL_load_OGL_texture( TEXTUREDIR"Barren Reds.jpg", SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_MIPMAPS)); if(!cube->GetTexture()) { cout << "barren reds is playing up" << endl; } quad = Mesh::GenerateQuad(); enemy = new OBJMesh(MESHDIR"ico2.obj"); enemy ->SetTexture(SOIL_load_OGL_texture( TEXTUREDIR"leo.png", SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_MIPMAPS)); if(!enemy->GetTexture()) { cout << "leopard skins f****d" << endl; } sphere = new OBJMesh(MESHDIR"ico2.obj"); sphere->SetTexture(SOIL_load_OGL_texture( TEXTUREDIR"swirl.tga", SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_MIPMAPS)); if(!sphere->GetTexture()) { cout << "swirl is BUM" << endl; } player = new OBJMesh(MESHDIR"ico2.obj"); player->SetTexture(SOIL_load_OGL_texture( TEXTUREDIR"cliff.jpg", SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_MIPMAPS)); if(!player->GetTexture()) { cout << "cliff is f****d" << endl; } CubeMap = SOIL_load_OGL_cubemap( TEXTUREDIR"interstellar_ft.tga", TEXTUREDIR"interstellar_bk.tga", TEXTUREDIR"interstellar_up.tga", TEXTUREDIR"interstellar_dn.tga", TEXTUREDIR"interstellar_rt.tga", TEXTUREDIR"interstellar_lf.tga", SOIL_LOAD_RGB, SOIL_CREATE_NEW_ID,0); enemy->SetCubeMap(CubeMap); if(!CubeMap) cout << "cube maps f*****g broken"; bumpShader = new Shader(SHADERDIR"bumpVertex.glsl",SHADERDIR"bumpFragment.glsl"); if(!bumpShader->LinkProgram()) { return; } enemyShader = new Shader(SHADERDIR"perPixelVertex.glsl",SHADERDIR"enemyFragment.glsl"); if(!enemyShader->LinkProgram()) { return; } heightmap = new HeightMap(TEXTUREDIR"stage1.raw"); heightmap->SetTexture(SOIL_load_OGL_texture( TEXTUREDIR"grass.jpg", SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_MIPMAPS)); heightmap->SetBumpMap(SOIL_load_OGL_texture( TEXTUREDIR"grassbump.jpg", SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_MIPMAPS)); SetTextureRepeating(heightmap->GetBumpMap(),true); if(!heightmap->GetTexture()){ cout << "height maps f*****g broken" << endl; } if(!heightmap->GetBumpMap()) { cout << "height map bump map f*****g broken" << endl; } for(int i = 0; i < NO_PROJECTILES; ++i) { projectiles[i] = BuildSphereEntity(25.0f); projectiles[i]->GetPhysicsNode().SetPosition(Vector3((51.0f* i) + 100.0f,500.0f,30.0f * i)); projectiles[i]->GetPhysicsNode().sleep = true; } for(int i = 0; i < NO_LASERS; ++i) { PhysicsSystem::GetPhysicsSystem().AddLaser(buildLaserEntity()); } PlanePos = Vector3(2048.0f,100.0f,2048.0f); // y = 450.0f playerEntity = buildPlayerEntity(); PhysicsSystem::GetPhysicsSystem().SetPlayer(playerEntity); allEntities.push_back(playerEntity); allEntities.push_back(BuildHeightmapEntity()); for(int i = 0; i < NO_PROJECTILES; ++i) { allEntities.push_back(projectiles[i]); } for(int i = 0; i < 10; ++i) { EnemyEntity* ee = buildEnemyEntity(Vector3(PlanePos.x + 150,PlanePos.y + 150, PlanePos.z + (i * 90) - 270)); ee->SetY(100.0f + (100.0f * i)); allEntities.push_back(ee); PhysicsSystem::GetPhysicsSystem().AddEnemy((ee)); } //gameCamera = new Camera(-2.0f,270.0f,Vector3(-360.0f,450.0f,3408.0f)); //gameCamera = new TPCamera(); gameCamera = new CameraMan(playerEntity->circleT); gameCamera->toggleLock(); Renderer::GetRenderer().SetCamera(gameCamera); ret = new Reticule(WIDTH,HEIGHT,FOV,ASPECT, gameCamera); //ret->c = gameCamera; Renderer::GetRenderer().SetReticule(ret); PhysicsSystem::GetPhysicsSystem().SetReticule(ret); //ret = new Reticule(); }
Scene::Scene() { // Creating the rendertarget and corresponding plane. m_RenderTarget = new Liqua::RenderTarget(SCRWIDTH, SCRHEIGHT, 1); m_Quad[0] = -1.0f; m_Quad[1] = -1.0f; m_Quad[2] = 0.0f; m_Quad[3] = 1.0f; m_Quad[4] = -1.0f; m_Quad[5] = 0.0f; m_Quad[6] = -1.0f; m_Quad[7] = 1.0f; m_Quad[8] = 0.0f; m_Quad[9] = -1.0f; m_Quad[10] = 1.0f; m_Quad[11] = 0.0f; m_Quad[12] = 1.0f; m_Quad[13] = -1.0f; m_Quad[14] = 0.0f; m_Quad[15] = 1.0f; m_Quad[16] = 1.0f; m_Quad[17] = 0.0f; glGenBuffers(1, &m_QuadBuffer); glBindBuffer(GL_ARRAY_BUFFER, m_QuadBuffer); glBufferData(GL_ARRAY_BUFFER, sizeof(m_Quad), m_Quad, GL_STATIC_DRAW); // create the depth of field shader m_DoFShader = new Liqua::Shader(); m_DoFShader->CreateShader(); m_DoFShader->AttachVertexShader("../Resources/Shaders/DoF.vert"); m_DoFShader->AttachFragmentShader("../Resources/Shaders/DoF.frag"); m_DoFShader->LinkShader(); // create the shader the shafts will use. m_ShaftShader = new Liqua::Shader(); m_ShaftShader->CreateShader(); m_ShaftShader->AttachVertexShader("../Resources/Shaders/Shaft.vert"); m_ShaftShader->AttachFragmentShader("../Resources/Shaders/Shaft.frag"); m_ShaftShader->LinkShader(); // Set the ambient color m_Ambient = glm::vec3(0.1f, 0.1f, 0.1f); // and the color of the water. m_WaterColor = glm::vec3(0.0f, 0.62f, 0.79f); // Light that acts as the sun m_SunLight = new Liqua::Light(); m_SunLight->SetPosition(glm::vec3(0.1, 900, 0.1)); // create the caustics effect m_CausticsEffect = new Liqua::Caustics(); // and load the textures for the caustic map for(int i = 0; i <= 60; i++) { char temp[256]; int picindex = i + 1; sprintf_s(temp, "../Resources/Textures/Caustics/CausticsRender_%03d.bmp", picindex); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); GLuint id = SOIL_load_OGL_texture(temp, SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_MIPMAPS); m_CausticsEffect->AddCausticTexture(id); } // Create the shafts with their initial values for(int i = 0; i < SHAFTS; i+=2) { float width = MathHelper::rFloatRange(25, 50); float depth = MathHelper::rFloatRange(25, 50); float angle = MathHelper::rFloatRange(0, 180); glm::vec3 pos = glm::vec3(MathHelper::rFloatRange(50, 400), -2, MathHelper::rFloatRange(-200, 200)); m_Shaft[i] = new Liqua::Shaft((depth * (pos.x / 100)), width); glm::quat Y = glm::angleAxis(angle, glm::vec3(0, 1, 0)); glm::quat X = glm::angleAxis(20.0f, glm::vec3(1, 0, 0)); glm::quat orientation = X * Y; m_Shaft[i]->Rotate(orientation); m_Shaft[i]->Translate(pos); m_Shaft[i]->SetShader(m_ShaftShader); m_Shaft[i]->SetStartPulse(MathHelper::rFloatRange(0.0f, 1.0f)); m_Shaft[i]->SetPulseFactor(MathHelper::rFloatRange(0.5f, 0.75f)); m_Shaft[i]->SetScrollSpeed(MathHelper::rFloatRange(-0.02f, 0.02f)); m_Shaft[i+1] = new Liqua::Shaft((depth * (pos.x / 100)), width); m_Shaft[i+1]->Rotate(orientation); m_Shaft[i+1]->Translate(pos); m_Shaft[i+1]->SetShader(m_ShaftShader); m_Shaft[i+1]->SetStartPulse(MathHelper::rFloatRange(0.0f, 1.0f)); m_Shaft[i+1]->SetPulseFactor(MathHelper::rFloatRange(0.5f, 0.75f)); m_Shaft[i+1]->SetScrollSpeed(MathHelper::rFloatRange(-0.02f, 0.02f)); } // Create the water surface m_WaterSurface = new Liqua::WaterSurface(); m_WaterSurface->SetHeight(-0.5); // and the sky m_Sky = new Liqua::Sky(); // Create the particle systems with 400 particles each. for(int i = 0; i < PARTICLESYSTEMS; i++) { m_ParticleSystem[i] = new Liqua::ParticleSystem(400); char tmp[256]; sprintf_s(tmp, "../Resources/Textures/Particles/debris_%i.png", i); int texid = SOIL_load_OGL_texture(tmp, SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_TEXTURE_REPEATS); m_ParticleSystem[i]->SetTexture(texid); } // Create a school of fish with 10 fish in it m_SchoolOfFish = new Liqua::School(10); m_AffectedMeshes.clear(); // Create the samples for the depth of field for(unsigned int i = 0; i < DOFSAMPLES; i++) { m_Samples[i] = glm::vec2(MathHelper::rFloatRange(-0.002f, 0.002f), MathHelper::rFloatRange(-0.002f, 0.002f)); } // Add the fishes from the previously created school to a vector that handles meshes that are affected by caustics. for(unsigned int i = 0; i < m_SchoolOfFish->GetFishArray().size(); i++) { AddAffectedMesh(m_SchoolOfFish->GetFishArray()[i]->GetMesh()); } // load the island and add it the same way as the fishes. m_Island = new Liqua::Mesh("../Resources/Models/Island/Island.omd"); AddAffectedMesh(m_Island); }
int LoadGLTextures() { /* load an image file directly as a new OpenGL texture */ texture[0] = SOIL_load_OGL_texture( "texture/serenity.jpg", SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_INVERT_Y ); texture[1] = SOIL_load_OGL_texture( "texture/circuit.jpg", SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_INVERT_Y ); // texture[2] = SOIL_load_OGL_texture( "texture/back.jpg", // SOIL_LOAD_AUTO, // SOIL_CREATE_NEW_ID, // SOIL_FLAG_INVERT_Y // ); // texture[3] = SOIL_load_OGL_texture( "texture/right.jpg", // SOIL_LOAD_AUTO, // SOIL_CREATE_NEW_ID, // SOIL_FLAG_INVERT_Y // ); // texture[4] = SOIL_load_OGL_texture( "texture/top.jpg", // SOIL_LOAD_AUTO, // SOIL_CREATE_NEW_ID, // SOIL_FLAG_INVERT_Y // ); // texture[5] = SOIL_load_OGL_texture( "texture/bottom.jpg", // SOIL_LOAD_AUTO, // SOIL_CREATE_NEW_ID, // SOIL_FLAG_INVERT_Y // ); if(!(texture[0] && texture[1] /*&& texture[2] && texture[3] && texture[4] && texture[5]*/)) { printf("Unable to load Texture"); return false; } // Typical Texture Generation Using Data From The Bitmap glBindTexture(GL_TEXTURE_2D, texture[0]); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); glBindTexture(GL_TEXTURE_2D, texture[1]); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); // glBindTexture(GL_TEXTURE_2D, texture[3]); // glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); // glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); // glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); // glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); // glBindTexture(GL_TEXTURE_2D, texture[4]); // glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); // glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); // glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); // glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); // glBindTexture(GL_TEXTURE_2D, texture[1]); // glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); // glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); // glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); // glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); // glBindTexture(GL_TEXTURE_2D, texture[5]); // glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); // glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); // glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); // glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); return true; // Return Success }
Graphics::Textures::Texture::Texture(const std::string &path) { mTexID = SOIL_load_OGL_texture(path.c_str(), SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, 0); LOG_DEBUG("Texture #" + m_TexID + " created: " + path) }