void L_ParticleEffect::RenderPointSprites(SurfaceAnim *pSurf, int start, int count) { pSurf->Bind(); glBlendFunc( GL_SRC_ALPHA, GL_ONE); //this point sprite code was based on code from http://www.71squared.com/2009/05/iphone-game-programming-tutorial-8-particle-emitter/ which //was based on some cocos2d code I think -Seth glBindBuffer(GL_ARRAY_BUFFER, L_ParticleMem::pointSpriteBufferID); CHECK_GL_ERROR(); glBufferData(GL_ARRAY_BUFFER, sizeof(PointSprite)*count, &L_ParticleMem::pointSpriteArray[0], GL_DYNAMIC_DRAW); CHECK_GL_ERROR(); glEnable(GL_BLEND); // Enable and configure point sprites which we are going to use for our particles glEnable(GL_POINT_SPRITE_OES); CHECK_GL_ERROR(); glTexEnvi( GL_POINT_SPRITE_OES, GL_COORD_REPLACE_OES, GL_TRUE ); CHECK_GL_ERROR(); // Enable vertex arrays and bind to the vertices VBO which has been created glEnableClientState(GL_VERTEX_ARRAY); CHECK_GL_ERROR(); glBindBuffer(GL_ARRAY_BUFFER, L_ParticleMem::pointSpriteBufferID); CHECK_GL_ERROR(); // Configure the vertex pointer which will use the vertices VBO glVertexPointer(2, GL_FLOAT, sizeof(PointSprite), 0); CHECK_GL_ERROR(); // Enable the point size array glEnableClientState(GL_POINT_SIZE_ARRAY_OES); // Configure the point size pointer which will use the currently bound VBO. PointSprite contains // both the location of the point as well as its size, so the config below tells the point size // pointer where in the currently bound VBO it can find the size for each point glPointSizePointerOES(GL_FLOAT,sizeof(PointSprite),(GLvoid*) (sizeof(GL_FLOAT)*2)); // Enable the use of the color array glEnableClientState(GL_COLOR_ARRAY); // Configure the color pointer specifying how many values there are for each color and their type glColorPointer(4,GL_UNSIGNED_BYTE,sizeof(PointSprite),(GLvoid*) (sizeof(GL_FLOAT)*3)); // Now that all of the VBOs have been used to configure the vertices, pointer size and color // use glDrawArrays to draw the points //NOTE: It crashes here on the WebOS GLES windows emulator .. but runs on the device. driver bug I guess -Seth //Another note: It also can crash a Touchpad so.. not going to use this optimized point sprite stuff for webos :( glDrawArrays(GL_POINTS, start, count); CHECK_GL_ERROR(); // Unbind the current VBO glBindBuffer(GL_ARRAY_BUFFER, 0); CHECK_GL_ERROR(); // Disable the client states which have been used incase the next draw function does // not need or use them glDisableClientState(GL_POINT_SIZE_ARRAY_OES); glDisableClientState(GL_COLOR_ARRAY); CHECK_GL_ERROR(); glDisable(GL_POINT_SPRITE_OES); CHECK_GL_ERROR(); glDisableClientState(GL_POINT_SIZE_ARRAY_OES); glDisableClientState(GL_COLOR_ARRAY); CHECK_GL_ERROR(); glDisable(GL_POINT_SPRITE_OES); glDisable(GL_BLEND); glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); CHECK_GL_ERROR(); }
JNIEXPORT void JNICALL Java_com_qualcomm_QCARSamples_VideoPlayback_VideoPlaybackRenderer_renderFrame(JNIEnv *, jobject) { //LOG("Java_com_qualcomm_QCARSamples_VideoPlayback_GLRenderer_renderFrame"); // Clear color and depth buffer glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Get the state from QCAR and mark the beginning of a rendering section QCAR::State state = QCAR::Renderer::getInstance().begin(); // Explicitly render the Video Background QCAR::Renderer::getInstance().drawVideoBackground(); glEnable(GL_DEPTH_TEST); // We must detect if background reflection is active and adjust the culling direction. // If the reflection is active, this means the post matrix has been reflected as well, // therefore standard counter clockwise face culling will result in "inside out" models. glEnable(GL_CULL_FACE); glCullFace(GL_BACK); if(QCAR::Renderer::getInstance().getVideoBackgroundConfig().mReflection == QCAR::VIDEO_BACKGROUND_REFLECTION_ON) glFrontFace(GL_CW); //Front camera else glFrontFace(GL_CCW); //Back camera for (int i=0; i<NUM_TARGETS; i++) { isTracking[i] = false; targetPositiveDimensions[i].data[0] = 0.0; targetPositiveDimensions[i].data[1] = 0.0; } // Did we find any trackables this frame? for(int tIdx = 0; tIdx < state.getNumTrackableResults(); tIdx++) { // Get the trackable: const QCAR::TrackableResult* trackableResult = state.getTrackableResult(tIdx); const QCAR::ImageTarget& imageTarget = (const QCAR::ImageTarget&) trackableResult->getTrackable(); int currentTarget; // We store the modelview matrix to be used later by the tap calculation if (strcmp(imageTarget.getName(), "stones") == 0) currentTarget=STONES; else currentTarget=CHIPS; modelViewMatrix[currentTarget] = QCAR::Tool::convertPose2GLMatrix(trackableResult->getPose()); isTracking[currentTarget] = true; targetPositiveDimensions[currentTarget] = imageTarget.getSize(); // The pose delivers the center of the target, thus the dimensions // go from -width/2 to width/2, same for height targetPositiveDimensions[currentTarget].data[0] /= 2.0f; targetPositiveDimensions[currentTarget].data[1] /= 2.0f; // If the movie is ready to start playing or it has reached the end // of playback we render the keyframe if ((currentStatus[currentTarget] == READY) || (currentStatus[currentTarget] == REACHED_END) || (currentStatus[currentTarget] == NOT_READY) || (currentStatus[currentTarget] == ERROR)) { QCAR::Matrix44F modelViewMatrixKeyframe = QCAR::Tool::convertPose2GLMatrix(trackableResult->getPose()); QCAR::Matrix44F modelViewProjectionKeyframe; SampleUtils::translatePoseMatrix(0.0f, 0.0f, targetPositiveDimensions[currentTarget].data[0], &modelViewMatrixKeyframe.data[0]); // Here we use the aspect ratio of the keyframe since it // is likely that it is not a perfect square float ratio=1.0; if (textures[currentTarget]->mSuccess) ratio = keyframeQuadAspectRatio[currentTarget]; else ratio = targetPositiveDimensions[currentTarget].data[1] / targetPositiveDimensions[currentTarget].data[0]; SampleUtils::scalePoseMatrix(targetPositiveDimensions[currentTarget].data[0], targetPositiveDimensions[currentTarget].data[0]*ratio, targetPositiveDimensions[currentTarget].data[0], &modelViewMatrixKeyframe.data[0]); SampleUtils::multiplyMatrix(&projectionMatrix.data[0], &modelViewMatrixKeyframe.data[0] , &modelViewProjectionKeyframe.data[0]); glUseProgram(keyframeShaderID); // Prepare for rendering the keyframe glVertexAttribPointer(keyframeVertexHandle, 3, GL_FLOAT, GL_FALSE, 0, (const GLvoid*) &quadVertices[0]); glVertexAttribPointer(keyframeNormalHandle, 3, GL_FLOAT, GL_FALSE, 0, (const GLvoid*) &quadNormals[0]); glVertexAttribPointer(keyframeTexCoordHandle, 2, GL_FLOAT, GL_FALSE, 0, (const GLvoid*) &quadTexCoords[0]); glEnableVertexAttribArray(keyframeVertexHandle); glEnableVertexAttribArray(keyframeNormalHandle); glEnableVertexAttribArray(keyframeTexCoordHandle); glActiveTexture(GL_TEXTURE0); // The first loaded texture from the assets folder is the keyframe glBindTexture(GL_TEXTURE_2D, textures[currentTarget]->mTextureID); glUniformMatrix4fv(keyframeMVPMatrixHandle, 1, GL_FALSE, (GLfloat*)&modelViewProjectionKeyframe.data[0] ); glUniform1i(keyframeTexSampler2DHandle, 0 /*GL_TEXTURE0*/); // Render glDrawElements(GL_TRIANGLES, NUM_QUAD_INDEX, GL_UNSIGNED_SHORT, (const GLvoid*) &quadIndices[0]); glDisableVertexAttribArray(keyframeVertexHandle); glDisableVertexAttribArray(keyframeNormalHandle); glDisableVertexAttribArray(keyframeTexCoordHandle); glUseProgram(0); } else // In any other case, such as playing or paused, we render the actual contents { QCAR::Matrix44F modelViewMatrixVideo = QCAR::Tool::convertPose2GLMatrix(trackableResult->getPose()); QCAR::Matrix44F modelViewProjectionVideo; SampleUtils::translatePoseMatrix(0.0f, 0.0f, targetPositiveDimensions[currentTarget].data[0], &modelViewMatrixVideo.data[0]); // Here we use the aspect ratio of the video frame SampleUtils::scalePoseMatrix(targetPositiveDimensions[currentTarget].data[0], targetPositiveDimensions[currentTarget].data[0]*videoQuadAspectRatio[currentTarget], targetPositiveDimensions[currentTarget].data[0], &modelViewMatrixVideo.data[0]); SampleUtils::multiplyMatrix(&projectionMatrix.data[0], &modelViewMatrixVideo.data[0] , &modelViewProjectionVideo.data[0]); glUseProgram(videoPlaybackShaderID); // Prepare for rendering the keyframe glVertexAttribPointer(videoPlaybackVertexHandle, 3, GL_FLOAT, GL_FALSE, 0, (const GLvoid*) &quadVertices[0]); glVertexAttribPointer(videoPlaybackNormalHandle, 3, GL_FLOAT, GL_FALSE, 0, (const GLvoid*) &quadNormals[0]); if (strcmp(imageTarget.getName(), "stones") == 0) glVertexAttribPointer(videoPlaybackTexCoordHandle, 2, GL_FLOAT, GL_FALSE, 0, (const GLvoid*) &videoQuadTextureCoordsTransformedStones[0]); else glVertexAttribPointer(videoPlaybackTexCoordHandle, 2, GL_FLOAT, GL_FALSE, 0, (const GLvoid*) &videoQuadTextureCoordsTransformedChips[0]); glEnableVertexAttribArray(videoPlaybackVertexHandle); glEnableVertexAttribArray(videoPlaybackNormalHandle); glEnableVertexAttribArray(videoPlaybackTexCoordHandle); glActiveTexture(GL_TEXTURE0); // IMPORTANT: // Notice here that the texture that we are binding is not the // typical GL_TEXTURE_2D but instead the GL_TEXTURE_EXTERNAL_OES glBindTexture(GL_TEXTURE_EXTERNAL_OES, videoPlaybackTextureID[currentTarget]); glUniformMatrix4fv(videoPlaybackMVPMatrixHandle, 1, GL_FALSE, (GLfloat*)&modelViewProjectionVideo.data[0]); glUniform1i(videoPlaybackTexSamplerOESHandle, 0 /*GL_TEXTURE0*/); // Render glDrawElements(GL_TRIANGLES, NUM_QUAD_INDEX, GL_UNSIGNED_SHORT, (const GLvoid*) &quadIndices[0]); glDisableVertexAttribArray(videoPlaybackVertexHandle); glDisableVertexAttribArray(videoPlaybackNormalHandle); glDisableVertexAttribArray(videoPlaybackTexCoordHandle); glUseProgram(0); } // The following section renders the icons. The actual textures used // are loaded from the assets folder /* if ((currentStatus[currentTarget] == READY) || (currentStatus[currentTarget] == REACHED_END) || (currentStatus[currentTarget] == PAUSED) || (currentStatus[currentTarget] == NOT_READY) || (currentStatus[currentTarget] == ERROR)) { // If the movie is ready to be played, pause, has reached end or is not // ready then we display one of the icons QCAR::Matrix44F modelViewMatrixButton = QCAR::Tool::convertPose2GLMatrix(trackableResult->getPose()); QCAR::Matrix44F modelViewProjectionButton; glDepthFunc(GL_LEQUAL); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // The inacuracy of the rendering process in some devices means that // even if we use the "Less or Equal" version of the depth function // it is likely that we will get ugly artifacts // That is the translation in the Z direction is slightly different // Another posibility would be to use a depth func "ALWAYS" but // that is typically not a good idea SampleUtils::translatePoseMatrix(0.0f, 0.0f, targetPositiveDimensions[currentTarget].data[1]/1.98f, &modelViewMatrixButton.data[0]); SampleUtils::scalePoseMatrix((targetPositiveDimensions[currentTarget].data[1]/2.0f), (targetPositiveDimensions[currentTarget].data[1]/2.0f), (targetPositiveDimensions[currentTarget].data[1]/2.0f), &modelViewMatrixButton.data[0]); SampleUtils::multiplyMatrix(&projectionMatrix.data[0], &modelViewMatrixButton.data[0] , &modelViewProjectionButton.data[0]); glUseProgram(keyframeShaderID); glVertexAttribPointer(keyframeVertexHandle, 3, GL_FLOAT, GL_FALSE, 0, (const GLvoid*) &quadVertices[0]); glVertexAttribPointer(keyframeNormalHandle, 3, GL_FLOAT, GL_FALSE, 0, (const GLvoid*) &quadNormals[0]); glVertexAttribPointer(keyframeTexCoordHandle, 2, GL_FLOAT, GL_FALSE, 0, (const GLvoid*) &quadTexCoords[0]); glEnableVertexAttribArray(keyframeVertexHandle); glEnableVertexAttribArray(keyframeNormalHandle); glEnableVertexAttribArray(keyframeTexCoordHandle); glActiveTexture(GL_TEXTURE0); // Depending on the status in which we are we choose the appropriate // texture to display. Notice that unlike the video these are regular // GL_TEXTURE_2D textures switch (currentStatus[currentTarget]) { case READY: glBindTexture(GL_TEXTURE_2D, textures[2]->mTextureID); break; case REACHED_END: glBindTexture(GL_TEXTURE_2D, textures[2]->mTextureID); break; case PAUSED: glBindTexture(GL_TEXTURE_2D, textures[2]->mTextureID); break; case NOT_READY: glBindTexture(GL_TEXTURE_2D, textures[3]->mTextureID); break; case ERROR: glBindTexture(GL_TEXTURE_2D, textures[4]->mTextureID); break; default: glBindTexture(GL_TEXTURE_2D, textures[3]->mTextureID); break; } glUniformMatrix4fv(keyframeMVPMatrixHandle, 1, GL_FALSE, (GLfloat*)&modelViewProjectionButton.data[0] ); glUniform1i(keyframeTexSampler2DHandle, 0 /*GL_TEXTURE0/); // Render glDrawElements(GL_TRIANGLES, NUM_QUAD_INDEX, GL_UNSIGNED_SHORT, (const GLvoid*) &quadIndices[0]); glDisableVertexAttribArray(keyframeVertexHandle); glDisableVertexAttribArray(keyframeNormalHandle); glDisableVertexAttribArray(keyframeTexCoordHandle); glUseProgram(0); // Finally we return the depth func to its original state glDepthFunc(GL_LESS); glDisable(GL_BLEND); } */ SampleUtils::checkGlError("VideoPlayback renderFrame"); } glDisable(GL_DEPTH_TEST); QCAR::Renderer::getInstance().end(); }
void RawStencilBufferTest3::setupStencilForClippingOnPlane(GLint plane) { RawStencilBufferTest::setupStencilForClippingOnPlane(plane); glDisable(GL_DEPTH_TEST); glDepthMask(GL_FALSE); }
/* draw the scene */ static Bool draw_antinspect_strip(ModeInfo * mi) { antinspectstruct *mp = &antinspect[MI_SCREEN(mi)]; int i, j; int mono = MI_IS_MONO(mi); int ro = (((int)antposition[1])/(360/(2*ANTCOUNT))) % (2*ANTCOUNT); glEnable(GL_TEXTURE_2D); position0[1] = 9.6; glLightfv(GL_LIGHT0, GL_POSITION, position0); glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialGray5); glRotatef(-30.0, 0.0, 1.0, 0.0); glDisable(GL_TEXTURE_2D); glDisable(GL_BLEND); /* render ground plane */ glBegin(GL_TRIANGLES); glColor4fv(MaterialShadow); glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialBlack); glNormal3f(0.0, 1.0, 0.0); /* middle tri */ glVertex3f(0.0, 0.0, -1.0); glVertex3f(-sqrt(3.0)/2.0, 0.0, 0.5); glVertex3f(sqrt(3.0)/2.0, 0.0, 0.5); mi->polygon_count++; glEnd(); /* rotate */ for(i = 0; i < 3; ++i) { glRotatef(120.0, 0.0, 1.0, 0.0); glBegin(GL_TRIANGLES); glVertex3f(0.0, 0.0, 1.0 + 3.0); glVertex3f(sqrt(3.0)/2.0, 0.0, -0.5 + 3.0); glVertex3f(-sqrt(3.0)/2.0, 0.0, -0.5 + 3.0); mi->polygon_count++; glEnd(); } /* first render shadows -- no depth required */ if(shadows) { GLfloat m[4][4]; shadowmatrix(m, ground, position0); glColor4fv(MaterialShadow); glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialShadow); glDisable(GL_BLEND); glDisable(GL_LIGHTING); /* display ant shadow */ glPushMatrix(); glTranslatef(0.0, 0.001, 0.0); glMultMatrixf(m[0]); for(i = 0; i < ANTCOUNT; ++i) { /* draw ant */ glPushMatrix(); /* center */ glRotatef(antposition[i], 0.0, 1.0, 0.0); glTranslatef(2.4, 0.0, 0.0); glTranslatef(0.0, antsphere[i], 0.0); glRotatef(90.0, 0.0, 1.0, 0.0); /* orient ant */ glRotatef(10.0, 0.0, 1.0, 0.0); glRotatef(40.0, 0.0, 0.0, 1.0); glTranslatef(0.0, -0.8, 0.0); glRotatef(180.0, 0.0, 1.0, 0.0); glRotatef(90.0, 0.0, 0.0, 1.0); /* set colour */ glColor4fv(MaterialShadow); glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialShadow); if(antposition[i] > 360.0) antposition[i] = 0.0; draw_antinspect_ant(mi, mp, MaterialShadow, mono, mySphere2, myCone2); glDisable(GL_BLEND); glDisable(GL_LIGHTING); /* draw sphere */ glRotatef(-20.0, 1.0, 0.0, 0.0); glRotatef(-mp->ant_step*2, 0.0, 0.0, 1.0); glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialShadow); mySphere2(1.2); glPopMatrix(); } glPopMatrix(); } glEnable(GL_LIGHTING); /* truants */ for(j = 0; j < ANTCOUNT; ++j) { /* determine rendering order */ i = antorder[ro][j]; glPushMatrix(); /* center */ glRotatef(antposition[i], 0.0, 1.0, 0.0); glTranslatef(2.4, 0.0, 0.0); glTranslatef(0.0, antsphere[i], 0.0); glRotatef(90.0, 0.0, 1.0, 0.0); /* draw ant */ glPushMatrix(); glRotatef(10.0, 0.0, 1.0, 0.0); glRotatef(40.0, 0.0, 0.0, 1.0); glTranslatef(0.0, -0.8, 0.0); glRotatef(180.0, 0.0, 1.0, 0.0); glRotatef(90.0, 0.0, 0.0, 1.0); if(antposition[i] > 360.0) antposition[i] = 0.0; glEnable(GL_BLEND); draw_antinspect_ant(mi, mp, antmaterial[i], mono, mySphere2, myCone2); glDisable(GL_BLEND); glPopMatrix(); /* draw sphere */ glRotatef(-20.0, 1.0, 0.0, 0.0); glRotatef(-mp->ant_step*2, 0.0, 0.0, 1.0); glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, mono ? MaterialGray5 : antmaterial[i]); mySphere2(1.2); glEnable(GL_BLEND); glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialBlack); mySphere(1.16); glDisable(GL_BLEND); glPopMatrix(); /* finally, evolve */ antposition[i] += antvelocity[i]; } /* but the step size is the same! */ mp->ant_step += 0.2; mp->ant_position += 1; return True; }
void SimpleGMap2::cb_redraw() { glDisable(GL_LIGHTING); glLineWidth(1.0f); Algo::Render::GL1::renderTopoGMD2<PFP>(myMap, position, true, true, true, 0.9f, 0.9f, 0.9f); }
void tile_set_draw_tile(struct tile_set *ts, struct tile_texture *tt) { if (!tt->texture_valid) { glGenTextures( 1, &tt->texture_id ); tt->texture_valid = 1; glPixelTransferi(GL_INDEX_SHIFT, 0); glPixelTransferi(GL_INDEX_OFFSET, 0); glPixelTransferi(GL_MAP_COLOR, GL_TRUE); uint8_t *data = (uint8_t*) malloc(tt->tile->width * tt->tile->height); gridmap_decode_base(data, tt->tile->width, tt->tile->height, tt->tile->data, tt->tile->datalen); glPixelStorei (GL_UNPACK_ROW_LENGTH, tt->tile->width); glPixelStorei (GL_UNPACK_ALIGNMENT, 1); glBindTexture (GL_TEXTURE_2D, tt->texture_id); glTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA8, tt->tile->width, tt->tile->height, 0, GL_COLOR_INDEX, GL_UNSIGNED_BYTE, data); glPixelStorei (GL_UNPACK_ROW_LENGTH, 0); glPixelTransferi(GL_MAP_COLOR, GL_FALSE); glBindTexture (GL_TEXTURE_2D, 0); free(data); } glPushAttrib (GL_ENABLE_BIT); glEnable (GL_BLEND); glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glDisable (GL_DEPTH_TEST); glEnable (GL_TEXTURE_2D); if (ts->r && ts->g && ts->b && ts->a) { glPixelTransferi(GL_INDEX_SHIFT, 0); glPixelTransferi(GL_INDEX_OFFSET, 0); glPixelTransferi(GL_MAP_COLOR, GL_TRUE); glPixelMapfv(GL_PIXEL_MAP_I_TO_R, 256, ts->r); glPixelMapfv(GL_PIXEL_MAP_I_TO_G, 256, ts->g); glPixelMapfv(GL_PIXEL_MAP_I_TO_B, 256, ts->b); glPixelMapfv(GL_PIXEL_MAP_I_TO_A, 256, ts->a); } glPixelStorei (GL_UNPACK_ROW_LENGTH, tt->tile->width); glPixelStorei (GL_UNPACK_ALIGNMENT, 1); glBindTexture (GL_TEXTURE_2D, tt->texture_id); glPixelStorei (GL_UNPACK_ROW_LENGTH, 0); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); double x0 = tt->tile->x0; double x1 = tt->tile->x0 + tt->tile->width * tt->tile->meters_per_pixel; double y0 = tt->tile->y0; double y1 = tt->tile->y0 + tt->tile->height * tt->tile->meters_per_pixel; int d = 1; glBegin (GL_QUADS); glTexCoord2i (0,0); glVertex2d (x0, y0); glTexCoord2i (0, d); glVertex2d (x0, y1); glTexCoord2i (d, d); glVertex2d (x1, y1); glTexCoord2i (d, 0); glVertex2d (x1, y0); glEnd (); glPixelTransferi(GL_MAP_COLOR, GL_FALSE); glBindTexture (GL_TEXTURE_2D, 0); glPopAttrib (); }
/** * CPaint() is used to render "all the small things". All children are * properly rendered here, with calls to SetScissor() and then to Paint(), * and although the call to SetScissor() might be unnecessary it's always * good to do things twice if you're not certain. After that Paint() of each * object is called. * * So, we have a loop that goes through the objects vector/list, then calls for * each object the SetScissor() and then Paint(). * * Prior to rendering, however, the delayedremove vector is checked out * and all objects requested are removed. * * This f. is used within Paint(); actually there should be no reason for this * function to be used except internally when writing a widget. You may be * more interested in the Paint() method. * * \sa Paint() */ void glictContainer::CPaint() { //printf("Rendering %s (child of %s)\n", objtype, parent ? parent->objtype : "NULL"); DelayedRemove(); #if 0 // below is debug code ... glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); if (glictGlobals.clippingMode==GLICT_SCISSORTEST) glDisable(GL_SCISSOR_TEST); if (glictGlobals.clippingMode==GLICT_STENCILTEST) glDisable(GL_STENCIL_TEST); glBegin(GL_LINES); glColor3f(1.0,0.0,0.0); glVertex2f(this->clipleft,this->clipbottom); glVertex2f(this->clipleft,this->cliptop); glColor3f(0.0,1.0,0.0); glVertex2f(this->clipright,this->clipbottom); glVertex2f(this->clipleft,this->clipbottom); glColor3f(0.0,0.0,1.0); glVertex2f(this->clipright,this->cliptop); glVertex2f(this->clipright,this->clipbottom); glColor3f(1.0,1.0,0.0); glVertex2f(this->clipleft,this->cliptop); glVertex2f(this->clipright,this->cliptop); glEnd(); if (glictGlobals.clippingMode==GLICT_SCISSORTEST) glEnable(GL_SCISSOR_TEST); if (glictGlobals.clippingMode==GLICT_STENCILTEST) glEnable(GL_STENCIL_TEST); glPopMatrix(); #endif if (objects.size()) { glictGlobals.Translatef(this->x + containeroffsetx - virtualpos.x, this->y + containeroffsety - virtualpos.y,0.0); std::vector<glictContainer*>::iterator it; for (it=objects.begin(); it!=objects.end(); it++) { if (!glictGlobals.drawPartialOut) { if ((*it)->GetX()+(*it)->GetWidth() > virtualpos.x + GetWidth()) continue; if ((*it)->GetY()+(*it)->GetHeight() > virtualpos.y + GetHeight()) continue; if ((*it)->GetX() < virtualpos.x ) continue; if ((*it)->GetY() < virtualpos.y ) continue; } if ((*it)->clipbottom <= (*it)->cliptop || (*it)->clipright <= (*it)->clipleft) continue; (*it)->SetScissor(); (*it)->Paint(); } glictGlobals.Translatef(-this->x - containeroffsetx + virtualpos.x, -this->y - containeroffsety + virtualpos.y,0.0); } }
Disable::Disable(GLenum flag) : flag(flag) { state = glIsEnabled(flag); if(state) glDisable(flag); }
bool OglUBitMapMC(int x, int y,grsBitmap *bm,int c) { GLint curFunc; GLdouble xo,yo,xf,yf; GLdouble u1,u2,v1,v2; r_ubitmapc++; x+=grdCurCanv->cvBitmap.bmProps.x; y+=grdCurCanv->cvBitmap.bmProps.y; xo=x/(double)last_width; xf=(bm->bmProps.w+x)/(double)last_width; yo=1.0-y/(double)last_height; yf=1.0-(bm->bmProps.h+y)/(double)last_height; glActiveTextureARB(GL_TEXTURE0); OglBindBmTex(bm); OglTexWrap(bm->glTexture,GL_CLAMP); glEnable(GL_TEXTURE_2D); glGetIntegerv (GL_DEPTH_FUNC, &curFunc); glDepthFunc(GL_ALWAYS); glEnable (GL_ALPHA_TEST); glEnable (GL_BLEND); glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); if (bm->bmProps.x==0) { u1=0; if (bm->bmProps.w==bm->glTexture->w) u2=bm->glTexture->u; else u2=(bm->bmProps.w+bm->bmProps.x)/(double)bm->glTexture->tw; } else { u1=bm->bmProps.x/(double)bm->glTexture->tw; u2=(bm->bmProps.w+bm->bmProps.x)/(double)bm->glTexture->tw; } if (bm->bmProps.y==0) { v1=0; if (bm->bmProps.h==bm->glTexture->h) v2=bm->glTexture->v; else v2=(bm->bmProps.h+bm->bmProps.y)/(double)bm->glTexture->th; } else{ v1=bm->bmProps.y/(double)bm->glTexture->th; v2=(bm->bmProps.h+bm->bmProps.y)/(double)bm->glTexture->th; } glBegin(GL_QUADS); if (c < 0) glColor3d (1.0,1.0,1.0); else glColor3d (CPAL2Tr (bmP->bmPalette, c), CPAL2Tg (bmP->bmPalette, c), CPAL2Tb (bmP->bmPalette, c)); glTexCoord2f (u1, v1); glVertex2d (xo, yo); glTexCoord2f (u2, v1); glVertex2d (xf, yo); glTexCoord2f (u2, v2); glVertex2d (xf, yf); glTexCoord2f (u1, v2); glVertex2d (xo, yf); glEnd(); glDepthFunc(curFunc); glDisable (GL_ALPHA_TEST); glDisable (GL_BLEND); glActiveTextureARB(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D,0); glDisable(GL_TEXTURE_2D); return 0; }
void CCanvasContext::stroke() { int pointCount = 0; int lineSegCount = 0; for( vector< vector<CGPoint> >::const_iterator it = m_lines.begin(); it != m_lines.end(); it++ ) { pointCount += it->size(); if( it->size() >= 2 ) { lineSegCount += (it->size() - 1); } } if( pointCount <= 0 ) { return; } cleanDrawImage(); glColor4f(m_strokeStyleColor.r, m_strokeStyleColor.g, m_strokeStyleColor.b, globalAlpha); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_BLEND); glEnableClientState(GL_VERTEX_ARRAY); bool bSqureCap = false; float originPointSize = 1; glGetFloatv(GL_POINT_SIZE, &originPointSize); int pointVertexCount = pointCount; int lineVertexCount = lineSegCount * 6 - 2; GLfloat * pointVertices = (GLfloat *)malloc(pointVertexCount * 2 * sizeof(GLfloat)); GLfloat * vertices = (GLfloat *)malloc( lineVertexCount * 2 * sizeof(GLfloat)); int pointCursor = 0; int lineCursor = 0; float x1,y1,x2,y2,distant,sina,cosa; float x11,y11,x12,y12,x21,y21,x22,y22; for( vector< vector<CGPoint> >::const_iterator it = m_lines.begin(); it != m_lines.end(); it++ ) { for( int i=0,max=it->size(); i<max; i++ ) { pointVertices[pointCursor++] = it->at(i).x; pointVertices[pointCursor++] = it->at(i).y; if( i == 0 ) { continue; } x1 = pointVertices[pointCursor-4]; y1 = pointVertices[pointCursor-3]; x2 = pointVertices[pointCursor-2]; y2 = pointVertices[pointCursor-1]; distant = sqrtf((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1)); sina = (y2-y1)/distant; cosa = (x2-x1)/distant; // 计算2点直线所组成的矩形的四个顶点 x11 = x1-sina*lineWidth - (bSqureCap ? cosa*lineWidth : 0); y11 = y1+cosa*lineWidth - (bSqureCap ? sina*lineWidth : 0); x12 = x1+sina*lineWidth - (bSqureCap ? cosa*lineWidth : 0); y12 = y1-cosa*lineWidth - (bSqureCap ? sina*lineWidth : 0); x21 = x2-sina*lineWidth + (bSqureCap ? cosa*lineWidth : 0); y21 = y2+cosa*lineWidth + (bSqureCap ? sina*lineWidth : 0); x22 = x2+sina*lineWidth + (bSqureCap ? cosa*lineWidth : 0); y22 = y2-cosa*lineWidth + (bSqureCap ? sina*lineWidth : 0); if( lineCursor != 0 ) { // 增加首尾连接 ABCD DE EFGH vertices[lineCursor++] = vertices[lineCursor-2]; vertices[lineCursor++] = vertices[lineCursor-2]; vertices[lineCursor++] = x11; vertices[lineCursor++] = y11; } vertices[lineCursor++] = x11; vertices[lineCursor++] = y11; vertices[lineCursor++] = x12; vertices[lineCursor++] = y12; vertices[lineCursor++] = x21; vertices[lineCursor++] = y21; vertices[lineCursor++] = x22; vertices[lineCursor++] = y22; } } glVertexPointer(2, GL_FLOAT, 0, vertices); glDrawArrays(GL_TRIANGLE_STRIP, 0, lineVertexCount); glPointSize(lineWidth * 2); glEnable(GL_POINT_SMOOTH); glVertexPointer(2, GL_FLOAT, 0, pointVertices); glDrawArrays(GL_POINTS, 0, pointVertexCount); free(pointVertices); free(vertices); glPointSize(originPointSize); glColor4f(1.0, 1.0, 1.0, 1.0); glDisable(GL_BLEND); }
Enable::~Enable() { if(!state) glDisable(flag); }
void CCanvasContext::drawImageBatch(CImage *image, const vector<float> &coords) { //LOG("drawImageBatch: %d", coords.size()); int count = (int)(coords.size() / 8); if( !image || count <= 0 ) return; //glPushMatrix(); glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, image->getTexture()); if( image->hasAlpha() ) { glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_BLEND); } else { glDisable(GL_BLEND); } glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY); int vertexCount = count * 6; static int maxVertex = 100; static GLfloat *vertices = NULL; static GLfloat *textureCoords = NULL; if( !vertices ) { vertices = (GLfloat *) malloc(maxVertex * 2 * sizeof(GLfloat)); } if( !textureCoords ) { textureCoords = (GLfloat *) malloc(maxVertex * 2 * sizeof(GLfloat)); } if( vertexCount > maxVertex ) { int newMaxVertex = maxVertex * 2; if( vertexCount > newMaxVertex ) { newMaxVertex = vertexCount; } GLfloat *newVertexBuf = (GLfloat *) malloc(newMaxVertex * 2 * sizeof(GLfloat)); GLfloat *newTextureCoordBuf = (GLfloat *) malloc(newMaxVertex * 2 * sizeof(GLfloat)); free(vertices); free(textureCoords); vertices = newVertexBuf; textureCoords = newTextureCoordBuf; maxVertex = newMaxVertex; } for( int i=0; i<count; i++ ) { float sx = coords[i*8]; float sy = coords[i*8+1]; float sw = coords[i*8+2]; float sh = coords[i*8+3]; float dx = coords[i*8+4]; float dy = coords[i*8+5]; float dw = coords[i*8+6]; float dh = coords[i*8+7]; // 6个点的订单坐标,其中2,3点和4,5点相同 vertices[i*12] = dx; vertices[i*12+1] = dy; vertices[i*12+2] = dx + dw; vertices[i*12+3] = dy; vertices[i*12+4] = dx; vertices[i*12+5] = dy + dh; vertices[i*12+6] = dx + dw; vertices[i*12+7] = dy; vertices[i*12+8] = dx; vertices[i*12+9] = dy + dh; vertices[i*12+10] = dx + dw; vertices[i*12+11] = dy + dh; // 6个点的纹理坐标,其中2,3点和4,5点相同 unsigned long POTWidth = image->POTWidth(); unsigned long POTHeight = image->POTHeight(); textureCoords[i*12] = sx / POTWidth; textureCoords[i*12+1] = sy / POTHeight; textureCoords[i*12+2] = (sx + sw) / POTWidth; textureCoords[i*12+3] = sy / POTHeight; textureCoords[i*12+4] = sx / POTWidth; textureCoords[i*12+5] = (sy + sh) / POTHeight; textureCoords[i*12+6] = (sx + sw) / POTWidth; textureCoords[i*12+7] = sy / POTHeight; textureCoords[i*12+8] = sx / POTWidth; textureCoords[i*12+9] = (sy + sh) / POTHeight; textureCoords[i*12+10] = (sx + sw) / POTWidth; textureCoords[i*12+11] = (sy + sh) / POTHeight; } glVertexPointer(2, GL_FLOAT, 0, vertices); glTexCoordPointer(2, GL_FLOAT, 0, textureCoords); glDrawArrays(GL_TRIANGLES, 0, vertexCount); //free(vertices); //free(textureCoords); glDisable(GL_VERTEX_ARRAY); glDisable(GL_TEXTURE_COORD_ARRAY); glDisable(GL_TEXTURE_2D); glDisable(GL_BLEND); //glPopMatrix(); }
// selfDraw draws in 3D using the default ofEasyCamera // you can change the camera by returning getCameraRef() void CloudsVisualSystem3DModelLoader::selfDraw() { //???: update... for some reason the selfUpdate is being called in stand alone. // bLeftCamIsActive = bFrontCamIsActive = bPlanCamIsActive = bPerspCamIsActive = false; glDisable(GL_CULL_FACE); if( cursorIsOverGUI() ) { leftCam.disableMouseInput(); planCam.disableMouseInput(); frontCam.disableMouseInput(); perspCam.disableMouseInput(); } else { if( bLeftCamIsActive && !leftCam.getMouseInputEnabled()) leftCam.enableMouseInput(); if( bFrontCamIsActive && !frontCam.getMouseInputEnabled()) frontCam.enableMouseInput(); if( bPlanCamIsActive && !planCam.getMouseInputEnabled()) planCam.enableMouseInput(); if( bPerspCamIsActive && !perspCam.getMouseInputEnabled()) perspCam.enableMouseInput(); } updateModelTransform(); aimMultipleViews( modelTransform.getPosition() ); //draw from single view if( bFourView ) { //MA: changed ofGetWidth() to GetCanvasWidth() and ofGetHeight() to GetCanvasHeight() int hw = getCanvasWidth()/2; int hh = getCanvasHeight()/2; drawSceneLeft( ofRectangle(0,0,hw,hh) ); drawSceneFront( ofRectangle(hw,0,hw,hh) ); drawScenePlan( ofRectangle(0,hh,hw,hh) ); drawScenePerspective( ofRectangle(hw,hh,hw,hh) ); } else if(currentSingleCam == &perspCam) { drawScenePerspective( ofGetCurrentViewport() ); } else if(currentSingleCam == &leftCam) { drawSceneLeft(); } else if(currentSingleCam == &frontCam) { drawSceneFront(); } else if(currentSingleCam == &planCam) { drawScenePlan(); } else if(currentSingleCam == &pathCamera) { if(bUseDuration) pathCamera.update(); else pathCamera.update( pathCameraPosition ); drawSceneCamera( &pathCamera ); } }
void CloudsVisualSystem3DModelLoader::drawSceneGeometry( ofCamera* cam) { //rotation velocity float t = ofGetElapsedTimef(); accumulatedRotation += globalRotationVelocity * 1. / ofGetFrameRate(); //draw infinite grid by positioning it infront of the camera if(bDrawGrid) { // ofVec3f camPos; // camPos = cam->getPosition(); // camPos += cam->getUpDir().cross(cam->getSideDir()).normalize() * gridDim * gridScale * .5; ofSetColor(255,255, 255, 150 );// make this an adjustable color in th GUI gridShader.begin(); gridShader.setUniform1f("halfGridDim", gridDim * .5 ); gridShader.setUniform1f("falloffDist", fogFalloffDistance ); gridShader.setUniform1f("falloffExpo", fogFalloffExpo ); gridShader.setUniform1f("falloffScl", fogFalloffScale ); gridShader.setUniform1f("alphaScale", gridAlphaScale ); //draw minor grid ofPushMatrix(); ofScale( gridScale, gridScale, gridScale ); ofSetLineWidth( gridLineWidth ); ofSetColor( gridColor.r*gridBrightness, gridColor.g*gridBrightness, gridColor.b*gridBrightness, gridAlpha ); grid.draw(GL_LINES, 0, numGridVertices ); ofPopMatrix(); //draw major grid ofPushMatrix(); int gms = gridMajorScale; ofTranslate( getCameraRef().getLookAtDir() * -gridLineWidth / gridScale ); ofScale( gridScale * gms,gridScale * gms, gridScale * gms ); ofSetLineWidth( majorGridLineWidth ); ofSetColor( gridMajorColor.r*gridMajorBrightness, gridMajorColor.g*gridMajorBrightness, gridMajorColor.b*gridMajorBrightness, gridMajorAlpha ); grid.draw(GL_LINES, 0, numGridVertices ); ofPopMatrix(); gridShader.end(); } //draw wireframe view cameras to the scene if(bDrawCameras) { drawMultipleViewCameras( cameraLineScale, cam ); } if(bDrawArrows) { //draw arrows at model's min bound ofPushMatrix(); ofTranslate( minBound * modelTransform.getGlobalTransformMatrix() ); ofMultMatrix( modelTransform.getGlobalOrientation() ); ofSetColor(0, 255, 0); ofPushMatrix(); ofScale( arrowScale.x, arrowScale.y, arrowScale.z ); arrowMesh.draw(); ofPopMatrix(); ofSetColor(255, 0, 0); ofPushMatrix(); ofRotate(90, 1, 0, 0); ofScale( arrowScale.x, arrowScale.y, arrowScale.z ); arrowMesh.draw(); ofPopMatrix(); ofSetColor(0, 0, 255); ofPushMatrix(); ofRotate(90, 1, 0, 0); ofRotate(90, 0, 0, -1); ofScale( arrowScale.x, arrowScale.y, arrowScale.z ); arrowMesh.draw(); ofPopMatrix(); ofPopMatrix(); } //draw our model ofPushMatrix(); // ofTranslate(-boundCenter); ofMultMatrix( modelTransform.getGlobalTransformMatrix() ); if(currentSingleCam != &pathCamera) { ofTranslate( positionOffset - boundCenter ); ofRotateX( globalRotation.x + accumulatedRotation.x ); ofRotateY( globalRotation.y + accumulatedRotation.y ); ofRotateZ( globalRotation.z + accumulatedRotation.z ); } //draw bounding box if(bDrawBoundingBox) { ofSetColor(255, 255, 255, 255); drawBoundingBox(); } if(bDrawCameraPath) { ofSetLineWidth(majorGridLineWidth); simpleShader.begin(); pathCamera.drawPaths(); simpleShader.end(); } ofSetColor(modelColor); if(activeShader != NULL ) { activeShader->begin(); activeShader->setUniform1f( "discardThreshold", discardThreshold ); activeShader->setUniform1f( "specularExpo", specularExpo ); activeShader->setUniform1f( "specularScale", specularScale ); activeShader->setUniform1f("falloffDist", fogFalloffDistance ); activeShader->setUniform1f("falloffExpo", fogFalloffExpo ); activeShader->setUniform1f("falloffScl", fogFalloffScale ); if(activeShader == &XRayShader){ /* sfactor Specifies how the red, green, blue, and alpha source blending factors are computed. The following symbolic constants are accepted: GL_ZERO, GL_ONE, GL_SRC_COLOR, GL_ONE_MINUS_SRC_COLOR, GL_DST_COLOR, GL_ONE_MINUS_DST_COLOR, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_DST_ALPHA, GL_ONE_MINUS_DST_ALPHA, GL_CONSTANT_COLOR, GL_ONE_MINUS_CONSTANT_COLOR, GL_CONSTANT_ALPHA, GL_ONE_MINUS_CONSTANT_ALPHA, and GL_SRC_ALPHA_SATURATE. The initial value is GL_ONE. dfactor Specifies how the red, green, blue, and alpha destination blending factors are computed. The following symbolic constants are accepted: GL_ZERO, GL_ONE, GL_SRC_COLOR, GL_ONE_MINUS_SRC_COLOR, GL_DST_COLOR, GL_ONE_MINUS_DST_COLOR, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_DST_ALPHA, GL_ONE_MINUS_DST_ALPHA. GL_CONSTANT_COLOR, GL_ONE_MINUS_CONSTANT_COLOR, GL_CONSTANT_ALPHA, and GL_ONE_MINUS_CONSTANT_ALPHA. The initial value is GL_ZERO. */ //GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA glDisable( GL_DEPTH_TEST ); glBlendFunc(GL_ONE, GL_ONE); // modelMesh.draw(); bWireframe? modelMesh.drawWireframe() : modelMesh.draw(); ofBlendMode( OF_BLENDMODE_ADD ); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); } else{ if(bWireframe) ofSetLineWidth( wireframeLinewidth ); bWireframe? modelMesh.drawWireframe() : modelMesh.draw(); } activeShader->end(); } ofPopMatrix(); }
void CStatMeshInstance::Draw(unsigned flags) { guard(CStatMeshInstance::Draw); int i; if (!pMesh->Lods.Num()) return; /*const*/ CStaticMeshLod& Mesh = pMesh->Lods[LodNum]; //?? not 'const' because of BuildTangents(); change this? int NumSections = Mesh.Sections.Num(); if (!NumSections || !Mesh.NumVerts) return; // if (!Mesh.HasNormals) Mesh.BuildNormals(); if (!Mesh.HasTangents) Mesh.BuildTangents(); // copy of CSkelMeshInstance::Draw sorting code #if SORT_BY_OPACITY // sort sections by material opacity int SectionMap[MAX_MESHMATERIALS]; int secPlace = 0; for (int opacity = 0; opacity < 2; opacity++) { for (i = 0; i < NumSections; i++) { UUnrealMaterial *Mat = Mesh.Sections[i].Material; int op = 0; // sort value if (Mat && Mat->IsTranslucent()) op = 1; if (op == opacity) SectionMap[secPlace++] = i; } } assert(secPlace == NumSections); #endif // SORT_BY_OPACITY // draw mesh glEnable(GL_LIGHTING); glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glEnableClientState(GL_NORMAL_ARRAY); glVertexPointer(3, GL_FLOAT, sizeof(CStaticMeshVertex), &Mesh.Verts[0].Position); glNormalPointer(GL_BYTE, sizeof(CStaticMeshVertex), &Mesh.Verts[0].Normal); if (UVIndex == 0) { glTexCoordPointer(2, GL_FLOAT, sizeof(CStaticMeshVertex), &Mesh.Verts[0].UV.U); } else { glTexCoordPointer(2, GL_FLOAT, sizeof(CMeshUVFloat), &Mesh.ExtraUV[UVIndex-1][0].U); } /*?? Can move tangent/binormal setup here too, but this will require to force shader to use fixed attribute locations (use glBindAttribLocation before glLinkProgram instead of querying atttribute via glGetAtribLocation). In this case: - can remove GCurrentShader - can eliminate hasTangent checks below and always bind attributes (when supports GL2.0) - can share code between SkeletalMesh and StaticMesh: - sort sections - setup arrays; differences: - position and normals are taken from different arrays in static and skeletal meshes - ShowInfluences in SkeletalMeshInstance should disable material binding - draw sections using glDrawElements() - un-setup arrays - use VAO+VBO for rendering */ for (i = 0; i < NumSections; i++) { #if SORT_BY_OPACITY int MaterialIndex = SectionMap[i]; #else int MaterialIndex = i; #endif const CMeshSection &Sec = Mesh.Sections[MaterialIndex]; if (!Sec.NumFaces) continue; SetMaterial(Sec.Material, MaterialIndex); // check tangent space GLint aNormal = -1; GLint aTangent = -1; // GLint aBinormal = -1; const CShader *Sh = GCurrentShader; if (Sh) { aNormal = Sh->GetAttrib("normal"); aTangent = Sh->GetAttrib("tangent"); // aBinormal = Sh->GetAttrib("binormal"); } if (aNormal >= 0) { glEnableVertexAttribArray(aNormal); // send 4 components to decode binormal in shader glVertexAttribPointer(aNormal, 4, GL_BYTE, GL_FALSE, sizeof(CStaticMeshVertex), &Mesh.Verts[0].Normal); } if (aTangent >= 0) { glEnableVertexAttribArray(aTangent); glVertexAttribPointer(aTangent, 3, GL_BYTE, GL_FALSE, sizeof(CStaticMeshVertex), &Mesh.Verts[0].Tangent); } /* if (aBinormal >= 0) { glEnableVertexAttribArray(aBinormal); glVertexAttribPointer(aBinormal, 3, GL_BYTE, GL_FALSE, sizeof(CStaticMeshVertex), &Mesh.Verts[0].Binormal); } */ // draw //?? place this code into CIndexBuffer? if (Mesh.Indices.Is32Bit()) glDrawElements(GL_TRIANGLES, Sec.NumFaces * 3, GL_UNSIGNED_INT, &Mesh.Indices.Indices32[Sec.FirstIndex]); else glDrawElements(GL_TRIANGLES, Sec.NumFaces * 3, GL_UNSIGNED_SHORT, &Mesh.Indices.Indices16[Sec.FirstIndex]); // disable tangents if (aNormal >= 0) glDisableVertexAttribArray(aNormal); if (aTangent >= 0) glDisableVertexAttribArray(aTangent); // if (aBinormal >= 0) // glDisableVertexAttribArray(aBinormal); } glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_TEXTURE_COORD_ARRAY); glDisableClientState(GL_NORMAL_ARRAY); glDisable(GL_LIGHTING); BindDefaultMaterial(true); // draw mesh normals if (flags & DF_SHOW_NORMALS) { //!! TODO: performance issues when displaying a large mesh (1M+ triangles) with normals/tangents. //!! Possible solution: //!! 1. use vertex buffer for normals, use single draw call //!! 2. cache normal data between render frames //!! 3. DecodeTangents() will do Unpack() for normal and tangent too, so this work is duplicated here int NumVerts = Mesh.NumVerts; glBegin(GL_LINES); glColor3f(0.5, 1, 0); CVecT tmp, unpacked; const float VisualLength = 2.0f; for (i = 0; i < NumVerts; i++) { glVertex3fv(Mesh.Verts[i].Position.v); Unpack(unpacked, Mesh.Verts[i].Normal); VectorMA(Mesh.Verts[i].Position, VisualLength, unpacked, tmp); glVertex3fv(tmp.v); } #if SHOW_TANGENTS glColor3f(0, 0.5f, 1); for (i = 0; i < NumVerts; i++) { const CVec3 &v = Mesh.Verts[i].Position; glVertex3fv(v.v); Unpack(unpacked, Mesh.Verts[i].Tangent); VectorMA(v, VisualLength, unpacked, tmp); glVertex3fv(tmp.v); } glColor3f(1, 0, 0.5f); for (i = 0; i < NumVerts; i++) { const CMeshVertex& vert = Mesh.Verts[i]; // decode binormal CVecT normal, tangent, binormal; vert.DecodeTangents(normal, tangent, binormal); // render const CVecT &v = vert.Position; glVertex3fv(v.v); VectorMA(v, VisualLength, binormal, tmp); glVertex3fv(tmp.v); } #endif // SHOW_TANGENTS glEnd(); } unguard; }
bool fpDrawTexPolyMulti ( int nv, g3sPoint **pointlist, tUVL *uvl_list, grsBitmap *bmbot, grsBitmap *bm, int orient) { bool lightmapping=0; int c; g3sPoint *p, **pp; GLint depthFunc; glGetIntegerv (GL_DEPTH_FUNC, &depthFunc); glDepthFunc(GL_LEQUAL); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); r_tpolyc++; if (lightmapping) {//lightmapping enabled glActiveTextureARB(GL_TEXTURE0); glEnable(GL_TEXTURE_2D); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, GL_RGBA); OglBindBmTex(bmbot); if (bm) { glActiveTextureARB(GL_TEXTURE1); glEnable(GL_TEXTURE_2D); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL ); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, GL_RGBA); OglBindBmTex(bm); } glBegin(GL_TRIANGLE_FAN); pp = pointlist; cap_tmap_color (uvl_list, nv, bmbot); for (c = 0; c < nv; c++, pp++) { set_tmap_color (uvl_list + c,c, bmbot); glTexCoord2f (f2glf(uvl_list[c].u),f2glf(uvl_list[c].v)); set_texcoord (uvl_list + c, orient, 1); glColor3d (1, 1, 1); p = *pp; glVertex3d (f2glf(p->p3_vec.x), f2glf(p->p3_vec.y), f2glf(p->p3_vec.z)); } glEnd(); glActiveTextureARB(GL_TEXTURE1); glBindTexture(GL_TEXTURE_2D,0); glDisable(GL_TEXTURE_2D); glActiveTextureARB(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D,0); glDisable(GL_TEXTURE_2D); } else {//lightmapping disabled - render old way g3sPoint *p; if (tmap_drawer_ptr==DrawTexPolyFlat){ glActiveTextureARB(GL_TEXTURE0); glDisable (GL_TEXTURE_2D); glColor4d(0,0,0,1.0-(gameStates.render.grAlpha/(double)NUM_LIGHTING_LEVELS)); glBegin(GL_TRIANGLE_FAN); for (c = 0; c < nv; c++, pointlist++) { p = *pointlist; glVertex3d (f2glf(p->p3_vec.x), f2glf(p->p3_vec.y), f2glf(p->p3_vec.z)); } glEnd(); pointlist=pointlist-4; } else if (tmap_drawer_ptr == draw_tmap) { r_tpolyc++; glActiveTextureARB(GL_TEXTURE0); OGL_ENABLE(TEXTURE_2D); OglBindBmTex(bmbot); OglTexWrap(bmbot->glTexture,GL_REPEAT); cap_tmap_color (uvl_list, nv, bmbot); glBegin(GL_TRIANGLE_FAN); for (c = 0; c < nv; c++, pointlist++) { set_tmap_color (uvl_list + c, c, bmbot); glTexCoord2d (f2glf(uvl_list[c].u), f2glf(uvl_list[c].v)); p = *pointlist; glVertex3d (f2glf(p->p3_vec.x), f2glf(p->p3_vec.y), f2glf(p->p3_vec.z)); } glEnd(); pointlist=pointlist-4; } else { #if TRACE con_printf (CONDBG,"G3DrawTexPoly: unhandled tmap_drawer %p\n",tmap_drawer_ptr); #endif } tMapColor.index = lightColor.index = 0; //G3DrawTexPoly (nv,pointlist,uvl_list,bmbot);//draw the bottom texture first.. could be optimized with multitexturing.. //then draw the second layer if (bm) { glDepthFunc(GL_LEQUAL); r_tpolyc++; glActiveTextureARB(GL_TEXTURE0); OGL_ENABLE(TEXTURE_2D); OglBindBmTex(bm); OglTexWrap(bm->glTexture,GL_REPEAT); cap_tmap_color (uvl_list, nv, bm); glBegin(GL_TRIANGLE_FAN); for (c = 0; c < nv; c++, pointlist++) { set_tmap_color (uvl_list + c, c, bm); set_texcoord (uvl_list + c, orient, 0); p = *pointlist; glVertex3d (f2glf(p->p3_vec.x), f2glf(p->p3_vec.y), f2glf(p->p3_vec.z)); } glEnd(); glDepthFunc(GL_LESS); } //glActiveTextureARB(GL_TEXTURE0); //glBindTexture(GL_TEXTURE_2D,0); //glDisable(GL_TEXTURE_2D); } return 0; }
void R_DrawParticles (void) { particle_t *p, *kill; float grav; int i; float time2, time3; float time1; float dvel; float frametime; #ifdef GLQUAKE vec3_t up, right; float scale; GL_Use (gl_coloredpolygon1textureprogram); glUniformMatrix4fv(gl_coloredpolygon1textureprogram_transform, 1, 0, gl_polygon_matrix); GL_Bind(particletexture); glEnable (GL_BLEND); VectorScale (vup, 1.5, up); VectorScale (vright, 1.5, right); #else D_StartParticles (); VectorScale (vright, xscaleshrink, r_pright); VectorScale (vup, yscaleshrink, r_pup); VectorCopy (vpn, r_ppn); #endif frametime = cl.time - cl.oldtime; time3 = frametime * 15; time2 = frametime * 10; // 15; time1 = frametime * 5; grav = frametime * sv_gravity.value * 0.05; dvel = 4*frametime; for ( ;; ) { kill = active_particles; if (kill && kill->die < cl.time) { active_particles = kill->next; kill->next = free_particles; free_particles = kill; continue; } break; } #ifdef GLQUAKE int mark = Hunk_LowMark(); int vertexcount = 0; for (p=active_particles ; p ; p=p->next) { vertexcount += 3; } if (vertexcount == 0) return; GLfloat* vertices = Hunk_AllocName (vertexcount * 9 * sizeof(GLfloat), "vertex_buffer"); int vertexpos = 0; #endif for (p=active_particles ; p ; p=p->next) { for ( ;; ) { kill = p->next; if (kill && kill->die < cl.time) { p->next = kill->next; kill->next = free_particles; free_particles = kill; continue; } break; } #ifdef GLQUAKE // hack a scale up to keep particles from disapearing scale = (p->org[0] - r_origin[0])*vpn[0] + (p->org[1] - r_origin[1])*vpn[1] + (p->org[2] - r_origin[2])*vpn[2]; if (scale < 20) scale = 1; else scale = 1 + scale * 0.004; unsigned c = d_8to24table[(int)p->color]; GLfloat r = (GLfloat)(c & 0xFF) / 255.0; GLfloat g = (GLfloat)((c >> 8) & 0xFF) / 255.0; GLfloat b = (GLfloat)((c >> 16) & 0xFF) / 255.0; GLfloat a = (GLfloat)((c >> 24) & 0xFF) / 255.0; vertices[vertexpos++] = p->org[0]; vertices[vertexpos++] = p->org[1]; vertices[vertexpos++] = p->org[2]; vertices[vertexpos++] = r; vertices[vertexpos++] = g; vertices[vertexpos++] = b; vertices[vertexpos++] = a; vertices[vertexpos++] = 0.0; vertices[vertexpos++] = 0.0; vertices[vertexpos++] = p->org[0] + up[0] * scale; vertices[vertexpos++] = p->org[1] + up[1] * scale; vertices[vertexpos++] = p->org[2] + up[2] * scale; vertices[vertexpos++] = r; vertices[vertexpos++] = g; vertices[vertexpos++] = b; vertices[vertexpos++] = a; vertices[vertexpos++] = 1.0; vertices[vertexpos++] = 0.0; vertices[vertexpos++] = p->org[0] + right[0] * scale; vertices[vertexpos++] = p->org[1] + right[1] * scale; vertices[vertexpos++] = p->org[2] + right[2] * scale; vertices[vertexpos++] = r; vertices[vertexpos++] = g; vertices[vertexpos++] = b; vertices[vertexpos++] = a; vertices[vertexpos++] = 0.0; vertices[vertexpos++] = 1.0; #else D_DrawParticle (p); #endif p->org[0] += p->vel[0]*frametime; p->org[1] += p->vel[1]*frametime; p->org[2] += p->vel[2]*frametime; switch (p->type) { case pt_static: break; case pt_fire: p->ramp += time1; if (p->ramp >= 6) p->die = -1; else p->color = ramp3[(int)p->ramp]; p->vel[2] += grav; break; case pt_explode: p->ramp += time2; if (p->ramp >=8) p->die = -1; else p->color = ramp1[(int)p->ramp]; for (i=0 ; i<3 ; i++) p->vel[i] += p->vel[i]*dvel; p->vel[2] -= grav; break; case pt_explode2: p->ramp += time3; if (p->ramp >=8) p->die = -1; else p->color = ramp2[(int)p->ramp]; for (i=0 ; i<3 ; i++) p->vel[i] -= p->vel[i]*frametime; p->vel[2] -= grav; break; case pt_blob: for (i=0 ; i<3 ; i++) p->vel[i] += p->vel[i]*dvel; p->vel[2] -= grav; break; case pt_blob2: for (i=0 ; i<2 ; i++) p->vel[i] -= p->vel[i]*dvel; p->vel[2] -= grav; break; case pt_grav: #ifdef QUAKE2 p->vel[2] -= grav * 20; break; #endif case pt_slowgrav: p->vel[2] -= grav; break; } } #ifdef GLQUAKE GLuint vertexbuffer; glGenBuffers(1, &vertexbuffer); glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer); glBufferData(GL_ARRAY_BUFFER, vertexcount * 9 * sizeof(GLfloat), vertices, GL_STATIC_DRAW); glEnableVertexAttribArray(gl_coloredpolygon1textureprogram_position); glVertexAttribPointer(gl_coloredpolygon1textureprogram_position, 3, GL_FLOAT, GL_FALSE, 9 * sizeof(GLfloat), (const GLvoid *)0); glEnableVertexAttribArray(gl_coloredpolygon1textureprogram_color); glVertexAttribPointer(gl_coloredpolygon1textureprogram_color, 4, GL_FLOAT, GL_FALSE, 9 * sizeof(GLfloat), (const GLvoid *)(3 * sizeof(GLfloat))); glEnableVertexAttribArray(gl_coloredpolygon1textureprogram_texcoords); glVertexAttribPointer(gl_coloredpolygon1textureprogram_texcoords, 2, GL_FLOAT, GL_FALSE, 9 * sizeof(GLfloat), (const GLvoid *)(7 * sizeof(GLfloat))); glDrawArrays(GL_TRIANGLES, 0, vertexcount); glDisableVertexAttribArray(gl_coloredpolygon1textureprogram_texcoords); glDisableVertexAttribArray(gl_coloredpolygon1textureprogram_color); glDisableVertexAttribArray(gl_coloredpolygon1textureprogram_position); glBindBuffer(GL_ARRAY_BUFFER, 0); glDeleteBuffers(1, &vertexbuffer); Hunk_FreeToLowMark (mark); glDisable (GL_BLEND); #else D_EndParticles (); #endif }
void RiftAppSkeleton::display_client() //const { ovrHmd hmd = m_Hmd; if (hmd == NULL) return; //ovrFrameTiming hmdFrameTiming = ovrHmd_BeginFrameTiming(hmd, 0); bindFBO(m_renderBuffer, m_fboScale); glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); for (int eyeIndex = 0; eyeIndex < ovrEye_Count; eyeIndex++) { const ovrEyeType eye = hmd->EyeRenderOrder[eyeIndex]; const ovrPosef eyePose = ovrHmd_GetEyePose(hmd, eye); m_eyeOri = eyePose.Orientation; // cache this for movement direction _StoreHmdPose(eyePose); const ovrGLTexture& otex = l_EyeTexture[eye]; const ovrRecti& rvp = otex.OGL.Header.RenderViewport; const ovrRecti rsc = { static_cast<int>(m_fboScale * rvp.Pos.x), static_cast<int>(m_fboScale * rvp.Pos.y), static_cast<int>(m_fboScale * rvp.Size.w), static_cast<int>(m_fboScale * rvp.Size.h) }; glViewport(rsc.Pos.x, rsc.Pos.y, rsc.Size.w, rsc.Size.h); const OVR::Matrix4f proj = ovrMatrix4f_Projection( m_EyeRenderDesc[eye].Fov, 0.01f, 10000.0f, true); ///@todo Should we be using this variable? //m_EyeRenderDesc[eye].DistortedViewport; const OVR::Matrix4f view = _MakeModelviewMatrix( eyePose, m_EyeRenderDesc[eye].ViewAdjust, m_chassisYaw, m_chassisPos); const OVR::Matrix4f scaledView = _MakeModelviewMatrix( eyePose, m_EyeRenderDesc[eye].ViewAdjust, m_chassisYaw, m_chassisPos, m_headSize); _resetGLState(); _DrawScenes(&view.Transposed().M[0][0], &proj.Transposed().M[0][0], rsc, &scaledView.Transposed().M[0][0]); } unbindFBO(); // Set full viewport...? const int w = m_Cfg.OGL.Header.RTSize.w; const int h = m_Cfg.OGL.Header.RTSize.h; glViewport(0, 0, w, h); glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glDisable(GL_DEPTH_TEST); glDisable(GL_CULL_FACE); // Now draw the distortion mesh... for(int eyeNum = 0; eyeNum < 2; eyeNum++) { const ShaderWithVariables& eyeShader = eyeNum == 0 ? m_presentDistMeshL : m_presentDistMeshR; const GLuint prog = eyeShader.prog(); glUseProgram(prog); //glBindVertexArray(eyeShader.m_vao); { const ovrDistortionMesh& mesh = m_DistMeshes[eyeNum]; glBindBuffer(GL_ARRAY_BUFFER, 0); const int a_pos = glGetAttribLocation(prog, "vPosition"); glVertexAttribPointer(a_pos, 4, GL_FLOAT, GL_FALSE, sizeof(ovrDistortionVertex), &mesh.pVertexData[0].ScreenPosNDC.x); glEnableVertexAttribArray(a_pos); const int a_texR = glGetAttribLocation(prog, "vTexR"); if (a_texR > -1) { glVertexAttribPointer(a_texR, 2, GL_FLOAT, GL_FALSE, sizeof(ovrDistortionVertex), &mesh.pVertexData[0].TanEyeAnglesR); glEnableVertexAttribArray(a_texR); } const int a_texG = glGetAttribLocation(prog, "vTexG"); if (a_texG > -1) { glVertexAttribPointer(a_texG, 2, GL_FLOAT, GL_FALSE, sizeof(ovrDistortionVertex), &mesh.pVertexData[0].TanEyeAnglesG); glEnableVertexAttribArray(a_texG); } const int a_texB = glGetAttribLocation(prog, "vTexB"); if (a_texB > -1) { glVertexAttribPointer(a_texB, 2, GL_FLOAT, GL_FALSE, sizeof(ovrDistortionVertex), &mesh.pVertexData[0].TanEyeAnglesB); glEnableVertexAttribArray(a_texB); } ovrVector2f uvoff = m_uvScaleOffsetOut[2*eyeNum + 1]; //DistortionData.UVScaleOffset[eyeNum][0]; ovrVector2f uvscale = m_uvScaleOffsetOut[2*eyeNum + 0]; //DistortionData.UVScaleOffset[eyeNum][1]; glUniform2f(eyeShader.GetUniLoc("EyeToSourceUVOffset"), uvoff.x, uvoff.y); glUniform2f(eyeShader.GetUniLoc("EyeToSourceUVScale"), uvscale.x, uvscale.y); #if 0 // Setup shader constants DistortionData.Shaders->SetUniform2f( "EyeToSourceUVScale", DistortionData.UVScaleOffset[eyeNum][0].x, DistortionData.UVScaleOffset[eyeNum][0].y); DistortionData.Shaders->SetUniform2f( "EyeToSourceUVOffset", DistortionData.UVScaleOffset[eyeNum][1].x, DistortionData.UVScaleOffset[eyeNum][1].y); if (distortionCaps & ovrDistortionCap_TimeWarp) { // TIMEWARP - Additional shader constants required ovrMatrix4f timeWarpMatrices[2]; ovrHmd_GetEyeTimewarpMatrices(HMD, (ovrEyeType)eyeNum, eyeRenderPoses[eyeNum], timeWarpMatrices); //WARNING!!! These matrices are transposed in SetUniform4x4f, before being used by the shader. DistortionData.Shaders->SetUniform4x4f("EyeRotationStart", Matrix4f(timeWarpMatrices[0])); DistortionData.Shaders->SetUniform4x4f("EyeRotationEnd", Matrix4f(timeWarpMatrices[1])); } // Perform distortion pRender->Render( &distortionShaderFill, DistortionData.MeshVBs[eyeNum], DistortionData.MeshIBs[eyeNum]); #endif glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, m_renderBuffer.tex); glUniform1i(eyeShader.GetUniLoc("fboTex"), 0); // This is the only uniform that changes per-frame glUniform1f(eyeShader.GetUniLoc("fboScale"), m_fboScale); glDrawElements( GL_TRIANGLES, mesh.IndexCount, GL_UNSIGNED_SHORT, &mesh.pIndexData[0]); } glBindVertexArray(0); glUseProgram(0); } ovrHmd_EndFrameTiming(hmd); }
void ScaleBarObject::draw(float pixelGLRatio, int screenWidth, int screenHeight, int viewWidth, int viewHeight, bool grabsMouse) { VolumeInformation pvlInfo = VolumeInformation::volumeInformation(); QString str; bool horizontal = m_type; float slen = voxels(); if (pvlInfo.voxelUnit > 0) { float avg = (pvlInfo.voxelSize[0] + pvlInfo.voxelSize[1] + pvlInfo.voxelSize[2])/3.0f; str = QString("%1 %2"). \ arg(slen, 0, 'f', Global::floatPrecision()). \ arg(pvlInfo.voxelUnitStringShort()); slen /= avg; } else str = QString("%1 voxels").arg(slen); slen = slen/pixelGLRatio; Vec s0 = Vec(m_pos.x()*viewWidth, m_pos.y()*viewHeight, 1); Vec s1 = s0; if (horizontal) { slen *= (float)viewWidth/(float)screenWidth; s0 -= Vec(slen/2, 0, 0); s1 += Vec(slen/2, 0, 0); } else { slen *= (float)viewHeight/(float)screenHeight; s0 -= Vec(0, slen/2, 0); s1 += Vec(0, slen/2, 0); } glEnable(GL_BLEND); glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); // back to front glColor4f(0, 0, 0, 0.8f); if (grabsMouse) { glColor4f(0.5f, 0, 0, 0.8f); glBegin(GL_QUADS); if (horizontal) { glVertex2f(s0.x-5, s0.y-10); glVertex2f(s1.x+5, s0.y-10); glVertex2f(s1.x+5, s0.y+10); glVertex2f(s0.x-5, s0.y+10); } else { glVertex2f(s0.x-10, s0.y-5); glVertex2f(s0.x-10, s1.y+5); glVertex2f(s0.x+10, s1.y+5); glVertex2f(s0.x+10, s0.y-5); } glEnd(); } glDisable(GL_BLEND); glColor3f(1,1,1); glLineWidth(10); glBegin(GL_LINES); glVertex3fv(s0); glVertex3fv(s1); glEnd(); glColor3f(0.5,0.5,0.5); glLineWidth(2); glBegin(GL_LINES); if (horizontal) { glVertex2f(s0.x+slen/2, s0.y-3); glVertex2f(s0.x+slen/2, s1.y+3); } else { glVertex2f(s1.x-3, (s1.y+s0.y)/2); glVertex2f(s0.x+3, (s1.y+s0.y)/2); } glEnd(); glColor3f(0,0,0); glLineWidth(2); glBegin(GL_LINES); if (horizontal) { glVertex2f(s0.x+1, s0.y); glVertex2f(s1.x-1, s1.y); } else { glVertex2f(s0.x, s0.y+1); glVertex2f(s1.x, s1.y-1); } glEnd(); glLineWidth(1); glColor3f(1,1,1); { Vec w0 = Vec(m_pos.x()*screenWidth, (1-m_pos.y())*screenHeight,1); Vec w1 = w0; if (horizontal) { w0 -= Vec(slen/2, 0, 0); w1 += Vec(slen/2, 0, 0); } else { w0 -= Vec(0, slen/2, 0); w1 += Vec(0, slen/2, 0); } QFont tfont = QFont("Helvetica", 12); tfont.setStyleStrategy(QFont::PreferAntialias); QFontMetrics metric(tfont); int mde = metric.descent(); int fht = metric.height()+2; int fwd = metric.width(str)+2; QImage bImage = QImage(fwd, fht, QImage::Format_ARGB32); bImage.fill(0); QPainter bpainter(&bImage); Vec bgcolor = Global::backgroundColor(); bpainter.setBackgroundMode(Qt::OpaqueMode); bpainter.setBackground(QColor(bgcolor.z*255, bgcolor.y*255, bgcolor.x*255)); float bgintensity = (0.3*bgcolor.x + 0.5*bgcolor.y + 0.2*bgcolor.z); QColor penColor(Qt::white); if (bgintensity > 0.5) penColor = Qt::black; bpainter.setPen(penColor); bpainter.setFont(tfont); bpainter.drawText(1, fht-mde, str); QImage cImage = bImage.mirrored(); if (!horizontal) { QMatrix matrix; matrix.rotate(90); cImage = cImage.transformed(matrix); } int x,y; if (horizontal) { x = (w0.x+w1.x)/2 - cImage.width()/2; y = w0.y-3-cImage.height(); if (!m_textpos) y = w0.y+6; } else { x = w1.x+3; if (!m_textpos) x = w1.x-5-cImage.width(); y = (w0.y+w1.y)/2 - cImage.height()/2; } glWindowPos2i(x,y); const uchar *bits = cImage.bits(); glDrawPixels(cImage.width(), cImage.height(), GL_RGBA, GL_UNSIGNED_BYTE, bits); } }
///@todo Even though this function shares most of its code with client rendering, /// which appears to work fine, it is non-convergable. It appears that the projection /// matrices for each eye are too far apart? Could be modelview... void RiftAppSkeleton::display_stereo_undistorted() //const { ovrHmd hmd = m_Hmd; if (hmd == NULL) return; //ovrFrameTiming hmdFrameTiming = ovrHmd_BeginFrameTiming(hmd, 0); bindFBO(m_renderBuffer, m_fboScale); glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); for (int eyeIndex = 0; eyeIndex < ovrEye_Count; eyeIndex++) { ovrEyeType eye = hmd->EyeRenderOrder[eyeIndex]; ovrPosef eyePose = ovrHmd_GetEyePose(hmd, eye); const ovrGLTexture& otex = l_EyeTexture[eye]; const ovrRecti& rvp = otex.OGL.Header.RenderViewport; const ovrRecti rsc = { static_cast<int>(m_fboScale * rvp.Pos.x), static_cast<int>(m_fboScale * rvp.Pos.y), static_cast<int>(m_fboScale * rvp.Size.w), static_cast<int>(m_fboScale * rvp.Size.h) }; glViewport(rsc.Pos.x, rsc.Pos.y, rsc.Size.w, rsc.Size.h); OVR::Quatf orientation = OVR::Quatf(eyePose.Orientation); OVR::Matrix4f proj = ovrMatrix4f_Projection( m_EyeRenderDesc[eye].Fov, 0.01f, 10000.0f, true); //m_EyeRenderDesc[eye].DistortedViewport; OVR::Vector3f EyePos = m_chassisPos; OVR::Matrix4f view = OVR::Matrix4f(orientation.Inverted()) * OVR::Matrix4f::RotationY(m_chassisYaw) * OVR::Matrix4f::Translation(-EyePos); OVR::Matrix4f eyeview = OVR::Matrix4f::Translation(m_EyeRenderDesc[eye].ViewAdjust) * view; _resetGLState(); _DrawScenes(&eyeview.Transposed().M[0][0], &proj.Transposed().M[0][0], rvp); } unbindFBO(); glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glDisable(GL_DEPTH_TEST); glDisable(GL_CULL_FACE); // Present FBO to screen const GLuint prog = m_presentFbo.prog(); glUseProgram(prog); m_presentFbo.bindVAO(); { glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, m_renderBuffer.tex); glUniform1i(m_presentFbo.GetUniLoc("fboTex"), 0); // This is the only uniform that changes per-frame glUniform1f(m_presentFbo.GetUniLoc("fboScale"), m_fboScale); glDrawArrays(GL_TRIANGLE_FAN, 0, 4); } glBindVertexArray(0); glUseProgram(0); ovrHmd_EndFrameTiming(hmd); }
/* draw an ant */ static Bool draw_antinspect_ant(ModeInfo *mi, antinspectstruct * mp, const float *Material, int mono, Bool (*sphere)(float), Bool (*cone)(float)) { float cos1 = cos(mp->ant_step); float cos2 = cos(mp->ant_step + 2 * Pi / 3); float cos3 = cos(mp->ant_step + 4 * Pi / 3); float sin1 = sin(mp->ant_step); float sin2 = sin(mp->ant_step + 2 * Pi / 3); float sin3 = sin(mp->ant_step + 4 * Pi / 3); if (mono) glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialGray5); else glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, Material); glEnable(GL_CULL_FACE); glPushMatrix(); glScalef(1, 1.3, 1); if (!((*sphere)(0.18))) return False; glScalef(1, 1 / 1.3, 1); glTranslatef(0.00, 0.30, 0.00); if (!((*sphere)(0.2))) return False; glTranslatef(-0.05, 0.17, 0.05); glRotatef(-90, 1, 0, 0); glRotatef(-25, 0, 1, 0); if (!((*cone)(0.05))) return False; glTranslatef(0.00, 0.10, 0.00); if (!((*cone)(0.05))) return False; glRotatef(25, 0, 1, 0); glRotatef(90, 1, 0, 0); glScalef(1, 1.3, 1); glTranslatef(0.15, -0.65, 0.05); if (!((*sphere)(0.25))) return False; glScalef(1, 1 / 1.3, 1); glPopMatrix(); glDisable(GL_CULL_FACE); glDisable(GL_LIGHTING); /* ANTENNAS */ glBegin(GL_LINES); if (mono) glColor3fv(MaterialGray5); else glColor3fv(Material); glVertex3f(0.00, 0.30, 0.00); glColor3fv(MaterialGray); glVertex3f(0.40, 0.70, 0.40); mi->polygon_count++; if (mono) glColor3fv(MaterialGray5); else glColor3fv(Material); glVertex3f(0.00, 0.30, 0.00); glColor3fv(MaterialGray); glVertex3f(0.40, 0.70, -0.40); mi->polygon_count++; glEnd(); glBegin(GL_POINTS); if (mono) glColor3fv(MaterialGray6); else glColor3fv(Material); glVertex3f(0.40, 0.70, 0.40); mi->polygon_count++; glVertex3f(0.40, 0.70, -0.40); mi->polygon_count++; glEnd(); /* LEFT-FRONT ARM */ glBegin(GL_LINE_STRIP); if (mono) glColor3fv(MaterialGray5); else glColor3fv(Material); glVertex3f(0.00, 0.05, 0.18); glVertex3f(0.35 + 0.05 * cos1, 0.15, 0.25); mi->polygon_count++; glColor3fv(MaterialGray); glVertex3f(-0.20 + 0.05 * cos1, 0.25 + 0.1 * sin1, 0.45); mi->polygon_count++; glEnd(); /* LEFT-CENTER ARM */ glBegin(GL_LINE_STRIP); if (mono) glColor3fv(MaterialGray5); else glColor3fv(Material); glVertex3f(0.00, 0.00, 0.18); glVertex3f(0.35 + 0.05 * cos2, 0.00, 0.25); mi->polygon_count++; glColor3fv(MaterialGray); glVertex3f(-0.20 + 0.05 * cos2, 0.00 + 0.1 * sin2, 0.45); mi->polygon_count++; glEnd(); mi->polygon_count++; /* LEFT-BACK ARM */ glBegin(GL_LINE_STRIP); if (mono) glColor3fv(MaterialGray5); else glColor3fv(Material); glVertex3f(0.00, -0.05, 0.18); glVertex3f(0.35 + 0.05 * cos3, -0.15, 0.25); mi->polygon_count++; glColor3fv(MaterialGray); glVertex3f(-0.20 + 0.05 * cos3, -0.25 + 0.1 * sin3, 0.45); mi->polygon_count++; glEnd(); /* RIGHT-FRONT ARM */ glBegin(GL_LINE_STRIP); if (mono) glColor3fv(MaterialGray5); else glColor3fv(Material); glVertex3f(0.00, 0.05, -0.18); glVertex3f(0.35 - 0.05 * sin1, 0.15, -0.25); mi->polygon_count++; glColor3fv(MaterialGray); glVertex3f(-0.20 - 0.05 * sin1, 0.25 + 0.1 * cos1, -0.45); mi->polygon_count++; glEnd(); /* RIGHT-CENTER ARM */ glBegin(GL_LINE_STRIP); if (mono) glColor3fv(MaterialGray5); else glColor3fv(Material); glVertex3f(0.00, 0.00, -0.18); glVertex3f(0.35 - 0.05 * sin2, 0.00, -0.25); mi->polygon_count++; glColor3fv(MaterialGray); glVertex3f(-0.20 - 0.05 * sin2, 0.00 + 0.1 * cos2, -0.45); mi->polygon_count++; glEnd(); /* RIGHT-BACK ARM */ glBegin(GL_LINE_STRIP); if (mono) glColor3fv(MaterialGray5); else glColor3fv(Material); glVertex3f(0.00, -0.05, -0.18); glVertex3f(0.35 - 0.05 * sin3, -0.15, -0.25); mi->polygon_count++; glColor3fv(MaterialGray); glVertex3f(-0.20 - 0.05 * sin3, -0.25 + 0.1 * cos3, -0.45); mi->polygon_count++; glEnd(); glEnable(GL_LIGHTING); return True; }
int display_edit_window_handler(window_info *win) { char temp[100]; glColor3f(0.77f,0.57f,0.39f); #ifdef X86_64 if(ew_selected_object!=-1 && !ew_object_type?(long int)objects_list[ew_selected_object]:(long int)obj_2d_list[ew_selected_object]){ #else if(ew_selected_object!=-1 && !ew_object_type?(int)objects_list[ew_selected_object]:(int)obj_2d_list[ew_selected_object]){ #endif glEnable(GL_BLEND); glBlendFunc(GL_ONE,GL_SRC_ALPHA); glDisable(GL_TEXTURE_2D); glDisable(GL_BLEND); // Drawing buttons glBegin(GL_LINE_LOOP); glVertex3i(g1_x1,g1_y1,0); glVertex3i(g1_x2,g1_y1,0); glVertex3i(g1_x2,g1_y2,0); glVertex3i(g1_x1,g1_y2,0); glEnd(); glBegin(GL_LINE_LOOP); glVertex3i(g2_x1,g2_y1,0); glVertex3i(g2_x2,g2_y1,0); glVertex3i(g2_x2,g2_y2,0); glVertex3i(g2_x1,g2_y2,0); glEnd(); glBegin(GL_LINE_LOOP); glVertex3i(g3_x1,g3_y1,0); glVertex3i(g3_x2,g3_y1,0); glVertex3i(g3_x2,g3_y2,0); glVertex3i(g3_x1,g3_y2,0); glEnd(); glBegin(GL_LINE_LOOP); glVertex3i(g4_x1,g4_y1,0); glVertex3i(g4_x2,g4_y1,0); glVertex3i(g4_x2,g4_y2,0); glVertex3i(g4_x1,g4_y2,0); glEnd(); glBegin(GL_LINE_LOOP); glVertex3i(g5_x1,g5_y1,0); glVertex3i(g5_x2,g5_y1,0); glVertex3i(g5_x2,g5_y2,0); glVertex3i(g5_x1,g5_y2,0); glEnd(); glBegin(GL_LINE_LOOP); glVertex3i(g6_x1,g6_y1,0); glVertex3i(g6_x2,g6_y1,0); glVertex3i(g6_x2,g6_y2,0); glVertex3i(g6_x1,g6_y2,0); glEnd(); glBegin(GL_LINE_LOOP); glVertex3i(g7_x1,g7_y1,0); glVertex3i(g7_x2,g7_y1,0); glVertex3i(g7_x2,g7_y2,0); glVertex3i(g7_x1,g7_y2,0); glEnd(); glBegin(GL_LINE_LOOP); glVertex3i(g8_x1,g8_y1,0); glVertex3i(g8_x2,g8_y1,0); glVertex3i(g8_x2,g8_y2,0); glVertex3i(g8_x1,g8_y2,0); glEnd(); glBegin(GL_LINE_LOOP); glVertex3i(g11_x1,g11_y1,0); glVertex3i(g11_x2,g11_y1,0); glVertex3i(g11_x2,g11_y2,0); glVertex3i(g11_x1,g11_y2,0); glEnd(); glBegin(GL_LINE_LOOP); glVertex3i(g12_x1,g12_y1,0); glVertex3i(g12_x2,g12_y1,0); glVertex3i(g12_x2,g12_y2,0); glVertex3i(g12_x1,g12_y2,0); glEnd(); glBegin(GL_LINE_LOOP); glVertex3i(g21_x1,g21_y1,0); glVertex3i(g21_x2,g21_y1,0); glVertex3i(g21_x2,g21_y2,0); glVertex3i(g21_x1,g21_y2,0); glEnd(); if(ew_object_type==0){ glBegin(GL_LINE_LOOP); glVertex3i(g9_x1,g9_y1,0); glVertex3i(g9_x2,g9_y1,0); glVertex3i(g9_x2,g9_y2,0); glVertex3i(g9_x1,g9_y2,0); glEnd(); glBegin(GL_LINE_LOOP); glVertex3i(g10_x1,g10_y1,0); glVertex3i(g10_x2,g10_y1,0); glVertex3i(g10_x2,g10_y2,0); glVertex3i(g10_x1,g10_y2,0); glEnd(); glBegin(GL_LINE_LOOP); glVertex3i(g13_x1,g13_y1,0); glVertex3i(g13_x2,g13_y1,0); glVertex3i(g13_x2,g13_y2,0); glVertex3i(g13_x1,g13_y2,0); glEnd(); glBegin(GL_LINE_LOOP); glVertex3i(g14_x1,g14_y1,0); glVertex3i(g14_x2,g14_y1,0); glVertex3i(g14_x2,g14_y2,0); glVertex3i(g14_x1,g14_y2,0); glEnd(); glBegin(GL_LINE_LOOP); glVertex3i(g15_x1,g15_y1,0); glVertex3i(g15_x2,g15_y1,0); glVertex3i(g15_x2,g15_y2,0); glVertex3i(g15_x1,g15_y2,0); glEnd(); glBegin(GL_LINE_LOOP); glVertex3i(g16_x1,g16_y1,0); glVertex3i(g16_x2,g16_y1,0); glVertex3i(g16_x2,g16_y2,0); glVertex3i(g16_x1,g16_y2,0); glEnd(); glBegin(GL_LINE_LOOP); glVertex3i(g17_x1,g17_y1,0); glVertex3i(g17_x2,g17_y1,0); glVertex3i(g17_x2,g17_y2,0); glVertex3i(g17_x1,g17_y2,0); glEnd(); glBegin(GL_LINE_LOOP); glVertex3i(g18_x1,g18_y1,0); glVertex3i(g18_x2,g18_y1,0); glVertex3i(g18_x2,g18_y2,0); glVertex3i(g18_x1,g18_y2,0); glEnd(); glBegin(GL_LINE_LOOP); glVertex3i(g19_x1,g19_y1,0); glVertex3i(g19_x2,g19_y1,0); glVertex3i(g19_x2,g19_y2,0); glVertex3i(g19_x1,g19_y2,0); glEnd(); glBegin(GL_LINE_LOOP); glVertex3i(g20_x1,g20_y1,0); glVertex3i(g20_x2,g20_y1,0); glVertex3i(g20_x2,g20_y2,0); glVertex3i(g20_x1,g20_y2,0); glEnd(); } glEnable(GL_TEXTURE_2D); // Drawing object info snprintf(temp,99,"X Pos: %03.2f",ew_object_type?obj_2d_list[ew_selected_object]->x_pos:objects_list[ew_selected_object]->x_pos); draw_string(10,10,temp,1); draw_string(160,10,"+ -",1); snprintf(temp,99,"Y Pos: %03.2f",ew_object_type?obj_2d_list[ew_selected_object]->y_pos:objects_list[ew_selected_object]->y_pos); draw_string(10,30,temp,1); draw_string(160,30,"+ -",1); snprintf(temp,99,"Z Pos: %03.2f",ew_object_type?obj_2d_list[ew_selected_object]->z_pos:objects_list[ew_selected_object]->z_pos); draw_string(10,50,temp,1); draw_string(160,50,"+ -",1); snprintf(temp,99,"X Rot: %03.2f",ew_object_type?obj_2d_list[ew_selected_object]->x_rot:objects_list[ew_selected_object]->x_rot); draw_string(10,80,temp,1); draw_string(160,80,"+ -",1); snprintf(temp,99,"Z Rot: %03.2f",ew_object_type?obj_2d_list[ew_selected_object]->z_rot:objects_list[ew_selected_object]->z_rot); draw_string(10,120,temp,1); draw_string(160,120,"+ -",1); snprintf(temp,99,"File Name: %s",ew_object_type?obj_2d_list[ew_selected_object]->file_name:objects_list[ew_selected_object]->file_name); draw_string(10,150,temp,1); snprintf(temp,99,"ObjectID: %d",ew_selected_object); draw_string(220,120,temp,1); draw_string(450,65,"Restore",1); if(ew_object_type==0){ snprintf(temp,99,"Y Rot: %03.2f",objects_list[ew_selected_object]->y_rot); draw_string(10,100,temp,1); draw_string(160,100,"+ -",1); snprintf(temp,99,"Red: %01.3f",objects_list[ew_selected_object]->r); draw_string(220,10,temp,1); draw_string(380,10,"+ -",1); snprintf(temp,99,"Green: %01.3f",objects_list[ew_selected_object]->g); draw_string(220,30,temp,1); draw_string(380,30,"+ -",1); snprintf(temp,99,"Blue: %01.3f",objects_list[ew_selected_object]->b); draw_string(220,50,temp,1); draw_string(380,50,"+ -",1); snprintf(temp,99,"Blended: %s",objects_list[ew_selected_object]->blended?"Yes":"No"); draw_string(220,80,temp,1); draw_string(380,80,"+",1); snprintf(temp,99,"SelfLit: %s",objects_list[ew_selected_object]->self_lit?"Yes":"No"); draw_string(220,100,temp,1); draw_string(380,100,"+",1); } } // The X draw_string(0+win->len_x-16,0+2,(unsigned char *)"X",1); return 1; } int check_edit_window_interface(window_info *win, int mx, int my, Uint32 flags) { int x,y; if(mouse_x>win->pos_x+win->len_x || mouse_x<win->pos_x || mouse_y<win->pos_y || mouse_y>win->pos_y+win->len_y)return 0; if(view_edit_window && mouse_x>(win->pos_x+win->len_x-20) && mouse_x<=(win->pos_x+win->len_x) && mouse_y>win->pos_y && mouse_y<=win->pos_y+20) { view_edit_window=0; return 1; } if(ew_selected_object==-1)return 0; x=mouse_x-win->pos_x; y=mouse_y-win->pos_y; if(x>g1_x1 && x<=g1_x2 && y>g1_y1 && y<=g1_y2){ if(ew_object_type) obj_2d_list[ew_selected_object]->x_pos+=(shift_on)?(ctrl_on?0.001:(alt_on?0.01:0.1)):(ctrl_on?100:(alt_on?10:1)); else objects_list[ew_selected_object]->x_pos+=(shift_on)?(ctrl_on?0.001:(alt_on?0.01:0.1)):(ctrl_on?100:(alt_on?10:1)); } if(x>g2_x1 && x<=g2_x2 && y>g2_y1 && y<=g2_y2){ if(ew_object_type) obj_2d_list[ew_selected_object]->x_pos-=(shift_on)?(ctrl_on?0.001:(alt_on?0.01:0.1)):(ctrl_on?100:(alt_on?10:1)); else objects_list[ew_selected_object]->x_pos-=(shift_on)?(ctrl_on?0.001:(alt_on?0.01:0.1)):(ctrl_on?100:(alt_on?10:1)); } if(x>g3_x1 && x<=g3_x2 && y>g3_y1 && y<=g3_y2){ if(ew_object_type) obj_2d_list[ew_selected_object]->y_pos+=(shift_on)?(ctrl_on?0.001:(alt_on?0.01:0.1)):(ctrl_on?100:(alt_on?10:1)); else objects_list[ew_selected_object]->y_pos+=(shift_on)?(ctrl_on?0.001:(alt_on?0.01:0.1)):(ctrl_on?100:(alt_on?10:1)); } if(x>g4_x1 && x<=g4_x2 && y>g4_y1 && y<=g4_y2){ if(ew_object_type) obj_2d_list[ew_selected_object]->y_pos-=(shift_on)?(ctrl_on?0.001:(alt_on?0.01:0.1)):(ctrl_on?100:(alt_on?10:1)); else objects_list[ew_selected_object]->y_pos-=(shift_on)?(ctrl_on?0.001:(alt_on?0.01:0.1)):(ctrl_on?100:(alt_on?10:1)); } if(x>g5_x1 && x<=g5_x2 && y>g5_y1 && y<=g5_y2){ if(ew_object_type) obj_2d_list[ew_selected_object]->z_pos+=(shift_on)?(ctrl_on?0.001:(alt_on?0.01:0.1)):(ctrl_on?100:(alt_on?10:1)); else objects_list[ew_selected_object]->z_pos+=(shift_on)?(ctrl_on?0.001:(alt_on?0.01:0.1)):(ctrl_on?100:(alt_on?10:1)); } if(x>g6_x1 && x<=g6_x2 && y>g6_y1 && y<=g6_y2){ if(ew_object_type) obj_2d_list[ew_selected_object]->z_pos-=(shift_on)?(ctrl_on?0.001:(alt_on?0.01:0.1)):(ctrl_on?100:(alt_on?10:1)); else objects_list[ew_selected_object]->z_pos-=(shift_on)?(ctrl_on?0.001:(alt_on?0.01:0.1)):(ctrl_on?100:(alt_on?10:1)); } if(x>g7_x1 && x<=g7_x2 && y>g7_y1 && y<=g7_y2){ if(ew_object_type) obj_2d_list[ew_selected_object]->x_rot+=(shift_on)?(ctrl_on?0.001:(alt_on?0.01:0.1)):(ctrl_on?100:(alt_on?10:1)); else objects_list[ew_selected_object]->x_rot+=(shift_on)?(ctrl_on?0.001:(alt_on?0.01:0.1)):(ctrl_on?100:(alt_on?10:1)); } if(x>g8_x1 && x<=g8_x2 && y>g8_y1 && y<=g8_y2){ if(ew_object_type) obj_2d_list[ew_selected_object]->x_rot-=(shift_on)?(ctrl_on?0.001:(alt_on?0.01:0.1)):(ctrl_on?100:(alt_on?10:1)); else objects_list[ew_selected_object]->x_rot-=(shift_on)?(ctrl_on?0.001:(alt_on?0.01:0.1)):(ctrl_on?100:(alt_on?10:1)); } if(x>g9_x1 && x<=g9_x2 && y>g9_y1 && y<=g9_y2 && !ew_object_type)objects_list[ew_selected_object]->y_rot+=(shift_on)?(ctrl_on?0.001:(alt_on?0.01:0.1)):(ctrl_on?100:(alt_on?10:1)); if(x>g10_x1 && x<=g10_x2 && y>g10_y1 && y<=g10_y2 && !ew_object_type)objects_list[ew_selected_object]->y_rot-=(shift_on)?(ctrl_on?0.001:(alt_on?0.01:0.1)):(ctrl_on?100:(alt_on?10:1)); if(x>g11_x1 && x<=g11_x2 && y>g11_y1 && y<=g11_y2){ if(ew_object_type) obj_2d_list[ew_selected_object]->z_rot+=(shift_on)?(ctrl_on?0.001:(alt_on?0.01:0.1)):(ctrl_on?100:(alt_on?10:1)); else objects_list[ew_selected_object]->z_rot+=(shift_on)?(ctrl_on?0.001:(alt_on?0.01:0.1)):(ctrl_on?100:(alt_on?10:1)); } if(x>g12_x1 && x<=g12_x2 && y>g12_y1 && y<=g12_y2){ if(ew_object_type) obj_2d_list[ew_selected_object]->z_rot-=(shift_on)?(ctrl_on?0.001:(alt_on?0.01:0.1)):(ctrl_on?100:(alt_on?10:1)); else objects_list[ew_selected_object]->z_rot-=(shift_on)?(ctrl_on?0.001:(alt_on?0.01:0.1)):(ctrl_on?100:(alt_on?10:1)); } if(x>g13_x1 && x<=g13_x2 && y>g13_y1 && y<=g13_y2 && !ew_object_type)objects_list[ew_selected_object]->r+=(shift_on)?(ctrl_on?0.001:(alt_on?0.01:0.1)):(ctrl_on?100:(alt_on?10:1)); if(x>g14_x1 && x<=g14_x2 && y>g14_y1 && y<=g14_y2 && !ew_object_type)objects_list[ew_selected_object]->r-=(shift_on)?(ctrl_on?0.001:(alt_on?0.01:0.1)):(ctrl_on?100:(alt_on?10:1)); if(x>g15_x1 && x<=g15_x2 && y>g15_y1 && y<=g15_y2 && !ew_object_type)objects_list[ew_selected_object]->g+=(shift_on)?(ctrl_on?0.001:(alt_on?0.01:0.1)):(ctrl_on?100:(alt_on?10:1)); if(x>g16_x1 && x<=g16_x2 && y>g16_y1 && y<=g16_y2 && !ew_object_type)objects_list[ew_selected_object]->g-=(shift_on)?(ctrl_on?0.001:(alt_on?0.01:0.1)):(ctrl_on?100:(alt_on?10:1)); if(x>g17_x1 && x<=g17_x2 && y>g17_y1 && y<=g17_y2 && !ew_object_type)objects_list[ew_selected_object]->b+=(shift_on)?(ctrl_on?0.001:(alt_on?0.01:0.1)):(ctrl_on?100:(alt_on?10:1)); if(x>g18_x1 && x<=g18_x2 && y>g18_y1 && y<=g18_y2 && !ew_object_type)objects_list[ew_selected_object]->b-=(shift_on)?(ctrl_on?0.001:(alt_on?0.01:0.1)):(ctrl_on?100:(alt_on?10:1)); if(x>g19_x1 && x<=g19_x2 && y>g19_y1 && y<=g19_y2 && !ew_object_type)objects_list[ew_selected_object]->blended=!objects_list[ew_selected_object]->blended; if(x>g20_x1 && x<=g20_x2 && y>g20_y1 && y<=g20_y2 && !ew_object_type)objects_list[ew_selected_object]->self_lit=!objects_list[ew_selected_object]->self_lit; if(x>g21_x1 && x<=g21_x2 && y>g21_y1 && y<=g21_y2){ if(ew_object_type==1) memcpy(obj_2d_list[ew_selected_object],&o2t,sizeof(obj_2d)); else memcpy(objects_list[ew_selected_object],&o3t,sizeof(object3d)); } return 1; }
void LinearTexture::allocate(int w, int h, int internalGlDataType, bool bUseARBExtention){ //our graphics card might not support arb so we have to see if it is supported. #ifndef TARGET_OPENGLES if (bUseARBExtention && GL_ARB_texture_rectangle){ texData.tex_w = w; texData.tex_h = h; texData.tex_t = w; texData.tex_u = h; texData.textureTarget = GL_TEXTURE_RECTANGLE_ARB; } else #endif { //otherwise we need to calculate the next power of 2 for the requested dimensions //ie (320x240) becomes (512x256) texData.tex_w = ofNextPow2(w); texData.tex_h = ofNextPow2(h); texData.tex_t = 1.0f; texData.tex_u = 1.0f; texData.textureTarget = GL_TEXTURE_2D; } texData.glTypeInternal = internalGlDataType; // MEMO: todo, add more types switch(texData.glTypeInternal) { #ifndef TARGET_OPENGLES case GL_RGBA32F_ARB: case GL_RGBA16F_ARB: texData.glType = GL_RGBA; texData.pixelType = GL_FLOAT; break; case GL_RGB32F_ARB: texData.glType = GL_RGB; texData.pixelType = GL_FLOAT; break; case GL_LUMINANCE32F_ARB: texData.glType = GL_LUMINANCE; texData.pixelType = GL_FLOAT; break; #endif default: texData.glType = GL_LUMINANCE; texData.pixelType = GL_UNSIGNED_BYTE; } // attempt to free the previous bound texture, if we can: clear(); glGenTextures(1, (GLuint *)&texData.textureID); // could be more then one, but for now, just one glEnable(texData.textureTarget); glBindTexture(texData.textureTarget, (GLuint)texData.textureID); glTexParameterf(texData.textureTarget, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameterf(texData.textureTarget, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameterf(texData.textureTarget, GL_TEXTURE_WRAP_S, GL_LINEAR); glTexParameterf(texData.textureTarget, GL_TEXTURE_WRAP_T, GL_LINEAR); #ifndef TARGET_OPENGLES // can't do this on OpenGL ES: on full-blown OpenGL, // internalGlDataType and glDataType (GL_LUMINANCE below) // can be different; on ES they must be exactly the same. // glTexImage2D(texData.textureTarget, 0, texData.glTypeInternal, (GLint)texData.tex_w, (GLint)texData.tex_h, 0, GL_LUMINANCE, PIXEL_TYPE, 0); // init to black... glTexImage2D(texData.textureTarget, 0, texData.glTypeInternal, (GLint)texData.tex_w, (GLint)texData.tex_h, 0, texData.glType, texData.pixelType, 0); // init to black... #else glTexImage2D(texData.textureTarget, 0, texData.glTypeInternal, texData.tex_w, texData.tex_h, 0, texData.glTypeInternal, GL_UNSIGNED_BYTE, 0); #endif glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); glDisable(texData.textureTarget); texData.width = w; texData.height = h; texData.bFlipTexture = false; texData.bAllocated = true; }
void a_InitGL() { glDisable(GL_LIGHT0); a_time=2.0; a_gets=0;a_timecyc=0; gendep=1.55; cameraray[0]=0;cameraray[1]=0;cameraray[2]=0; rray[0]=0;rray[1]=0;rray[2]=0; a_x=0;a_y=0;a_float_x=0;a_float_y=0;a_float_xb=0;a_float_yb=0; a_xrot=0;a_yrot=0;a_zrot=0;a_rad=0.0f; quantos=-1.0f; a_zeta=-1.0f; a_factor=10.0f; a_time=2.0f; a_waves=0; a_az=0; a_counter=0; a_mod=0; a_xa=0;a_ya=0; a_mod=0; a_xa=0;a_ya=0; a_diffuse[0]=0.2f;a_diffuse[1]=0.2f;a_diffuse[2]=0.2f;a_diffuse[3]=1.0f; a_ambient[0]=0.1f;a_ambient[1]=0.1f;a_ambient[2]=0.1f;a_ambient[3]=1.0f; a_specular[0]=.75f;a_specular[1]=.75f;a_specular[2]=.75f;a_specular[3]=1.0f; a_emission[0]=0.2f;a_emission[1]=0.2f;a_emission[2]=0.2f;a_emission[3]=1.0f; a_shininess = 10.0f; a_LightAmbient[0]=0.5f;a_LightAmbient[1]=0.5f;a_LightAmbient[2]=0.5f;a_LightAmbient[3]=1.0f; a_LightDiffuse[0]=0.5f;a_LightDiffuse[1]=0.5f;a_LightDiffuse[2]=0.5f;a_LightDiffuse[3]=1.0f; a_LightSpecular[0]=.5f;a_LightSpecular[1]=.5f;a_LightSpecular[2]=.5f;a_LightSpecular[3]=1.0f; a_LightPosition[0]=0.0f;a_LightPosition[1]=8.0f;a_LightPosition[2]=-20.0f;a_LightPosition[3]=1.0f; a_Sinus[0]=0; a_Sinus[1]=0; a_Sinus[2]=0; a_xrot=0; a_yrot=0; a_zrot=0; a_counter=0; a_rad=0.0f; quantos=-1.0f; a_zeta=-1.0f; a_factor=10.0f; a_waves=0; a_counter=0; coeff=7.1f; a_gets=0; switcher=false; gendep=1.55; camera[0]=-12.8; camera[1]=12.8; camera[2]=5; glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,0.1f,100.0f); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); 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); a_Text=new Texture[numtexs]; a_Text[1].Load("data/logoxs.raw"); a_Text[2].Load("data/white.raw"); a_Text[3].Load("data/sun2.raw"); a_Text[4].Load("data/star.raw"); glEnable (GL_LIGHTING); glEnable (GL_LIGHT1); glLightfv(GL_LIGHT1,GL_DIFFUSE,a_LightDiffuse); glLightfv(GL_LIGHT1,GL_AMBIENT,a_LightAmbient); glLightfv(GL_LIGHT1,GL_SPECULAR,a_LightSpecular); glLightfv(GL_LIGHT1,GL_POSITION,a_LightPosition); glMaterialfv(GL_FRONT,GL_DIFFUSE,a_diffuse); glMaterialfv(GL_FRONT,GL_AMBIENT,a_ambient); glMaterialfv(GL_FRONT,GL_SPECULAR,a_specular); glMaterialf(GL_FRONT,GL_SHININESS,10.0f); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); glEnable(GL_TEXTURE_2D); for (a_x=0;a_x<size;a_x++) { for (a_y=0; a_y<size;a_y++) { a_points[a_x][a_y][0]=float(a_x/(1.25f*size/32)); a_points[a_x][a_y][1]=float(a_y/(1.25f*size/32)); a_points[a_x][a_y][2]=0.0; } } for (int p=0; p<a_num; p++) { parts[p].r=128+rand()%128; parts[p].g=128+rand()%128; parts[p].b=128+rand()%128; parts[p].a=-1; parts[p].angle=rand()%90; parts[p].a_mod=0.0f; parts[p].speedlim=.005+.0001*((GLfloat)(rand()%1000)); parts[p].speed=parts[p].speedlim; parts[p].a_x=0.0f; parts[p].a_y=0.0f; parts[p].z=0.0f; } a_mod=1.0; glBlendFunc(GL_SRC_ALPHA,GL_ONE); glEnable(GL_BLEND); glDisable(GL_DEPTH_TEST); a_setpart(); }
void CModelGTF::RenderModel() { // Go through all of the objects stored in this model for(int i = 0; i < m_Model.numOfObjects; i++) { // Get the current object that we are displaying t3DObject *pObject = &m_Model.pObject[i]; // Check if there are materials assigned to this object and // enable texture mapping if necessary, otherwise turn it off. if(pObject->numOfMaterials >= 1) glEnable(GL_TEXTURE_2D); else glDisable(GL_TEXTURE_2D); // Go through all of the faces (polygons) of the object and draw them for(int j = 0; j < pObject->numOfFaces; j++) { // Now let's see if there are any materials that need binding if(pObject->numOfMaterials >= 1) { // Create a static int to hold the last texture ID static int lastTexID = -1; // Extract the current textureID for this face from our face data int textureID = m_Model.pMaterials[pObject->pFaces[j].textureID].texureId; // If the current texture ID isn't the same as last time, bind the texture. if(textureID != lastTexID && textureID >= 0 && textureID < (int)strTextures.size()) glBindTexture(GL_TEXTURE_2D, m_Textures[textureID]); // Store the current textureID in our static int for next time lastTexID = textureID; } // Start drawing our model triangles glBegin(GL_TRIANGLES); // Go through each vertex of the triangle and draw it. for(int whichVertex = 0; whichVertex < 3; whichVertex++) { // Make sure there are texture coordinates for this if(pObject->pTexVerts) { // Here we grab the texture index from our face information int texIndex = pObject->pFaces[j].coordIndex[whichVertex]; // Assign the texture coordinate to this vertex glTexCoord2f(pObject->pTexVerts[ texIndex ].x, pObject->pTexVerts[ texIndex ].y); } // Grab the current vertex index from our face information int vertIndex = pObject->pFaces[j].vertIndex[whichVertex]; //////////// *** NEW *** ////////// *** NEW *** ///////////// *** NEW *** //////////////////// // Now we get to the beef of the tutorial. Below is where we // handle the calculations for our animation. Basically what // happens is we grab the current and the next frame of animation // data. With that data (the weights and transformations) we // do spherical interpolation (quaternion rotations) and linear // interpolation (the translations) to get a smooth transformation // between each frame of animation. There isn't anything to // difficult about the concepts, but the math is the challenging // part. The only math that is new to this tutorial is the // calculations of multiplying a quaternion by a 3D vector. // Extract the current vertex and draw it CVector3 vPos = pObject->pVerts[vertIndex]; // If there is no animation, just render the original // vertex and continue (skip the animation calculations). if(!pObject->bAnimated) { glVertex3f(vPos.x, vPos.y, vPos.z); continue; } // This will be our final vertex position to render CVector3 vNewPos(0, 0, 0); // Just to specify the index, we store our vertex index as a blendIndex. // This will index into our weight list. int blendIndex = vertIndex; // Now comes the crazy code :) We now will go through every single // weight influence and add up all the influences and transformations // to our current vertex. for(int b=0; b < pObject->vWeightInfo[blendIndex].numBlendLinks; b++) { // Grab the current bone index from our weight list. Remember that // the X variable stores the bone index and the Y stores the weight. int boneIndex = (int)pObject->vWeightInfo[blendIndex].pWeightInfo[b].x; // Make sure that the index we got isn't out of range of our bones if(boneIndex > pObject->numBones) return; // Now we want to grab the translation and rotation data for both the // current and the next frame of animation. That way we can interpolate // between the two frames to make the animation look smoother. So here // we grab pointers to the current and next matrix information for the // current bone we are working with. tBoneMatrix *pBoneMatrix1 = &(pObject->vBoneInfo[m_Model.currentFrame].pBoneMatrices[boneIndex]); tBoneMatrix *pBoneMatrix2 = &(pObject->vBoneInfo[m_Model.nextFrame].pBoneMatrices[boneIndex]); // First we want to perform the spherical-linear interpolation between // the two quaternions (rotations) for the current and next frame. CQuaternion qPos(pBoneMatrix1->qRotation); CQuaternion qPos2(pBoneMatrix2->qRotation); CQuaternion qNew = qPos.Slerp(qPos, qPos2, m_Model.t); // To apply the interpolated rotation we multiply our rotation by // the original position of the vertex. This will then use our // function that we created at the top of this file which multiplies a // quaternion by a vector. Once we do that, we store the new 3D vector. CVector3 vTempPos = qNew * vPos; // Next we grab the translations for the current and next frame CVector3 vPosition = pBoneMatrix1->vTranslation; CVector3 vNextPosition = pBoneMatrix2->vTranslation; // Using a simple linear-interpolation equation, we use our time "t" // value to interpolate between the current and next translation. This // gives us a smooth transition between each frame of animation. vTempPos.x += vPosition.x + m_Model.t * (vNextPosition.x - vPosition.x); vTempPos.y += vPosition.y + m_Model.t * (vNextPosition.y - vPosition.y); vTempPos.z += vPosition.z + m_Model.t * (vNextPosition.z - vPosition.z); // If there is a special weight for this vertex we want to extract // that and apply it to our current vertex. If the model isn't using // weighted animation then the weight will just be 1.0, which will do // nothing to the vertex when applied. Remember that the Y value of // our weight-info list is the actual weight value to be applied. float weight = pObject->vWeightInfo[blendIndex].pWeightInfo[b].y; // Apply the weight value to our current vertex and add it to our // final transformed vertex position. vNewPos += vTempPos * weight; } // vNewPos has our final position that was transformed, so render it. glVertex3f(vNewPos.x, vNewPos.y, vNewPos.z); //////////// *** NEW *** ////////// *** NEW *** ///////////// *** NEW *** //////////////////// } // Stop drawing polygons glEnd(); } } }
int a_DrawGLScene(GLfloat globtime) { if (init) {a_InitGL();init=false;} a_time=2.0+globtime*.01; // MOTION if (a_time<10.0f) { a_zeta=25.0f*cos((3.1415f/2.0f)*(1+a_time/10.0f)); a_xrot=-45.0f*cos((3.1415f/2.0f)*(1+a_time/10.0f)); } else { a_xrot=45.0f-30.0f*sin((a_time-10.0f)/20.0f)*sin((a_time-10.0f)/20.0f); a_zrot=360.0f*sin((a_time-10.0f)/50.0f)*sin((a_time-10.0f)/50.0f); a_zeta=-25.0f+5.0f*sin((a_time-10.0f)/10.0f)*sin((a_time-10.0f)/10.0f); } if (a_time>90.0f) a_zeta=-20.0f+10.0f*(1.0f-cos((a_time-90.0f)*3.1415f/10.0f)); if (a_zeta>-2.5f) a_zeta=-2.5f; a_factor=(a_xrot/.5+20)/50.0f; if (a_mod>0.5f) a_mod=1.0-.03f*(a_time-a_gets); else a_mod=.5-0.015f*(a_time-a_gets); if (a_mod<0.0f) a_mod=0.0f; glDisable(GL_TEXTURE_2D); glLoadIdentity(); glTranslatef(0,0,-5); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); if (a_zeta>-20.0f) glColor4f(0,0,0,-(a_zeta+20.0f)/40.0f+.25f); else glColor4f(0,0,0,.25f); glDisable(GL_LIGHTING); glEnable(GL_BLEND); a_drawquad(6); if (first)//a_time<3.01f) { glDisable(GL_BLEND); glColor4ub(255,255,255,255); a_drawquad(6); glEnable(GL_BLEND); first=false; } if (a_time>95.0f) { glColor4f(1.0f,1.0f,1.0f,(a_time-95.0f)/1.5f); a_drawquad(6); } glEnable(GL_TEXTURE_2D); glBlendFunc(GL_SRC_ALPHA,GL_ONE); glEnable(GL_LIGHTING); glLoadIdentity(); if (a_time>30.0) glTranslatef(0.0f,1.5f,a_zeta); else glTranslatef(0.0f,.5+.5f*(1.0-cos((a_time-2.0f)*3.1415f/28.0f)),a_zeta); glRotatef(-90+2*a_xrot,1.0f,0.0f,0.0f); glRotatef(a_yrot,0.0f,1.0f,0.0f); glRotatef(a_zrot,0.0f,0.0f,1.0f); for (int a_xx=0; a_xx<size; a_xx++) for (int a_yy=0; a_yy<size; a_yy++) { double raggio; double value; double arg; if (quantos>0.0f) { raggio=.5*sqrt((double)((a_points[a_xx][a_yy][0]-a_points[size/2][size/2][0])*(a_points[a_xx][a_yy][0]-a_points[size/2][size/2][0]) +(a_points[a_xx][a_yy][1]-a_points[size/2][size/2][1])*(a_points[a_xx][a_yy][1]-a_points[size/2][size/2][1]))); arg=2.5*raggio-quantos*2+30; if ((arg<-2*6.28)||(arg>4*6.28)) value=0; else value=.05*sin(arg)*sin(arg)*exp(arg/7); a_points[a_xx][a_yy][2]=value; } if (quantos>10) { raggio=.5*sqrt((double)((a_points[a_xx][a_yy][0]-a_points[48][48][0])*(a_points[a_xx][a_yy][0]-a_points[48][48][0]) +(a_points[a_xx][a_yy][1]-a_points[48][48][1])*(a_points[a_xx][a_yy][1]-a_points[48][48][1]))); arg=2.5*raggio-(quantos-10)*3+30; if ((arg<-2*6.28)||(arg>4*6.28)) value=0; else value=.025*sin(arg)*sin(arg)*exp(arg/7); a_points[a_xx][a_yy][2]+=value; } if (quantos>24) { raggio=.5*sqrt((double)((a_points[a_xx][a_yy][0]-a_points[50][22][0])*(a_points[a_xx][a_yy][0]-a_points[50][22][0]) +(a_points[a_xx][a_yy][1]-a_points[50][22][1])*(a_points[a_xx][a_yy][1]-a_points[50][22][1]))); arg=3.0*raggio-(quantos-24)*4+30; if ((arg<-2*6.28)||(arg>4*6.28)) value=0; else value=.02*sin(arg)*sin(arg)*exp(arg/7); a_points[a_xx][a_yy][2]+=value; } if (quantos>32) { raggio=.5*sqrt((double)((a_points[a_xx][a_yy][0]-a_points[32][32][0])*(a_points[a_xx][a_yy][0]-a_points[32][32][0]) +(a_points[a_xx][a_yy][1]-a_points[32][32][1])*(a_points[a_xx][a_yy][1]-a_points[32][32][1]))); arg=2.5*raggio-(quantos-32)*3+30; if ((arg<0*6.28)||(arg>4*6.28)) value=0; else value=.035*sin(arg)*sin(arg)*exp(arg/7); a_points[a_xx][a_yy][2]+=value; } calcul(a_xx,a_yy); } if (a_time>34.0f) quantos=2.0+(a_time-34.0)/1.5f; a_Text[1].Use(); glMaterialfv(GL_FRONT,GL_DIFFUSE,a_diffuse); glMaterialfv(GL_FRONT,GL_AMBIENT,a_ambient); glMaterialfv(GL_FRONT,GL_SPECULAR,a_specular); glMaterialf(GL_FRONT,GL_SHININESS,10.0f); // glPushMatrix(); // what for? //glDisable(GL_LIGHTING); glScalef(-1,-1,1); glColor4f(1,1,1,1); // glPushMatrix(); // what for? glTranslatef(-12.8,12.8,0); glNormal3f(0,0,1); for (int cc=0; cc<1; cc++) { if ((cc%2)==0) { glScalef(1,-1,1); glFrontFace(GL_CCW); } else { glScalef(-1,1,1); glFrontFace(GL_CW); } glBegin(GL_QUADS); for( a_x = 0; a_x < size-1; a_x++ ) { if (1)//a_x%2==0) { for( a_y = 0; a_y < size-1; a_y++ ) { glTexCoord2fv(newcoord[a_x][a_y]); //glNormal3f(-norm[a_x][a_y][0],-norm[a_x][a_y][1],-norm[a_x][a_y][2]); glVertex3fv( a_points[a_x][a_y]); glTexCoord2fv(newcoord[a_x][a_y+1]); //glNormal3f(-norm[a_x][a_y+1][0],-norm[a_x][a_y+1][1],-norm[a_x][a_y+1][2]); glVertex3fv( a_points[a_x][a_y+1]); glTexCoord2fv(newcoord[a_x+1][a_y+1]); //glNormal3f(-norm[a_x+1][a_y+1][0],-norm[a_x+1][a_y+1][1],-norm[a_x+1][a_y+1][2]); glVertex3fv( a_points[a_x+1][a_y+1]); glTexCoord2fv(newcoord[a_x+1][a_y]); //glNormal3f(-norm[a_x+1][a_y][0],-norm[a_x+1][a_y][1],-norm[a_x+1][a_y][2]); glVertex3fv( a_points[a_x+1][a_y]); } } else { for(a_y=size-2;a_y>=0;a_y--) { glTexCoord2fv(newcoord[a_x][a_y]); glVertex3fv( a_points[a_x][a_y]); glTexCoord2fv(newcoord[a_x][a_y+1]); glVertex3fv( a_points[a_x][a_y+1]); glTexCoord2fv(newcoord[a_x+1][a_y+1]); glVertex3fv( a_points[a_x+1][a_y+1]); glTexCoord2fv(newcoord[a_x+1][a_y]); glVertex3fv( a_points[a_x+1][a_y]); } } } glEnd(); } // glPushMatrix(); // what for? glDisable(GL_DEPTH_TEST); // glPopMatrix(); // what for? glDisable(GL_LIGHTING); a_Text[4].Use(); a_counter=a_time*10.0f; for (int p=0; p<a_num; p++) { GLfloat time; time=a_time*500-2.0-parts[p].time;//******************************************************** glPushMatrix(); glTranslatef(parts[p].a_x,parts[p].a_y,parts[p].z); glRotatef(-a_zrot,0,0,1); glRotatef(90-2.0f*a_xrot,1,0,0); glRotatef(parts[p].angle-135,0,0,1); glTranslatef(parts[p].a_mod,0,0); if (a_time<20.0f) glColor4ub(parts[p].r,parts[p].g,parts[p].b,(unsigned char)((parts[p].a-(int)((GLfloat)time/8.0f))*(a_time-6.0)/14.0)); else glColor4ub(parts[p].r,parts[p].g,parts[p].b,(unsigned char)(parts[p].a-(int)((GLfloat)time/8.0f))); if (a_time>6.0) a_drawquad(1.125f-.75*p/a_num); parts[p].a_mod=parts[p].speed*time/35.0f; parts[p].speed=parts[p].speedlim-time/2500000.0f; if (parts[p].speed<0.005f) parts[p].speed=0.005f; if (parts[p].a-(int)((GLfloat)time/8.0f)<3) { parts[p].a_x=10.0f*sin(a_counter*4.0f*3.14f/360.0f); parts[p].a_y=0.0f+10.0f*sin(a_counter*2*3.14/360.0); parts[p].z=a_Sinus[2]=3.0f-2.5f*cos(a_counter*8.0f*3.14f/360.0f); parts[p].r=128+rand()%128; parts[p].g=128+rand()%128; parts[p].b=128+rand()%128; parts[p].a=rand()%255; parts[p].a_mod=0.0f; parts[p].speedlim=.005+.0001*((GLfloat)(rand()%1000)); parts[p].speed=parts[p].speedlim; parts[p].time=(int)(a_time*500-2);//********************************* } glPopMatrix(); } glPushMatrix(); a_Sinus[0]=10.0f*sin(a_counter*4.0f*3.14f/360.0f); a_Sinus[1]=0.0f+10.0f*sin(a_counter*2*3.14/360.0); a_Sinus[2]=3.0f-2.5f*cos(a_counter*8.0f*3.14f/360.0f); glTranslatef(a_Sinus[0],a_Sinus[1],a_Sinus[2]); glRotatef(-a_zrot,0,0,1); glRotatef(90-2*a_xrot,1,0,0); glColor4ub(255,128,255,255); glColor4ub(128,192,255,255); glRotatef(2*a_counter,0,0,1); a_LightPosition[0]=0;//a_Sinus[0];//10.0f*sin(a_counter*4.0f*3.14f/360.0f); a_LightPosition[1]=0;//a_Sinus[1];//0.0f+10.0f*sin(a_counter*2*3.14/360.0); a_LightPosition[2]=0;//a_Sinus[2];//3.0f-2.5f*cos(a_counter*8.0f*3.14f/360.0f); glEnable(GL_LIGHTING); glLightfv(GL_LIGHT1,GL_POSITION,a_LightPosition); glDisable(GL_LIGHTING); a_Text[2].Use(); a_drawquad(1.0f+sin(a_counter*12.0f*3.1415f/360.0)+3.1415f/2.0f); a_Text[3].Use(); a_drawquad(3.0f+2*sin(a_counter*6.0f*3.1415f/360.0)); glPopMatrix(); /* a_LightPosition[0]=10.0f*sin(a_counter*4.0f*3.14f/360.0f); a_LightPosition[1]=0.0f+10.0f*sin(a_counter*2*3.14/360.0); a_LightPosition[2]=3.0f-2.5f*cos(a_counter*8.0f*3.14f/360.0f); // glTranslatef(a_LightPosition[0],a_LightPosition[1],a_LightPosition[2]); glEnable(GL_LIGHTING); glLightfv(GL_LIGHT1,GL_POSITION,a_LightPosition); */ // a_time=2.0f+(1)/500.0f;//************************************ if (a_time>96.0f) { //****************************** FINISH //a_Clean(); return false; } glutSwapBuffers(); return true; }
void CBasicTreeSquareDrawer::DrawQuad (int x,int y) { int treesX = td->treesX; CBasicTreeDrawer::TreeSquareStruct* tss=&td->trees[y*treesX+x]; float3 dif; dif.x=camera->pos.x-(x*SQUARE_SIZE*TREE_SQUARE_SIZE + SQUARE_SIZE*TREE_SQUARE_SIZE/2); dif.y=0; dif.z=camera->pos.z-(y*SQUARE_SIZE*TREE_SQUARE_SIZE + SQUARE_SIZE*TREE_SQUARE_SIZE/2); float dist=dif.Length(); dif/=dist; if(dist<SQUARE_SIZE*TREE_SQUARE_SIZE*treeDistance*2 && dist>SQUARE_SIZE*TREE_SQUARE_SIZE*(treeDistance)){//far trees tss->lastSeenFar=gs->frameNum; if(!tss->farDisplist || dif.dot(tss->viewVector)<0.97){ va=GetVertexArray(); va->Initialize(); tss->viewVector=dif; if(!tss->farDisplist) tss->farDisplist=glGenLists(1); float3 up(0,1,0); float3 side=up.cross(dif); for(std::map<int,CBasicTreeDrawer::TreeStruct>::iterator ti=tss->trees.begin();ti!=tss->trees.end();++ti){ CBasicTreeDrawer::TreeStruct* ts=&ti->second; if(ts->type<8){ float3 base(ts->pos); float height=MAX_TREE_HEIGHT; float width=MAX_TREE_HEIGHT*0.3; SetArray(0,0,base+side*width); SetArray(0,0.25,base+side*width+float3(0,height,0)); SetArray(0.5f,0.25,base-side*width+float3(0,height,0)); SetArray(0.5f,0,base-side*width); } else { float3 base(ts->pos); float height=MAX_TREE_HEIGHT; float width=MAX_TREE_HEIGHT*0.3; SetArray(0,0.25,base+side*width); SetArray(0,0.5,base+side*width+float3(0,height,0)); SetArray(0.25f,0.5,base-side*width+float3(0,height,0)); SetArray(0.25f,0.25,base-side*width); } } glNewList(td->trees[y*treesX+x].farDisplist,GL_COMPILE); va->DrawArrayT(GL_QUADS); glEndList(); } if(dist>SQUARE_SIZE*TREE_SQUARE_SIZE*(treeDistance*2-1)){ float trans=(SQUARE_SIZE*TREE_SQUARE_SIZE*treeDistance*2-dist)/(SQUARE_SIZE*TREE_SQUARE_SIZE); glEnable(GL_BLEND); glColor4f(1,1,1,trans); glAlphaFunc(GL_GREATER,(SQUARE_SIZE*TREE_SQUARE_SIZE*treeDistance*2-dist)/(SQUARE_SIZE*TREE_SQUARE_SIZE*2)); } else { glColor4f(1,1,1,1); glDisable(GL_BLEND); glAlphaFunc(GL_GREATER,0.5f); } glCallList(tss->farDisplist); } if(dist<SQUARE_SIZE*TREE_SQUARE_SIZE*treeDistance){ //midle distance trees tss->lastSeen=gs->frameNum; if(!tss->displist){ va=GetVertexArray(); va->Initialize(); tss->displist=glGenLists(1); for(std::map<int,CBasicTreeDrawer::TreeStruct>::iterator ti=tss->trees.begin();ti!=tss->trees.end();++ti){ CBasicTreeDrawer::TreeStruct* ts=&ti->second; if(ts->type<8){ float3 base(ts->pos); float height=MAX_TREE_HEIGHT; float width=MAX_TREE_HEIGHT*0.3; SetArray(0,0,base+float3(width,0,0)); SetArray(0,0.25,base+float3(width,height,0)); SetArray(0.5f,0.25,base+float3(-width,height,0)); SetArray(0.5f,0,base+float3(-width,0,0)); SetArray(0,0,base+float3(0,0,width)); SetArray(0,0.25,base+float3(0,height,width)); SetArray(0.5f,0.25,base+float3(0,height,-width)); SetArray(0.5f,0,base+float3(0,0,-width)); width*=1.2f; SetArray(0.5,0,base+float3(width,height*0.25,0)); SetArray(0.5,0.25,base+float3(0,height*0.25,-width)); SetArray(1,0.25,base+float3(-width,height*0.25,0)); SetArray(1,0,base+float3(0,height*0.25,width)); } else { float3 base(ts->pos); float height=MAX_TREE_HEIGHT; float width=MAX_TREE_HEIGHT*0.3; SetArray(0,0.25,base+float3(width,0,0)); SetArray(0,0.5,base+float3(width,height,0)); SetArray(0.25f,0.5,base+float3(-width,height,0)); SetArray(0.25f,0.25,base+float3(-width,0,0)); SetArray(0.25f,0.25,base+float3(0,0,width)); SetArray(0.25f,0.5,base+float3(0,height,width)); SetArray(0.5f,0.5,base+float3(0,height,-width)); SetArray(0.5f,0.25,base+float3(0,0,-width)); width*=1.2f; SetArray(0.5,0.25,base+float3(width,height*0.3,0)); SetArray(0.5,0.5,base+float3(0,height*0.3,-width)); SetArray(1,0.5,base+float3(-width,height*0.3,0)); SetArray(1,0.25,base+float3(0,height*0.3,width)); } } glNewList(tss->displist,GL_COMPILE); va->DrawArrayT(GL_QUADS); glEndList(); } glColor4f(1,1,1,1); glDisable(GL_BLEND); glAlphaFunc(GL_GREATER,0.5f); glCallList(tss->displist); } }
void DebugHooks::drawFaceLoopWireframe(const std::vector<const carve::geom3d::Vector *> &face_loop, const carve::geom3d::Vector &normal, float r, float g, float b, float a, bool inset) { glDisable(GL_DEPTH_TEST); const size_t S = face_loop.size(); double INSET = 0.005; if (inset) { glColor4f(r, g, b, a / 2.0); glBegin(GL_LINE_LOOP); for (size_t i = 0; i < S; ++i) { size_t i_pre = (i + S - 1) % S; size_t i_post = (i + 1) % S; carve::geom3d::Vector v1 = (*face_loop[i] - *face_loop[i_pre]).normalized(); carve::geom3d::Vector v2 = (*face_loop[i] - *face_loop[i_post]).normalized(); carve::geom3d::Vector n1 = cross(normal, v1); carve::geom3d::Vector n2 = cross(v2, normal); carve::geom3d::Vector v = *face_loop[i]; carve::geom3d::Vector p1 = v + INSET * n1; carve::geom3d::Vector p2 = v + INSET * n2; carve::geom3d::Vector i1 , i2; double mu1, mu2; carve::geom3d::Vector p; if (carve::geom3d::rayRayIntersection(carve::geom3d::Ray(v1, p1), carve::geom3d::Ray(v2, p2), i1, i2, mu1, mu2)) { p = (i1 + i2) / 2; } else { p = (p1 + p2) / 2; } glVertex(&p); } glEnd(); } glColor4f(r, g, b, a); glBegin(GL_LINE_LOOP); for (unsigned i = 0; i < S; ++i) { glVertex(face_loop[i]); } glEnd(); glColor4f(r, g, b, a); glPointSize(3.0); glBegin(GL_POINTS); for (unsigned i = 0; i < S; ++i) { carve::geom3d::Vector p = *face_loop[i]; glVertex(face_loop[i]); } glEnd(); glEnable(GL_DEPTH_TEST); }
//---------------------------------------------------------- void ofTexture::loadData(void * data, int w, int h, int glDataType){ //SOSOLIMITED: image load step 5 - sets tex.glType to match // can we allow for uploads bigger then texture and // just take as much as the texture can? // // ie: // int uploadW = MIN(w, tex_w); // int uploadH = MIN(h, tex_h); // but with a "step" size of w? // check "glTexSubImage2D" if ( w > texData.tex_w || h > texData.tex_h) { ofLog(OF_LOG_ERROR,"image data too big for allocated texture. not uploading..."); return; } //update our size with the new dimensions - this should be the same size or smaller than the allocated texture size texData.width = w; texData.height = h; texData.glType = glDataType; //compute new tex co-ords based on the ratio of data's w, h to texture w,h; #ifndef TARGET_OPENGLES if (texData.textureTarget == GL_TEXTURE_RECTANGLE_ARB){ texData.tex_t = w; texData.tex_u = h; } else #endif { texData.tex_t = (float)(w) / (float)texData.tex_w; texData.tex_u = (float)(h) / (float)texData.tex_h; } // ok this is an ultra annoying bug : // opengl texels and linear filtering - // when we have a sub-image, and we scale it // we can clamp the border pixels to the border, // but the borders of the sub image get mixed with // neighboring pixels... // grr... // // the best solution would be to pad out the image // being uploaded with 2 pixels on all sides, and // recompute tex_t coordinates.. // another option is a gl_arb non pow 2 textures... // the current hack is to alter the tex_t, tex_u calcs, but // that makes the image slightly off... // this is currently being done in draw... // // we need a good solution for this.. // // http://www.opengl.org/discussion_boards/ubb/ultimatebb.php?ubb=get_topic;f=3;t=014770#000001 // http://www.opengl.org/discussion_boards/ubb/ultimatebb.php?ubb=get_topic;f=3;t=014770#000001 //------------------------ likely, we are uploading continuous data GLint prevAlignment; glGetIntegerv(GL_UNPACK_ALIGNMENT, &prevAlignment); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); //Sosolimited: texture compression if ((!texData.useCompression) || (texData.compressionType == OF_COMPRESS_NONE)) { //STANDARD openFrameworks: no compression //update the texture image: glEnable(texData.textureTarget); glBindTexture(texData.textureTarget, (GLuint)texData.textureID); glTexSubImage2D(texData.textureTarget, 0, 0, 0, w, h, texData.glType, texData.pixelType, data); // MEMO: important to use pixelType here glDisable(texData.textureTarget); } else { //SOSOLIMITED: setup mipmaps and use compression //need proper tex_u and tex_t positions, with mipmaps they are the nearest power of 2 #ifndef TARGET_OPENGLES if (texData.textureTarget == GL_TEXTURE_RECTANGLE_ARB){ //need to find closest powers of two int last_h = ofNextPow2(texData.height)>>1; int next_h = ofNextPow2(texData.height); if ((texData.height - last_h) < (next_h - texData.height)) texData.tex_u = last_h; else texData.tex_u = next_h; int last_w = ofNextPow2(texData.width)>>1; int next_w = ofNextPow2(texData.width); if ((texData.width - last_w) < (next_w - texData.width)) texData.tex_t = last_w; else texData.tex_t = next_w; //printf("ofTexture::loadData w:%.1f, h:%.1f, tex_t:%.1f, tex_u:%.1f \n", texData.width,texData.height,texData.tex_t,texData.tex_u); } #endif glEnable(texData.textureTarget); glBindTexture(texData.textureTarget, (GLuint)texData.textureID); glHint(GL_GENERATE_MIPMAP_HINT, GL_NICEST); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); #ifndef TARGET_OPENGLES glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP_SGIS, true); #endif glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_LINEAR); #ifndef TARGET_OPENGLES //using sRGB compression if (texData.compressionType == OF_COMPRESS_SRGB) { if(texData.glType == GL_RGBA) gluBuild2DMipmaps(texData.textureTarget, GL_COMPRESSED_SRGB_ALPHA, w, h, texData.glType, GL_UNSIGNED_BYTE, data); else if(texData.glType == GL_RGB) gluBuild2DMipmaps(texData.textureTarget, GL_COMPRESSED_SRGB_ALPHA, w, h, texData.glType, GL_UNSIGNED_BYTE, data); else if(texData.glType == GL_LUMINANCE_ALPHA) gluBuild2DMipmaps(texData.textureTarget, GL_COMPRESSED_SRGB_ALPHA, w, h, texData.glType, GL_UNSIGNED_BYTE, data); else if(texData.glType == GL_LUMINANCE) gluBuild2DMipmaps(texData.textureTarget, GL_COMPRESSED_SRGB_ALPHA, w, h, texData.glType, GL_UNSIGNED_BYTE, data); } //using ARB compression: default else { if(texData.glType == GL_RGBA) gluBuild2DMipmaps(texData.textureTarget, GL_COMPRESSED_RGBA_ARB, w, h, texData.glType, GL_UNSIGNED_BYTE, data); else if(texData.glType == GL_RGB) gluBuild2DMipmaps(texData.textureTarget, GL_COMPRESSED_RGB_ARB, w, h, texData.glType, GL_UNSIGNED_BYTE, data); else if(texData.glType == GL_LUMINANCE_ALPHA) gluBuild2DMipmaps(texData.textureTarget, GL_COMPRESSED_LUMINANCE_ALPHA_ARB, w, h, texData.glType, GL_UNSIGNED_BYTE, data); else if(texData.glType == GL_LUMINANCE) gluBuild2DMipmaps(texData.textureTarget, GL_COMPRESSED_LUMINANCE_ARB, w, h, texData.glType, GL_UNSIGNED_BYTE, data); } #endif glDisable(texData.textureTarget); }
void ccGenericMesh::drawMeOnly(CC_DRAW_CONTEXT& context) { ccGenericPointCloud* vertices = getAssociatedCloud(); if (!vertices) return; handleColorRamp(context); //3D pass if (MACRO_Draw3D(context)) { //any triangle? unsigned triNum = size(); if (triNum == 0) return; //L.O.D. bool lodEnabled = (triNum > context.minLODTriangleCount && context.decimateMeshOnMove && MACRO_LODActivated(context)); unsigned decimStep = (lodEnabled ? static_cast<unsigned>(ceil(static_cast<double>(triNum*3) / context.minLODTriangleCount)) : 1); unsigned displayedTriNum = triNum / decimStep; //display parameters glDrawParams glParams; getDrawingParameters(glParams); glParams.showNorms &= bool(MACRO_LightIsEnabled(context)); //vertices visibility const ccGenericPointCloud::VisibilityTableType* verticesVisibility = vertices->getTheVisibilityArray(); bool visFiltering = (verticesVisibility && verticesVisibility->isAllocated()); //wireframe ? (not compatible with LOD) bool showWired = isShownAsWire() && !lodEnabled; //per-triangle normals? bool showTriNormals = (hasTriNormals() && triNormsShown()); //fix 'showNorms' glParams.showNorms = showTriNormals || (vertices->hasNormals() && m_normalsDisplayed); //materials & textures bool applyMaterials = (hasMaterials() && materialsShown()); bool showTextures = (hasTextures() && materialsShown() && !lodEnabled); //GL name pushing bool pushName = MACRO_DrawEntityNames(context); //special case: triangle names pushing (for picking) bool pushTriangleNames = MACRO_DrawTriangleNames(context); pushName |= pushTriangleNames; if (pushName) { //not fast at all! if (MACRO_DrawFastNamesOnly(context)) return; glPushName(getUniqueIDForDisplay()); //minimal display for picking mode! glParams.showNorms = false; glParams.showColors = false; //glParams.showSF --> we keep it only if SF 'NaN' values are hidden showTriNormals = false; applyMaterials = false; showTextures = false; } //in the case we need to display scalar field colors ccScalarField* currentDisplayedScalarField = 0; bool greyForNanScalarValues = true; //unsigned colorRampSteps = 0; ccColorScale::Shared colorScale(0); if (glParams.showSF) { assert(vertices->isA(CC_TYPES::POINT_CLOUD)); ccPointCloud* cloud = static_cast<ccPointCloud*>(vertices); greyForNanScalarValues = (cloud->getCurrentDisplayedScalarField() && cloud->getCurrentDisplayedScalarField()->areNaNValuesShownInGrey()); if (greyForNanScalarValues && pushName) { //in picking mode, no need to take SF into account if we don't hide any points! glParams.showSF = false; } else { currentDisplayedScalarField = cloud->getCurrentDisplayedScalarField(); colorScale = currentDisplayedScalarField->getColorScale(); //colorRampSteps = currentDisplayedScalarField->getColorRampSteps(); assert(colorScale); //get default color ramp if cloud has no scale associated?! if (!colorScale) colorScale = ccColorScalesManager::GetUniqueInstance()->getDefaultScale(ccColorScalesManager::BGYR); } } //materials or color? bool colorMaterial = false; if (glParams.showSF || glParams.showColors) { applyMaterials = false; colorMaterial = true; glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE); glEnable(GL_COLOR_MATERIAL); } //in the case we need to display vertex colors ColorsTableType* rgbColorsTable = 0; if (glParams.showColors) { if (isColorOverriden()) { ccGL::Color3v(m_tempColor.rgb); glParams.showColors = false; } else { assert(vertices->isA(CC_TYPES::POINT_CLOUD)); rgbColorsTable = static_cast<ccPointCloud*>(vertices)->rgbColors(); } } else { glColor3fv(context.defaultMat->getDiffuseFront().rgba); } if (glParams.showNorms) { //DGM: Strangely, when Qt::renderPixmap is called, the OpenGL version can fall to 1.0! glEnable((QGLFormat::openGLVersionFlags() & QGLFormat::OpenGL_Version_1_2 ? GL_RESCALE_NORMAL : GL_NORMALIZE)); glEnable(GL_LIGHTING); context.defaultMat->applyGL(true,colorMaterial); } //in the case we need normals (i.e. lighting) NormsIndexesTableType* normalsIndexesTable = 0; ccNormalVectors* compressedNormals = 0; if (glParams.showNorms) { assert(vertices->isA(CC_TYPES::POINT_CLOUD)); normalsIndexesTable = static_cast<ccPointCloud*>(vertices)->normals(); compressedNormals = ccNormalVectors::GetUniqueInstance(); } //stipple mask if (stipplingEnabled()) EnableGLStippleMask(true); if (!pushTriangleNames && !visFiltering && !(applyMaterials || showTextures) && (!glParams.showSF || greyForNanScalarValues)) { //the GL type depends on the PointCoordinateType 'size' (float or double) GLenum GL_COORD_TYPE = sizeof(PointCoordinateType) == 4 ? GL_FLOAT : GL_DOUBLE; glEnableClientState(GL_VERTEX_ARRAY); glVertexPointer(3,GL_COORD_TYPE,0,GetVertexBuffer()); if (glParams.showNorms) { glEnableClientState(GL_NORMAL_ARRAY); glNormalPointer(GL_COORD_TYPE,0,GetNormalsBuffer()); } if (glParams.showSF || glParams.showColors) { glEnableClientState(GL_COLOR_ARRAY); glColorPointer(3,GL_UNSIGNED_BYTE,0,GetColorsBuffer()); } //we can scan and process each chunk separately in an optimized way //we mimic the way ccMesh beahves by using virtual chunks! unsigned chunks = static_cast<unsigned>(ceil(static_cast<double>(displayedTriNum)/MAX_NUMBER_OF_ELEMENTS_PER_CHUNK)); unsigned chunkStart = 0; const ColorCompType* col = 0; for (unsigned k=0; k<chunks; ++k, chunkStart += MAX_NUMBER_OF_ELEMENTS_PER_CHUNK) { //virtual chunk size const unsigned chunkSize = k+1 < chunks ? MAX_NUMBER_OF_ELEMENTS_PER_CHUNK : (displayedTriNum % MAX_NUMBER_OF_ELEMENTS_PER_CHUNK); //vertices PointCoordinateType* _vertices = GetVertexBuffer(); for (unsigned n=0; n<chunkSize; n+=decimStep) { const CCLib::VerticesIndexes* ti = getTriangleVertIndexes(chunkStart + n); memcpy(_vertices,vertices->getPoint(ti->i1)->u,sizeof(PointCoordinateType)*3); _vertices+=3; memcpy(_vertices,vertices->getPoint(ti->i2)->u,sizeof(PointCoordinateType)*3); _vertices+=3; memcpy(_vertices,vertices->getPoint(ti->i3)->u,sizeof(PointCoordinateType)*3); _vertices+=3; } //scalar field if (glParams.showSF) { ColorCompType* _rgbColors = GetColorsBuffer(); assert(colorScale); for (unsigned n=0; n<chunkSize; n+=decimStep) { const CCLib::VerticesIndexes* ti = getTriangleVertIndexes(chunkStart + n); col = currentDisplayedScalarField->getValueColor(ti->i1); memcpy(_rgbColors,col,sizeof(ColorCompType)*3); _rgbColors += 3; col = currentDisplayedScalarField->getValueColor(ti->i2); memcpy(_rgbColors,col,sizeof(ColorCompType)*3); _rgbColors += 3; col = currentDisplayedScalarField->getValueColor(ti->i3); memcpy(_rgbColors,col,sizeof(ColorCompType)*3); _rgbColors += 3; } } //colors else if (glParams.showColors) { ColorCompType* _rgbColors = GetColorsBuffer(); for (unsigned n=0; n<chunkSize; n+=decimStep) { const CCLib::VerticesIndexes* ti = getTriangleVertIndexes(chunkStart + n); memcpy(_rgbColors,rgbColorsTable->getValue(ti->i1),sizeof(ColorCompType)*3); _rgbColors += 3; memcpy(_rgbColors,rgbColorsTable->getValue(ti->i2),sizeof(ColorCompType)*3); _rgbColors += 3; memcpy(_rgbColors,rgbColorsTable->getValue(ti->i3),sizeof(ColorCompType)*3); _rgbColors += 3; } } //normals if (glParams.showNorms) { PointCoordinateType* _normals = GetNormalsBuffer(); if (showTriNormals) { for (unsigned n=0; n<chunkSize; n+=decimStep) { CCVector3 Na, Nb, Nc; getTriangleNormals(chunkStart + n, Na, Nb, Nc); memcpy(_normals,Na.u,sizeof(PointCoordinateType)*3); _normals+=3; memcpy(_normals,Nb.u,sizeof(PointCoordinateType)*3); _normals+=3; memcpy(_normals,Nc.u,sizeof(PointCoordinateType)*3); _normals+=3; } } else { for (unsigned n=0; n<chunkSize; n+=decimStep) { const CCLib::VerticesIndexes* ti = getTriangleVertIndexes(chunkStart + n); memcpy(_normals,vertices->getPointNormal(ti->i1).u,sizeof(PointCoordinateType)*3); _normals+=3; memcpy(_normals,vertices->getPointNormal(ti->i2).u,sizeof(PointCoordinateType)*3); _normals+=3; memcpy(_normals,vertices->getPointNormal(ti->i3).u,sizeof(PointCoordinateType)*3); _normals+=3; } } } if (!showWired) { glDrawArrays(lodEnabled ? GL_POINTS : GL_TRIANGLES,0,(chunkSize/decimStep)*3); } else { glDrawElements(GL_LINES,(chunkSize/decimStep)*6,GL_UNSIGNED_INT,GetWireVertexIndexes()); } } //disable arrays glDisableClientState(GL_VERTEX_ARRAY); if (glParams.showNorms) glDisableClientState(GL_NORMAL_ARRAY); if (glParams.showSF || glParams.showColors) glDisableClientState(GL_COLOR_ARRAY); } else { //current vertex color const ColorCompType *col1=0,*col2=0,*col3=0; //current vertex normal const PointCoordinateType *N1=0,*N2=0,*N3=0; //current vertex texture coordinates float *Tx1=0,*Tx2=0,*Tx3=0; //loop on all triangles int lasMtlIndex = -1; if (showTextures) { //#define TEST_TEXTURED_BUNDLER_IMPORT #ifdef TEST_TEXTURED_BUNDLER_IMPORT glPushAttrib(GL_COLOR_BUFFER_BIT); glEnable(GL_BLEND); glBlendFunc(context.sourceBlend, context.destBlend); #endif glEnable(GL_TEXTURE_2D); } if (pushTriangleNames) glPushName(0); GLenum triangleDisplayType = lodEnabled ? GL_POINTS : showWired ? GL_LINE_LOOP : GL_TRIANGLES; glBegin(triangleDisplayType); //per-triangle normals const NormsIndexesTableType* triNormals = getTriNormsTable(); //materials const ccMaterialSet* materials = getMaterialSet(); for (unsigned n=0; n<triNum; ++n) { //current triangle vertices const CCLib::VerticesIndexes* tsi = getTriangleVertIndexes(n); //LOD: shall we display this triangle? if (n % decimStep) continue; if (visFiltering) { //we skip the triangle if at least one vertex is hidden if ((verticesVisibility->getValue(tsi->i1) != POINT_VISIBLE) || (verticesVisibility->getValue(tsi->i2) != POINT_VISIBLE) || (verticesVisibility->getValue(tsi->i3) != POINT_VISIBLE)) continue; } if (glParams.showSF) { assert(colorScale); col1 = currentDisplayedScalarField->getValueColor(tsi->i1); if (!col1) continue; col2 = currentDisplayedScalarField->getValueColor(tsi->i2); if (!col2) continue; col3 = currentDisplayedScalarField->getValueColor(tsi->i3); if (!col3) continue; } else if (glParams.showColors) { col1 = rgbColorsTable->getValue(tsi->i1); col2 = rgbColorsTable->getValue(tsi->i2); col3 = rgbColorsTable->getValue(tsi->i3); } if (glParams.showNorms) { if (showTriNormals) { assert(triNormals); int n1,n2,n3; getTriangleNormalIndexes(n,n1,n2,n3); N1 = (n1>=0 ? ccNormalVectors::GetNormal(triNormals->getValue(n1)).u : 0); N2 = (n1==n2 ? N1 : n1>=0 ? ccNormalVectors::GetNormal(triNormals->getValue(n2)).u : 0); N3 = (n1==n3 ? N1 : n3>=0 ? ccNormalVectors::GetNormal(triNormals->getValue(n3)).u : 0); } else { N1 = compressedNormals->getNormal(normalsIndexesTable->getValue(tsi->i1)).u; N2 = compressedNormals->getNormal(normalsIndexesTable->getValue(tsi->i2)).u; N3 = compressedNormals->getNormal(normalsIndexesTable->getValue(tsi->i3)).u; } } if (applyMaterials || showTextures) { assert(materials); int newMatlIndex = this->getTriangleMtlIndex(n); //do we need to change material? if (lasMtlIndex != newMatlIndex) { assert(newMatlIndex < static_cast<int>(materials->size())); glEnd(); if (showTextures) { GLuint texID = (newMatlIndex >= 0 ? context._win->getTextureID((*materials)[newMatlIndex]) : 0); assert(texID <= 0 || glIsTexture(texID)); glBindTexture(GL_TEXTURE_2D, texID); } //if we don't have any current material, we apply default one if (newMatlIndex >= 0) (*materials)[newMatlIndex]->applyGL(glParams.showNorms,false); else context.defaultMat->applyGL(glParams.showNorms,false); glBegin(triangleDisplayType); lasMtlIndex = newMatlIndex; } if (showTextures) { getTriangleTexCoordinates(n,Tx1,Tx2,Tx3); } } if (pushTriangleNames) { glEnd(); glLoadName(n); glBegin(triangleDisplayType); } else if (showWired) { glEnd(); glBegin(triangleDisplayType); } //vertex 1 if (N1) ccGL::Normal3v(N1); if (col1) glColor3ubv(col1); if (Tx1) glTexCoord2fv(Tx1); ccGL::Vertex3v(vertices->getPoint(tsi->i1)->u); //vertex 2 if (N2) ccGL::Normal3v(N2); if (col2) glColor3ubv(col2); if (Tx2) glTexCoord2fv(Tx2); ccGL::Vertex3v(vertices->getPoint(tsi->i2)->u); //vertex 3 if (N3) ccGL::Normal3v(N3); if (col3) glColor3ubv(col3); if (Tx3) glTexCoord2fv(Tx3); ccGL::Vertex3v(vertices->getPoint(tsi->i3)->u); } glEnd(); if (pushTriangleNames) glPopName(); if (showTextures) { #ifdef TEST_TEXTURED_BUNDLER_IMPORT glPopAttrib(); //GL_COLOR_BUFFER_BIT #endif glBindTexture(GL_TEXTURE_2D, 0); glDisable(GL_TEXTURE_2D); } } if (stipplingEnabled()) EnableGLStippleMask(false); if (colorMaterial) glDisable(GL_COLOR_MATERIAL); if (glParams.showNorms) { glDisable(GL_LIGHTING); glDisable((QGLFormat::openGLVersionFlags() & QGLFormat::OpenGL_Version_1_2 ? GL_RESCALE_NORMAL : GL_NORMALIZE)); } if (pushName) glPopName(); } }