void PolygonBackground::clear(DrawEnv *pEnv) { #if !defined(OSG_OGL_COREONLY) || defined(OSG_CHECK_COREONLY) if(pEnv->getPixelWidth() == 0 || pEnv->getPixelHeight() == 0 ) { FWARNING(("Port has zero size: nothing to render to!\n")); return; } if(getMFPositions()->size() == 0 || getMFPositions()->size() != getMFTexCoords()->size()) { FWARNING(("PolygonBackground::clear: positions and texcoords have " "different/ invalid sizes (%d vs. %d)!\n", getMFPositions()->size(), getMFTexCoords()->size())); return; } Int32 bit = getClearStencilBit(); // 0x0 if(bit >= 0) { glClearStencil(bit); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); } else { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); } glPushAttrib(GL_ALL_ATTRIB_BITS); glDisable(GL_DEPTH_TEST); glDepthFunc(GL_ALWAYS); if(getCleanup()) glDepthMask(GL_FALSE); Real32 aspectX = 1.0f, aspectY = 1.0f; if(getAspectHeight() != 0 && getAspectWidth() != 0) { aspectX = (Real32(pEnv->getPixelHeight()) / getAspectHeight()) / (Real32(pEnv->getPixelWidth ()) / getAspectWidth ()); } Real32 sFac = getScale() > 0 ? getScale() : 1.0f; UInt32 fullWidth; UInt32 fullHeight; if(!getTile()) { beginOrthoRender(pEnv, getNormalizedX(), getNormalizedY(), fullWidth, fullHeight ); Real32 t = 0; if(getAspectHeight() != 0 && getAspectWidth() != 0 && fullHeight != 0 && fullHeight != 0 ) { aspectX = (Real32(fullHeight) / getAspectHeight()) / (Real32(fullWidth ) / getAspectWidth ()); t = Real32(fullWidth) * (1.0f - aspectX) * 0.5f; t *= Real32(pEnv->getPixelWidth()) / fullWidth; } glTranslatef(t, 0.0f, 0.0f); glScalef (aspectX, aspectY, 1.0f); Real32 tW = (1.0f - sFac) * 0.5f * Real32(pEnv->getPixelWidth ()); Real32 tH = (1.0f - sFac) * 0.5f * Real32(pEnv->getPixelHeight()); glTranslatef(tW, tH, 0.0f); glScalef (sFac, sFac, 1.0f); } else { glScalef(sFac, sFac, 1.0f); glScalef(aspectX, aspectY, 1.0f); beginOrthoRender(pEnv, getNormalizedX(), getNormalizedY(), fullWidth, fullHeight ); } getMaterial()->getState()->activate(pEnv); const Vec3f *tc = &getMFTexCoords()->front(); const Pnt2f *pos = &getMFPositions()->front(); glBegin(GL_POLYGON); for (UInt16 i=0; i < getMFPositions()->size(); i++) { glTexCoord3fv( tc[i].getValues()); glVertex2fv (pos[i].getValues()); } glEnd(); getMaterial()->getState()->deactivate(pEnv); glScalef(1, 1, 1); if(getCleanup()) { if(bit >= 0) { glClear(GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); } else { glClear(GL_DEPTH_BUFFER_BIT); } } endOrthoRender(pEnv); glPopAttrib(); #endif }
void PolygonForeground::draw(DrawEnv *pEnv) { if(getActive() == false) return; if(getMFPositions()->size() == 0) // nothing to render return; if(pEnv->getPixelWidth() == 0 || pEnv->getPixelHeight() == 0 ) // nothing to render to return; bool bUseTC = true; if(getMFPositions()->size() != getMFTexCoords()->size()) { #if 0 FWARNING(("PolygonForeground::draw: positions and texcoords have " "different sizes (%d vs. %d)!\n", getMFPositions()->size(), getMFTexCoords()->size())); return; #endif bUseTC = false; } glPushAttrib(GL_ALL_ATTRIB_BITS); Real32 aspectX = 1.0f, aspectY = 1.0f; if(getAspectHeight() && getAspectWidth()) { aspectX = (Real32(pEnv->getPixelHeight()) / getAspectHeight()) / (Real32(pEnv->getPixelWidth()) / getAspectWidth()); } glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); Real32 sFac = getScale() > 0 ? getScale() : 1.0f; UInt32 width = pEnv->getPixelWidth(), height = pEnv->getPixelHeight(); if(pEnv->getTileFullSize()[0] != 0 && getTile() == false) { width = pEnv->getTileFullSize()[0]; height = pEnv->getTileFullSize()[1]; Real32 t = 0; #if 0 Real32 left = pEnv->getTileRegion()[0]; //cdP->getLeft(), Real32 right = pEnv->getTileRegion()[1]; //cdP->getRight(), Real32 top = pEnv->getTileRegion()[3]; //cdP->getTop(), Real32 bottom = pEnv->getTileRegion()[2]; //cdP->getBottom(); #endif if (getAspectHeight() && getAspectWidth() && height != 0 && width != 0) { aspectX = (Real32(height/getAspectHeight())) / (Real32(width / getAspectWidth())); t = Real32(width) * (1 - aspectX) * 0.5f; t *= Real32(pEnv->getPixelWidth()) / width; } Matrix sm = pEnv->calcTileDecorationMatrix(); glLoadMatrixf(sm.getValues()); glOrtho(0, pEnv->getPixelWidth(), 0, pEnv->getPixelHeight(), 0, 1); glTranslatef(t, 0, 0); glScalef(aspectX, aspectY, 1); float t1 = (1 - sFac) * 0.5f * Real32(pEnv->getPixelWidth()); float t2 = (1 - sFac) * 0.5f * Real32(pEnv->getPixelHeight()); glTranslatef(t1, t2, 0); glScalef(sFac,sFac,1); } else { glScalef(sFac,sFac,1); glScalef(aspectX, aspectY, 1); glOrtho(0, pEnv->getPixelWidth(), 0, pEnv->getPixelHeight(), 0, 1); } getMaterial()->getState()->activate(pEnv); const Vec3f *tc = NULL; if(bUseTC == true) { tc = &((*getMFTexCoords())[0]); } const Pnt2f *pos = &((*getMFPositions())[0]); glBegin(GL_POLYGON); for(UInt16 i = 0; i < getMFPositions()->size(); i++) { if(bUseTC == true) { glTexCoord3fv( tc[i].getValues() ); } glVertex2f( mapCoordinate(pos[i][0], Real32(pEnv->getPixelWidth()), getNormalizedX()), mapCoordinate(pos[i][1], Real32(pEnv->getPixelHeight()), getNormalizedY()) ); } glEnd(); getMaterial()->getState()->deactivate(pEnv); glScalef(1, 1, 1); glPopMatrix(); glMatrixMode(GL_MODELVIEW); glPopMatrix(); glPopAttrib(); }
void loadPGMFile(){ FILE *pgmFile; char pgm_name[10000]; size_t x,y; unsigned int k=0; GLfloat **verticesArrayX, **verticesArrayY, **verticesArrayZ; // pgmFile = fopen("sthelens_after.pgm","r"); pgmFile = fopen("dem/sthelens_before.pgm","r"); //pgmFile = fopen("dem/mtbachelor.pgm","r"); fgets(pgm_name,10000,pgmFile); fscanf(pgmFile,"%d", &width); fscanf(pgmFile,"%d", &height); fscanf(pgmFile,"%d", &maxVal); gridData = malloc(height * sizeof(int *)); for( x = 0; x < height; x++){ gridData[x] = malloc(width * sizeof(int)); for(y = 0; y < width; y++){ fscanf(pgmFile, "%d", &gridData[x][y]); } } verticesArray = malloc(width * height * 3 * sizeof(GLfloat)); indicesArray = malloc(width * height * 6 * sizeof(GLuint)); normalsArray = malloc(width * height * 3 * sizeof(GLfloat)); verticesArrayX = malloc(height*sizeof(GLfloat*)); verticesArrayY = malloc(height*sizeof(GLfloat*)); verticesArrayZ = malloc(height*sizeof(GLfloat*)); for(k=0;k<height;k++) { verticesArrayX[k] = malloc(width* sizeof(GLfloat)); verticesArrayY[k] = malloc(width* sizeof(GLfloat)); verticesArrayZ[k] = malloc(width* sizeof(GLfloat)); } int indicesI=0; unsigned long i=0,j=0; unsigned long vertexIndex = 0; for(j=0;j<height;j++){ for(i=0;i<width; i++){ verticesArrayX[j][i] = getNormalizedX(i); verticesArrayY[j][i] = getNormalizedY(j); verticesArrayZ[j][i] = getNormalizedZ(i,j); verticesArray[vertexIndex++] = verticesArrayX[j][i]; verticesArray[vertexIndex++] = verticesArrayY[j][i]; verticesArray[vertexIndex++] = verticesArrayZ[j][i]; } } indicesI=0; for( size_t row = 1; row < height; ++row ){ for( size_t col = 1; col < width; ++col ) { indicesArray[indicesI++] = ( (col-1) + (row-1) * width ); indicesArray[indicesI++] = ( (col-0) + (row-1) * width ); indicesArray[indicesI++] = ( (col-1) + (row-0) * width ); indicesArray[indicesI++] = ( (col-1) + (row-0) * width ); indicesArray[indicesI++] = ( (col-0) + (row-1) * width ); indicesArray[indicesI++] = ( (col-0) + (row-0) * width ); } } unsigned long normalIndex = 0; for(size_t row=0; row < height; ++row){ for(size_t col =0; col < width; ++col){ GLfloat *normalResult; getNormals(verticesArrayX,verticesArrayY, verticesArrayZ, row,col,height,width, &normalResult); normalsArray[normalIndex++]= normalResult[0]; normalsArray[normalIndex++]= normalResult[1]; normalsArray[normalIndex++]= normalResult[2]; } } totalVertices = width*height*3; totalIndices = indicesI; totalNormals = width*height*3; // computeMinimum(); }