void ShaderGl::end(){ if(inited){ assertGl(); glDeleteObjectARB(handle); assertGl(); } }
void Renderer::renderGrid() { if(grid) { float i=0; assertGl(); glPushAttrib(GL_ENABLE_BIT); glDisable(GL_TEXTURE_2D); glDisable(GL_LIGHTING); glBegin(GL_LINES); glColor3f(1.0f, 1.0f, 1.0f); // gridcolor constant for(i=-10.0f; i<=10.0f; i+=1.0f) { glVertex3f(i, 0.0f, 10.0f); glVertex3f(i, 0.0f, -10.0f); } for(i=-10.0f; i<=10.0f; i+=1.0f) { glVertex3f(10.f, 0.0f, i); glVertex3f(-10.f, 0.0f, i); } glEnd(); glPopAttrib(); assertGl(); } }
bool ShaderGl::compile(string &messages){ assertGl(); messages= "Compiling shader: " + source.getPathInfo() + "\n"; //load source GLint length= source.getCode().size(); const GLcharARB *csource= source.getCode().c_str(); glShaderSourceARB(handle, 1, &csource, &length); //compile glCompileShaderARB(handle); //log GLint logLength= 0; glGetObjectParameterivARB(handle, GL_OBJECT_INFO_LOG_LENGTH_ARB, &logLength); char *buffer= new char[logLength+1]; glGetInfoLogARB(handle, logLength+1, NULL, buffer); messages+= buffer; delete [] buffer; //status GLint status= false; glGetObjectParameterivARB(handle, GL_OBJECT_COMPILE_STATUS_ARB, &status); assertGl(); return status!=0; }
void ShaderProgramGl::end(){ if(inited){ assertGl(); glDeleteObjectARB(handle); assertGl(); inited= false; } }
void ShaderProgramGl::init(){ if(!inited){ assertGl(); handle= glCreateProgramObjectARB(); assertGl(); inited= true; } }
void FragmentShaderGl::init(){ if(!inited){ assertGl(); handle= glCreateShaderObjectARB(GL_FRAGMENT_SHADER_ARB); assertGl(); inited= true; } }
void VertexShaderGl::init(){ if(!inited){ assertGl(); handle= glCreateShaderObjectARB(GL_VERTEX_SHADER_ARB); assertGl(); inited= true; } }
void BaseRenderer::initMapSurface(int clientW, int clientH) { assertGl(); glFrontFace(GL_CW); glEnable(GL_CULL_FACE); glPolygonMode(GL_FRONT, GL_FILL); glClearColor(0.5, 0.5, 0.5, 1.0); assertGl(); }
void Renderer::transform(float rotX, float rotY, float zoom) { assertGl(); glMatrixMode(GL_MODELVIEW); glRotatef(rotY, 1.0f, 0.0f, 0.0f); glRotatef(rotX, 0.0f, 1.0f, 0.0f); glScalef(zoom, zoom, zoom); Vec4f pos(-8.0f, 5.0f, 10.0f, 0.0f); glLightfv(GL_LIGHT0,GL_POSITION, pos.ptr()); assertGl(); }
void ModelRendererGl::renderNormalsOnly(Model *model) { //assertions assert(rendering); assertGl(); //render every mesh //if(model->getIsStaticModel() == true) { for(uint32 i=0; i<model->getMeshCount(); ++i) { renderMeshNormals(model->getMeshPtr(i)); } //} //assertions assertGl(); }
void ModelRendererGl::render(Model *model,int renderMode) { //assertions assert(rendering); assertGl(); //if(model->getIsStaticModel()) printf("In [%s::%s Line: %d] filename [%s] is static about to render...\n",__FILE__,__FUNCTION__,__LINE__,model->getFileName().c_str()); //render every mesh //if(model->getIsStaticModel() == true) { for(uint32 i = 0; i < model->getMeshCount(); ++i) { renderMesh(model->getMeshPtr(i),renderMode); } //} //assertions assertGl(); }
void TextFTGL::Render(const char* str, const int len) { //printf("Render TextFTGL\n"); /* FTGL renders the whole string when len == 0 but we don't want any text rendered then. */ if(len != 0) { //printf("FTGL Render [%s] facesize = %d\n",str,ftFont->FaceSize()); assertGl(); ftFont->Render(str, len); //assertGl(); GLenum error = glGetError(); if(error != GL_NO_ERROR) { printf("\n[%s::%s] Line %d Error = %d [%s] for text [%s]\n",__FILE__,__FUNCTION__,__LINE__,error,gluErrorString(error),str); fflush(stdout); } if(ftFont->Error()) { char szBuf[8096]=""; snprintf(szBuf,8096,"FTGL: error trying to render, #%d",ftFont->Error()); throw megaglest_runtime_error(szBuf); } } }
void ModelRendererGl::end() { //assertions assert(rendering); assertGl(); //set render state rendering= false; if(this->colorPickingMode == false) { glPolygonOffset( 0.0f, 0.0f ); glDisable(GL_POLYGON_OFFSET_FILL); } //pop glPopAttrib(); glPopClientAttrib(); if(colorPickingMode == true) { BaseColorPickEntity::endPicking(); } //assertions assertGl(); }
bool ShaderProgramGl::link(string &messages){ assertGl(); VertexShaderGl *vertexShaderGl= static_cast<VertexShaderGl*>(vertexShader); FragmentShaderGl *fragmentShaderGl= static_cast<FragmentShaderGl*>(fragmentShader); const ShaderSource *vss= vertexShaderGl->getSource(); const ShaderSource *fss= fragmentShaderGl->getSource(); messages= "Linking program: " + vss->getPathInfo() + ", " + fss->getPathInfo() + "\n"; //attach glAttachObjectARB(handle, vertexShaderGl->getHandle()); glAttachObjectARB(handle, fragmentShaderGl->getHandle()); assertGl(); //bind attributes for(int i=0; i<attributes.size(); ++i){ //int a= attributes[i].second; //string s= attributes[i].first; glBindAttribLocationARB(handle, attributes[i].second, attributes[i].first.c_str()); } assertGl(); //link glLinkProgramARB(handle); glValidateProgramARB(handle); assertGl(); //log GLint logLength= 0; glGetObjectParameterivARB(handle, GL_OBJECT_INFO_LOG_LENGTH_ARB, &logLength); char *buffer= new char[logLength+1]; glGetInfoLogARB(handle, logLength+1, NULL, buffer); messages+= buffer; delete [] buffer; assertGl(); //status GLint status= false; glGetObjectParameterivARB(handle, GL_OBJECT_LINK_STATUS_ARB, &status); assertGl(); return status!=0; }
void BaseRenderer::renderMap(MapPreview *map, int x, int y, int clientW, int clientH, int cellSize, bool grid) { float alt=0; float showWater=0; assertGl(); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0, clientW, 0, clientH, 1, -1); glViewport(0, 0, clientW, clientH); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glPushAttrib(GL_CURRENT_BIT); glTranslatef(static_cast<float>(x), static_cast<float>(y), 0.0f); glLineWidth(1); glClear(GL_COLOR_BUFFER_BIT); glColor3f(0, 0, 0); for (int j = 0; j < map->getH(); j++) { for (int i = 0; i < map->getW(); i++) { if (i * cellSize + x > -cellSize && i * cellSize + x < clientW && clientH - cellSize - j * cellSize + y > -cellSize && clientH - cellSize - j * cellSize + y < clientH) { bool isCliff=false; // needed to speedup things //surface alt = map->getHeight(i, j) / 20.f; showWater = map->getWaterLevel()/ 20.f - alt; showWater = (showWater > 0)? showWater:0; Vec3f surfColor; switch (map->getSurface(i, j)) { case st_Grass: surfColor = Vec3f(0.0, 0.8f * alt, 0.f + showWater); break; case st_Secondary_Grass: surfColor = Vec3f(0.4f * alt, 0.6f * alt, 0.f + showWater); break; case st_Road: surfColor = Vec3f(0.6f * alt, 0.3f * alt, 0.f + showWater); break; case st_Stone: surfColor = Vec3f(0.7f * alt, 0.7f * alt, 0.7f * alt + showWater); break; case st_Ground: surfColor = Vec3f(0.7f * alt, 0.5f * alt, 0.3f * alt + showWater); break; } if(map->getCliffLevel()>0) {// we maybe need to render cliff surfColor if(map->isCliff(i, j)){ surfColor = Vec3f(0.95f * alt, 0.8f * alt, 0.0f * alt + showWater); isCliff=true; } } glColor3fv(surfColor.ptr()); glBegin(GL_TRIANGLE_STRIP); glVertex2i(i * cellSize, clientH - j * cellSize - cellSize); glVertex2i(i * cellSize, clientH - j * cellSize); glVertex2i(i * cellSize + cellSize, clientH - j * cellSize - cellSize); glVertex2i(i * cellSize + cellSize, clientH - j * cellSize); glEnd(); //objects switch (map->getObject(i, j)) { case 0: glColor3f(0.f, 0.f, 0.f); break; case 1: glColor3f(1.f, 0.f, 0.f); break; case 2: glColor3f(1.f, 1.f, 1.f); break; case 3: glColor3f(0.5f, 0.5f, 1.f); break; case 4: glColor3f(0.f, 0.f, 1.f); break; case 5: glColor3f(0.5f, 0.5f, 0.5f); break; case 6: glColor3f(1.f, 0.8f, 0.5f); break; case 7: glColor3f(0.f, 1.f, 1.f); break; case 8: glColor3f(0.7f, 0.1f, 0.3f); break; case 9: glColor3f(0.5f, 1.f, 0.1f); break; case 10: glColor3f(1.f, 0.2f, 0.8f); break; } if (map->getObject(i, j) != 0 || isCliff ) { glPointSize(cellSize / 2.f); glBegin(GL_POINTS); glVertex2i(i * cellSize + cellSize / 2, clientH - j * cellSize - cellSize / 2); glEnd(); } // bool found = false; //height lines // if (!found) { glColor3fv((surfColor*0.5f).ptr()); //left if (grid || (i > 0 && map->getHeight(i - 1, j) > map->getHeight(i, j))) { glBegin(GL_LINES); glVertex2i(i * cellSize, clientH - (j + 1) * cellSize); glVertex2i(i * cellSize, clientH - j * cellSize); glEnd(); } //down if (grid || (j > 0 && map->getHeight(i, j - 1) > map->getHeight(i, j))) { glBegin(GL_LINES); glVertex2i(i * cellSize, clientH - j * cellSize); glVertex2i((i + 1) * cellSize, clientH - j * cellSize); glEnd(); } glColor3fv((surfColor*2.f).ptr()); //left if (i > 0 && map->getHeight(i - 1, j) < map->getHeight(i, j)) { glBegin(GL_LINES); glVertex2i(i * cellSize, clientH - (j + 1) * cellSize); glVertex2i(i * cellSize, clientH - j * cellSize); glEnd(); } if (j > 0 && map->getHeight(i, j - 1) < map->getHeight(i, j)) { glBegin(GL_LINES); glVertex2i(i * cellSize, clientH - j * cellSize); glVertex2i((i + 1) * cellSize, clientH - j * cellSize); glEnd(); } // } //resources switch (map->getResource(i, j)) { case 1: glColor3f(1.f, 1.f, 0.f); break; case 2: glColor3f(0.5f, 0.5f, 0.5f); break; case 3: glColor3f(1.f, 0.f, 0.f); break; case 4: glColor3f(0.f, 0.f, 1.f); break; case 5: glColor3f(0.5f, 0.5f, 1.f); break; } if (map->getResource(i, j) != 0) { glBegin(GL_LINES); glVertex2i(i * cellSize, clientH - j * cellSize - cellSize); glVertex2i(i * cellSize + cellSize, clientH - j * cellSize); glVertex2i(i * cellSize, clientH - j * cellSize); glVertex2i(i * cellSize + cellSize, clientH - j * cellSize - cellSize); glEnd(); } } } } //start locations glLineWidth(3); for (int i = 0; i < map->getMaxFactions(); i++) { switch (i) { case 0: glColor3f(1.f, 0.f, 0.f); break; case 1: glColor3f(0.f, 0.f, 1.f); break; case 2: glColor3f(0.f, 1.f, 0.f); break; case 3: glColor3f(1.f, 1.f, 0.f); break; case 4: glColor3f(1.f, 1.f, 1.f); break; case 5: glColor3f(0.f, 1.f, 0.8f); break; case 6: glColor3f(1.f, 0.5f, 0.f); break; case 7: glColor3f(1.f, 0.5f, 1.f); break; } glBegin(GL_LINES); glVertex2i((map->getStartLocationX(i) - 1) * cellSize, clientH - (map->getStartLocationY(i) - 1) * cellSize); glVertex2i((map->getStartLocationX(i) + 1) * cellSize + cellSize, clientH - (map->getStartLocationY(i) + 1) * cellSize - cellSize); glVertex2i((map->getStartLocationX(i) - 1) * cellSize, clientH - (map->getStartLocationY(i) + 1) * cellSize - cellSize); glVertex2i((map->getStartLocationX(i) + 1) * cellSize + cellSize, clientH - (map->getStartLocationY(i) - 1) * cellSize); glEnd(); } glPopMatrix(); glPopAttrib(); assertGl(); }
void ShaderProgramGl::setUniform(const string &name, float value){ assertGl(); glUniform1fARB(getLocation(name), value); assertGl(); }
void ShaderProgramGl::activate(){ assertGl(); glUseProgramObjectARB(handle); assertGl(); }
void ModelRendererGl::renderMesh(Mesh *mesh,int renderMode) { if(renderMode==rmSelection && mesh->getNoSelect()==true) {// don't render this and do nothing return; } //assertions assertGl(); //glPolygonOffset(0.05f, 0.0f); //set cull face if(mesh->getTwoSided()) { glDisable(GL_CULL_FACE); } else{ glEnable(GL_CULL_FACE); } if(this->colorPickingMode == false) { //set color if(renderColors) { Vec4f color(mesh->getDiffuseColor(), mesh->getOpacity()); glColor4fv(color.ptr()); } //texture state const Texture2DGl *texture= static_cast<const Texture2DGl*>(mesh->getTexture(mtDiffuse)); if(texture != NULL && renderTextures) { if(lastTexture != texture->getHandle()){ //assert(glIsTexture(texture->getHandle())); //throw megaglest_runtime_error("glIsTexture(texture->getHandle()) == false for texture: " + texture->getPath()); if(glIsTexture(texture->getHandle()) == GL_TRUE) { glBindTexture(GL_TEXTURE_2D, texture->getHandle()); lastTexture= texture->getHandle(); } else { glBindTexture(GL_TEXTURE_2D, 0); lastTexture= 0; } } } else{ glBindTexture(GL_TEXTURE_2D, 0); lastTexture= 0; } if(meshCallback != NULL) { meshCallback->execute(mesh); } } //misc vars uint32 vertexCount= mesh->getVertexCount(); uint32 indexCount= mesh->getIndexCount(); //assertions assertGl(); if(getVBOSupported() == true && mesh->getFrameCount() == 1) { if(mesh->hasBuiltVBOEntities() == false) { mesh->BuildVBOs(); } //printf("Rendering Mesh with VBO's\n"); //vertices glBindBufferARB( GL_ARRAY_BUFFER_ARB, mesh->getVBOVertices() ); glVertexPointer( 3, GL_FLOAT, 0, (char *) NULL ); // Set The Vertex Pointer To The Vertex Buffer //glBindBufferARB( GL_ARRAY_BUFFER_ARB, 0 ); //normals if(renderNormals) { glBindBufferARB( GL_ARRAY_BUFFER_ARB, mesh->getVBONormals() ); glEnableClientState(GL_NORMAL_ARRAY); glNormalPointer(GL_FLOAT, 0, (char *) NULL); //glBindBufferARB( GL_ARRAY_BUFFER_ARB, 0 ); } else{ glDisableClientState(GL_NORMAL_ARRAY); } //tex coords if(renderTextures && mesh->getTexture(mtDiffuse) != NULL ) { if(duplicateTexCoords) { glActiveTexture(GL_TEXTURE0 + secondaryTexCoordUnit); glBindBufferARB( GL_ARRAY_BUFFER_ARB, mesh->getVBOTexCoords() ); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glTexCoordPointer( 2, GL_FLOAT, 0, (char *) NULL ); // Set The TexCoord Pointer To The TexCoord Buffer //glBindBufferARB( GL_ARRAY_BUFFER_ARB, 0 ); } glActiveTexture(GL_TEXTURE0); glBindBufferARB( GL_ARRAY_BUFFER_ARB, mesh->getVBOTexCoords() ); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glTexCoordPointer( 2, GL_FLOAT, 0, (char *) NULL ); // Set The TexCoord Pointer To The TexCoord Buffer //glBindBufferARB( GL_ARRAY_BUFFER_ARB, 0 ); } else { if(duplicateTexCoords) { glActiveTexture(GL_TEXTURE0 + secondaryTexCoordUnit); glDisableClientState(GL_TEXTURE_COORD_ARRAY); } glActiveTexture(GL_TEXTURE0); glDisableClientState(GL_TEXTURE_COORD_ARRAY); } } else { //printf("Rendering Mesh WITHOUT VBO's\n"); //vertices glVertexPointer(3, GL_FLOAT, 0, mesh->getInterpolationData()->getVertices()); //normals if(renderNormals) { glEnableClientState(GL_NORMAL_ARRAY); glNormalPointer(GL_FLOAT, 0, mesh->getInterpolationData()->getNormals()); } else{ glDisableClientState(GL_NORMAL_ARRAY); } //tex coords if(renderTextures && mesh->getTexture(mtDiffuse)!=NULL ) { if(duplicateTexCoords) { glActiveTexture(GL_TEXTURE0 + secondaryTexCoordUnit); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glTexCoordPointer(2, GL_FLOAT, 0, mesh->getTexCoords()); } glActiveTexture(GL_TEXTURE0); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glTexCoordPointer(2, GL_FLOAT, 0, mesh->getTexCoords()); } else { if(duplicateTexCoords) { glActiveTexture(GL_TEXTURE0 + secondaryTexCoordUnit); glDisableClientState(GL_TEXTURE_COORD_ARRAY); } glActiveTexture(GL_TEXTURE0); glDisableClientState(GL_TEXTURE_COORD_ARRAY); } } if(getVBOSupported() == true && mesh->getFrameCount() == 1) { glBindBufferARB( GL_ELEMENT_ARRAY_BUFFER_ARB, mesh->getVBOIndexes() ); glDrawRangeElements(GL_TRIANGLES, 0, vertexCount-1, indexCount, GL_UNSIGNED_INT, (char *)NULL); glBindBufferARB( GL_ELEMENT_ARRAY_BUFFER_ARB, 0 ); glBindBufferARB( GL_ARRAY_BUFFER_ARB, 0 ); //glDrawRangeElements(GL_TRIANGLES, 0, vertexCount-1, indexCount, GL_UNSIGNED_INT, mesh->getIndices()); } else { //draw model glDrawRangeElements(GL_TRIANGLES, 0, vertexCount-1, indexCount, GL_UNSIGNED_INT, mesh->getIndices()); } //assertions assertGl(); }
void ModelRendererGl::begin(bool renderNormals, bool renderTextures, bool renderColors, bool colorPickingMode, MeshCallback *meshCallback) { //assertions assert(rendering == false); assertGl(); this->renderTextures= renderTextures; this->renderNormals= renderNormals; this->renderColors= renderColors; this->colorPickingMode = colorPickingMode; this->meshCallback= meshCallback; rendering= true; lastTexture= 0; glBindTexture(GL_TEXTURE_2D, 0); //push attribs glPushAttrib(GL_ENABLE_BIT | GL_LIGHTING_BIT | GL_POLYGON_BIT | GL_CURRENT_BIT | GL_TEXTURE_BIT); glPushClientAttrib(GL_CLIENT_VERTEX_ARRAY_BIT); //init opengl if(this->colorPickingMode == false) { glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); } glBindTexture(GL_TEXTURE_2D, 0); glFrontFace(GL_CCW); if(this->colorPickingMode == false) { glEnable(GL_NORMALIZE); glEnable(GL_BLEND); glEnable(GL_POLYGON_OFFSET_FILL); glPolygonOffset(0.005f, 0.0f); } glEnableClientState(GL_VERTEX_ARRAY); if(renderNormals){ glEnableClientState(GL_NORMAL_ARRAY); } if(renderTextures){ glEnableClientState(GL_TEXTURE_COORD_ARRAY); } /* glHint( GL_LINE_SMOOTH_HINT, GL_FASTEST ); glHint( GL_FRAGMENT_SHADER_DERIVATIVE_HINT, GL_FASTEST ); glHint( GL_GENERATE_MIPMAP_HINT, GL_FASTEST ); glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST ); glHint( GL_POINT_SMOOTH_HINT, GL_FASTEST ); glHint( GL_POLYGON_SMOOTH_HINT, GL_FASTEST ); glHint( GL_TEXTURE_COMPRESSION_HINT, GL_FASTEST ); */ if(this->colorPickingMode == true) { BaseColorPickEntity::beginPicking(); } //assertions assertGl(); }
void ShaderProgramGl::setUniform(const string &name, const Vec4f &value){ assertGl(); glUniform4fvARB(getLocation(name), 1, value.ptr()); assertGl(); }
void ShaderProgramGl::setUniform(const string &name, const Matrix4f &value){ assertGl(); glUniformMatrix4fvARB(getLocation(name), 1, GL_FALSE, value.ptr()); assertGl(); }
void ShaderProgramGl::deactivate(){ assertGl(); glUseProgramObjectARB(0); assertGl(); }
void Renderer::reset(int w, int h, PlayerColor playerColor) { assertGl(); width=w; height=h; //glClearColor(red, green, blue, alpha); //backgroundcolor constant 0.3 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); /* once the GL context is valid : */ //GLint alpha_bits; //glGetIntegerv(GL_ALPHA_BITS, &alpha_bits); //printf("#2 The framebuffer uses %d bit(s) per the alpha component\n", alpha_bits); glViewport(0, 0, w, h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(60.0f, static_cast<float>(w)/h, 1.0f, 200.0f); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glTranslatef(0, -1.5, -5); Texture2D *customTexture=NULL; switch(playerColor) { case pcRed: customTexture= customTextureRed; break; case pcBlue: customTexture= customTextureBlue; break; case pcGreen: customTexture= customTextureGreen; break; case pcYellow: customTexture= customTextureYellow; break; case pcWhite: customTexture= customTextureWhite; break; case pcCyan: customTexture= customTextureCyan; break; case pcOrange: customTexture= customTextureOrange; break; case pcMagenta: customTexture= customTextureMagenta; break; default: assert(false); break; } meshCallbackTeamColor.setTeamTexture(customTexture); if(wireframe) { glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); glDisable(GL_TEXTURE_2D); glDisable(GL_LIGHTING); glDisable(GL_LIGHT0); } else { glEnable(GL_TEXTURE_2D); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); } assertGl(); }
void Renderer::init() { assertGl(); GraphicsFactory *gf= GraphicsInterface::getInstance().getFactory(); if(gf == NULL) { gf= new GraphicsFactoryGl(); GraphicsInterface::getInstance().setFactory(gf); } Config &config = Config::getInstance(); if(config.getBool("CheckGlCaps")){ if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); checkGlCaps(); } if(glActiveTexture == NULL) { char szBuf[8096]=""; snprintf(szBuf,8096,"Error: glActiveTexture == NULL\nglActiveTexture is only supported if the GL version is 1.3 or greater,\nor if the ARB_multitexture extension is supported!"); throw megaglest_runtime_error(szBuf); } modelRenderer= gf->newModelRenderer(); textureManager= gf->newTextureManager(); particleRenderer= gf->newParticleRenderer(); //resources particleManager= gf->newParticleManager(); modelManager = gf->newModelManager(); modelManager->setTextureManager(textureManager); //red tex customTextureRed= textureManager->newTexture2D(); customTextureRed->getPixmap()->init(1, 1, 3); customTextureRed->getPixmap()->setPixel(0, 0, Vec3f(1.f, 0.f, 0.f)); //blue tex customTextureBlue= textureManager->newTexture2D(); customTextureBlue->getPixmap()->init(1, 1, 3); customTextureBlue->getPixmap()->setPixel(0, 0, Vec3f(0.f, 0.f, 1.f)); //green tex customTextureGreen= textureManager->newTexture2D(); customTextureGreen->getPixmap()->init(1, 1, 3); customTextureGreen->getPixmap()->setPixel(0, 0, Vec3f(0.f, 0.5f, 0.f)); //yellow tex customTextureYellow= textureManager->newTexture2D(); customTextureYellow->getPixmap()->init(1, 1, 3); customTextureYellow->getPixmap()->setPixel(0, 0, Vec3f(1.f, 1.f, 0.f)); //white tex customTextureWhite= textureManager->newTexture2D(); customTextureWhite->getPixmap()->init(1, 1, 3); customTextureWhite->getPixmap()->setPixel(0, 0, Vec3f(1.f, 1.f, 1.f)); //cyan tex customTextureCyan= textureManager->newTexture2D(); customTextureCyan->getPixmap()->init(1, 1, 3); customTextureCyan->getPixmap()->setPixel(0, 0, Vec3f(0.f, 1.f, 0.8f)); //orange tex customTextureOrange= textureManager->newTexture2D(); customTextureOrange->getPixmap()->init(1, 1, 3); customTextureOrange->getPixmap()->setPixel(0, 0, Vec3f(1.f, 0.5f, 0.f)); //magenta tex customTextureMagenta= textureManager->newTexture2D(); customTextureMagenta->getPixmap()->init(1, 1, 3); customTextureMagenta->getPixmap()->setPixel(0, 0, Vec3f(1.f, 0.5f, 1.f)); glClearColor(red, green, blue, alpha); //backgroundcolor constant 0.3 //glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); /* once the GL context is valid : */ //GLint alpha_bits; //glGetIntegerv(GL_ALPHA_BITS, &alpha_bits); //printf("#1 The framebuffer uses %d bit(s) per the alpha component\n", alpha_bits); glEnable(GL_TEXTURE_2D); glFrontFace(GL_CW); glEnable(GL_CULL_FACE); glEnable(GL_DEPTH_TEST); glEnable(GL_ALPHA_TEST); //glAlphaFunc(GL_GREATER, 0.5f); glAlphaFunc(GL_GREATER, 0.0f); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); Vec4f diffuse= Vec4f(1.0f, 1.0f, 1.0f, 1.0f); Vec4f ambient= Vec4f(0.3f, 0.3f, 0.3f, 1.0f); Vec4f specular= Vec4f(0.1f, 0.1f, 0.1f, 1.0f); glLightfv(GL_LIGHT0,GL_AMBIENT, ambient.ptr()); glLightfv(GL_LIGHT0,GL_DIFFUSE, diffuse.ptr()); glLightfv(GL_LIGHT0,GL_SPECULAR, specular.ptr()); glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE); glEnable(GL_COLOR_MATERIAL); assertGl(); }