GL::Boolean GL::isEnabled(Enum cap) { Boolean flag = glIsEnabled(cap); CHECK_GL_ERROR1(glIsEnabled, cap); return flag; }
void Set_Light() { glLoadIdentity(); switch (Current_Material) { case 0: { GLfloat light[] = { 1.0, 1.0, 1.0, 0.0 }; glLightfv(GL_LIGHT0, GL_POSITION, light); GLfloat ambvals[] = { 0.1f, 0.1f, 0.1f, 1.0f }; GLfloat diffvals[] = { 0.9f, 0.9f, 0.9f, 1.0f }; GLfloat specvals[] = { 0.8f, 0.8f, 0.8f, 1.0f }; glLightfv(GL_LIGHT0, GL_AMBIENT, ambvals); glLightfv(GL_LIGHT0, GL_DIFFUSE, diffvals); glLightfv(GL_LIGHT0, GL_SPECULAR, specvals); GLfloat lmodel_ambient[] = { 0.2, 0.2, 0.2, 1.0 }; glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient); glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE); if (glIsEnabled (GL_LIGHT1)) { glDisable(GL_LIGHT1); } if (glIsEnabled (GL_LIGHT2)) { glDisable(GL_LIGHT2); } } break; case 1: { GLfloat light[] = { 0.5, 0.5, 1.0, 0.0 }; glLightfv(GL_LIGHT0, GL_POSITION, light); GLfloat ambvals[] = { 0.0f, 0.0f, 0.0f, 1.0f }; GLfloat diffvals[] = { 0.5f, 0.5f, 0.5f, 1.0f }; GLfloat specvals[] = { 1.0f, 1.0f, 1.0f, 1.0f }; glLightfv(GL_LIGHT0, GL_AMBIENT, ambvals); glLightfv(GL_LIGHT0, GL_DIFFUSE, diffvals); glLightfv(GL_LIGHT0, GL_SPECULAR, specvals); GLfloat lmodel_ambient[] = { 0.5, 0.5, 0.5, 1.0 }; glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient); glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE); if (glIsEnabled (GL_LIGHT1)) { glDisable(GL_LIGHT1); } if (glIsEnabled (GL_LIGHT2)) { glDisable(GL_LIGHT2); } } break; case 2: { GLfloat light[] = { 0.0, 0.0, 1.0, 0.0 }; glLightfv(GL_LIGHT0, GL_POSITION, light); GLfloat ambvals[] = { 0.0f, 0.0f, 0.0f, 1.0f }; GLfloat diffvals[] = { 0.5f, 0.5f, 0.5f, 1.0f }; GLfloat specvals[] = { 0.0f, 0.0f, 0.0f, 1.0f }; glLightfv(GL_LIGHT0, GL_AMBIENT, ambvals); glLightfv(GL_LIGHT0, GL_DIFFUSE, diffvals); glLightfv(GL_LIGHT0, GL_SPECULAR, specvals); GLfloat lmodel_ambient[] = { 0.5, 0.5, 0.5, 1.0 }; glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient); glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE); if (glIsEnabled (GL_LIGHT1)) { glDisable(GL_LIGHT1); } if (glIsEnabled (GL_LIGHT2)) { glDisable(GL_LIGHT2); } } break; case 3: { GLfloat light[] = { 0.0, 0.0, 1.0, 0.0 }; glLightfv(GL_LIGHT0, GL_POSITION, light); GLfloat ambvals[] = { 0.0f, 0.0f, 0.0f, 1.0f }; GLfloat diffvals[] = { 0.7f, 0.7f, 0.7f, 1.0f }; GLfloat specvals[] = { 0.6f, 0.6f, 0.6f, 1.0f }; glLightfv(GL_LIGHT0, GL_AMBIENT, ambvals); glLightfv(GL_LIGHT0, GL_DIFFUSE, diffvals); glLightfv(GL_LIGHT0, GL_SPECULAR, specvals); GLfloat lmodel_ambient[] = { 0.5, 0.5, 0.5, 1.0 }; glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient); glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE); if (glIsEnabled (GL_LIGHT1)) { glDisable(GL_LIGHT1); } if (glIsEnabled (GL_LIGHT2)) { glDisable(GL_LIGHT2); } } break; case 4: { GLfloat light[] = { 1.0, 0.0, 1.0, 0.0 }; glLightfv(GL_LIGHT0, GL_POSITION, light); GLfloat light1[] = { 1.0, 1.0, 1.0, 0.0 }; glLightfv(GL_LIGHT1, GL_POSITION, light1); GLfloat light2[] = { 0.0, 1.0, 1.0, 0.0 }; glLightfv(GL_LIGHT2, GL_POSITION, light2); GLfloat specvals[] = { 0.3f, 0.3f, 0.3f, 1.0f }; GLfloat diffvals[] = { 0.4f, 0.0f, 0.0f, 0.0f }; glLightfv(GL_LIGHT0, GL_DIFFUSE, diffvals); glLightfv(GL_LIGHT0, GL_SPECULAR, specvals); GLfloat diffvals1[] = { 0.0f, 0.4f, 0.0f, 0.0f }; glLightfv(GL_LIGHT1, GL_DIFFUSE, diffvals1); glLightfv(GL_LIGHT1, GL_SPECULAR, specvals); GLfloat diffvals2[] = { 0.0f, 0.0f, 0.4f, 0.0f }; glLightfv(GL_LIGHT2, GL_DIFFUSE, diffvals2); glLightfv(GL_LIGHT2, GL_SPECULAR, specvals); glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE); glEnable(GL_LIGHT0); glEnable(GL_LIGHT1); glEnable(GL_LIGHT2); } break; } // Enable textures with specular color glLightModeli (GL_LIGHT_MODEL_COLOR_CONTROL, GL_SEPARATE_SPECULAR_COLOR); }
/** * @brief Dumps OpenGL state for debugging - typically every capability set with glEnable(). */ void R_DumpOpenGlState (void) { #define CAPABILITY( X ) {GL_ ## X, # X} /* List taken from here: http://www.khronos.org/opengles/sdk/1.1/docs/man/glIsEnabled.xml */ const struct { GLenum idx; const char * text; } openGLCaps[] = { CAPABILITY(ALPHA_TEST), CAPABILITY(BLEND), CAPABILITY(COLOR_ARRAY), CAPABILITY(COLOR_LOGIC_OP), CAPABILITY(COLOR_MATERIAL), CAPABILITY(CULL_FACE), CAPABILITY(DEPTH_TEST), CAPABILITY(DITHER), CAPABILITY(FOG), CAPABILITY(LIGHTING), CAPABILITY(LINE_SMOOTH), CAPABILITY(MULTISAMPLE), CAPABILITY(NORMAL_ARRAY), CAPABILITY(NORMALIZE), CAPABILITY(POINT_SMOOTH), CAPABILITY(POLYGON_OFFSET_FILL), CAPABILITY(RESCALE_NORMAL), CAPABILITY(SAMPLE_ALPHA_TO_COVERAGE), CAPABILITY(SAMPLE_ALPHA_TO_ONE), CAPABILITY(SAMPLE_COVERAGE), CAPABILITY(SCISSOR_TEST), CAPABILITY(STENCIL_TEST), CAPABILITY(VERTEX_ARRAY) }; #undef CAPABILITY char s[1024] = ""; GLint i; GLint maxTexUnits = 0; GLint activeTexUnit = 0; GLint activeClientTexUnit = 0; GLint activeTexId = 0; GLfloat texEnvMode = 0; const char * texEnvModeStr = "UNKNOWN"; GLfloat color[4]; for (i = 0; i < sizeof(openGLCaps)/sizeof(openGLCaps[0]); i++) { if (glIsEnabled(openGLCaps[i].idx)) { Q_strcat(s, sizeof(s), openGLCaps[i].text); Q_strcat(s, sizeof(s), " "); } } glGetFloatv(GL_CURRENT_COLOR, color); Com_Printf("OpenGL enabled caps: %s color %f %f %f %f \n", s, color[0], color[1], color[2], color[3]); glGetIntegerv(GL_ACTIVE_TEXTURE, &activeTexUnit); glGetIntegerv(GL_CLIENT_ACTIVE_TEXTURE, &activeClientTexUnit); glGetIntegerv(GL_MAX_TEXTURE_UNITS, &maxTexUnits); for (i = GL_TEXTURE0; i < GL_TEXTURE0 + maxTexUnits; i++) { glActiveTexture(i); glClientActiveTexture(i); strcpy(s, ""); if (glIsEnabled (GL_TEXTURE_2D)) strcat(s, "enabled, "); if (glIsEnabled (GL_TEXTURE_COORD_ARRAY)) strcat(s, "with texcoord array, "); if (i == activeTexUnit) strcat(s, "active, "); if (i == activeClientTexUnit) strcat(s, "client active, "); glGetIntegerv(GL_TEXTURE_BINDING_2D, &activeTexId); glGetTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, &texEnvMode); if (fabs(texEnvMode - GL_ADD) < 0.1f) texEnvModeStr = "ADD"; if (fabs(texEnvMode - GL_MODULATE) < 0.1f) texEnvModeStr = "MODULATE"; if (fabs(texEnvMode - GL_DECAL) < 0.1f) texEnvModeStr = "DECAL"; if (fabs(texEnvMode - GL_BLEND) < 0.1f) texEnvModeStr = "BLEND"; if (fabs(texEnvMode - GL_REPLACE) < 0.1f) texEnvModeStr = "REPLACE"; if (fabs(texEnvMode - GL_COMBINE) < 0.1f) texEnvModeStr = "COMBINE"; Com_Printf("Texunit: %d texID %d %s texEnv mode %s\n", i - GL_TEXTURE0, activeTexId, s, texEnvModeStr); } glActiveTexture(activeTexUnit); glClientActiveTexture(activeClientTexUnit); }
bool CCEGLViewProtocol::isScissorEnabled() { return (GL_FALSE == glIsEnabled(GL_SCISSOR_TEST)) ? false : true; }
void Draw_SV_Hitboxes(void) { if(!draw_sv_hitboxes_enable->value) return; GLint activeTextureARB = GL_TEXTURE0_ARB; GLboolean arbActive; if(g_Has_GL_ARB_multitexture) { glGetIntegerv(GL_ACTIVE_TEXTURE_ARB, &activeTextureARB); } if(GL_TEXTURE1_ARB == activeTextureARB) { arbActive = glIsEnabled(GL_TEXTURE_2D); glDisable(GL_TEXTURE_2D); glActiveTextureARB(GL_TEXTURE0_ARB); } GLfloat lineWidth; GLboolean depth = glIsEnabled(GL_DEPTH_TEST); GLboolean text = glIsEnabled(GL_TEXTURE_2D); glGetFloatv(GL_LINE_WIDTH, &lineWidth); glEnable(GL_DEPTH_TEST); glDisable(GL_TEXTURE_2D); glLineWidth(draw_sv_hitboxes_width->value); for(std::map<int, temp_edictboxes_t>::iterator it = tempEdicts.begin(); it != tempEdicts.end(); it++) { if(draw_sv_hitboxes_ignore1->value && 1 == it->first) { continue; } double red, green, blue; temp_edictboxes_t & tempEdict = it->second; if(tempEdict.isFresh) { red = hitboxesColorU[0]; green = hitboxesColorU[1]; blue = hitboxesColorU[2]; } else { red = hitboxesColor[0]; green = hitboxesColor[1]; blue = hitboxesColor[2]; } tempEdict.isFresh = false; for(std::list<temp_box_t>::iterator it2 = tempEdict.tempBoxes.begin(); it2 != tempEdict.tempBoxes.end(); it2++) { DrawBox(*it2, red, green, blue); } } glLineWidth(lineWidth); if(text) glEnable(GL_TEXTURE_2D); if(!depth) glDisable(GL_DEPTH_TEST); if(GL_TEXTURE1_ARB == activeTextureARB) { glActiveTextureARB(GL_TEXTURE1_ARB); if(arbActive) glEnable(GL_TEXTURE_2D); } }
void mesh3DS::draw(int textureID, bool pregenetateList){ if (m_specialTransform){ ++m_specialTransformTick; } assert(getNumFaces()!=0); if (!pregenetateList && !m_specialTransform) glCallList(glutGetWindow()==1?getListLeft():getListRight()); // uruchomienie rysowania ze swap'a else //currentMaterial.setList(glGenLists(1));// wygenerowanie miejsca dla jednej listy i zwr�cenie do niej uchwytu - mozliwe jest generowanie szeregu list, pod kolejnymi (+1) wartosciami uchwytow, wtedy metoda zwraca uchwyt do pierwszej z nich for (int window=1;window < (m_parentModel->getStereo()?3:2);window++){ if (m_parentModel->getStereo()) glutSetWindow(window); if (!m_specialTransform) { if (window==1)setListLeft(glGenLists(1)); else setListRight(glGenLists(1)); glNewList(window==1?getListLeft():getListRight(),GL_COMPILE); //definicja zawarto�ci listy("cube") } int face, numFaces, vertexIndex, texcoordIndex; GLuint materialFaces; //GL_FRONT or GL_FRONT_AND_BACK std::map<std::string, std::vector<ushort> >::iterator materialsIter; for(materialsIter=m_materialFaces.begin(); materialsIter!=m_materialFaces.end(); ++materialsIter){ const material3DS& currentMaterial = m_parentModel->getMaterial(materialsIter->first); // Bind texture map (if any) bool hasTextureMap = currentMaterial.hasTextureMap(); if (textureID) glBindTexture(GL_TEXTURE_2D, textureID); else if(hasTextureMap) glBindTexture(GL_TEXTURE_2D, currentMaterial.getTextureMapId()); else glBindTexture(GL_TEXTURE_2D, 0); const GLfloat *specular = currentMaterial.getSpecularColor(); float shininess = currentMaterial.getShininess(); float adjustedSpecular[4] = {specular[0]*shininess, specular[1]*shininess, specular[2]*shininess, 1}; glPushAttrib(GL_LIGHTING_BIT); if(currentMaterial.isTwoSided()){ glLightModeli(GL_LIGHT_MODEL_TWO_SIDE,1); materialFaces = GL_FRONT_AND_BACK; } else{ glLightModeli(GL_LIGHT_MODEL_TWO_SIDE,0); materialFaces = GL_FRONT; } // Apply material colors if(glIsEnabled(GL_LIGHTING)){ GLfloat matOne[4]={1,1,1,1}; GLfloat matLow[4]={0.20,0.20,0.20,0.20}; GLfloat matDiffuse[4]; // tworzenie diffuseColor z parametrem alfa pochodzacym z opacity memcpy(matDiffuse,currentMaterial.getDiffuseColor(),sizeof(float)*3); matDiffuse[3] = 1 - currentMaterial.getOpacity(); if(hasTextureMap){ //replace only color with texture, but keep lighting contribution glMaterialfv(materialFaces, GL_DIFFUSE, matOne); } else glMaterialfv(materialFaces, GL_DIFFUSE, matDiffuse); glMaterialfv(materialFaces, GL_AMBIENT, matLow); glMaterialfv(materialFaces, GL_SPECULAR, matLow); glMaterialf(materialFaces, GL_SHININESS, 2.0f); } else glColor3fv(currentMaterial.getDiffuseColor()); if (currentMaterial.getOpacity() < 1){ glEnable(GL_BLEND); glDepthMask(GL_FALSE); glBlendFunc(GL_SRC_COLOR, GL_ONE_MINUS_SRC_ALPHA); //glBlendFunc(GL_ONE_MINUS_SRC_ALPHA, GL_SRC_ALPHA); } std::vector<ushort> *currentMatFaces = &(materialsIter->second); numFaces = (int)currentMatFaces->size(); //number of faces in this material switch(m_drawMode){ case DRAW_IMMEDIATE_MODE: glBegin(GL_TRIANGLES); for(face=0; face<numFaces; face+=3){ if(hasTextureMap){ texcoordIndex = (*currentMatFaces)[face]*2; glTexCoord2f(m_texcoords[texcoordIndex], m_texcoords[texcoordIndex+1]); } vertexIndex = (*currentMatFaces)[face]*3; glNormal3f(m_normals[vertexIndex], m_normals[vertexIndex+1], m_normals[vertexIndex+2]); glVertex3f(m_vertices[vertexIndex]+calculateSpecialTransformX(vertexIndex), m_vertices[vertexIndex+1]+calculateSpecialTransformY(vertexIndex), m_vertices[vertexIndex+2]+calculateSpecialTransformZ(vertexIndex)); if(hasTextureMap){ texcoordIndex = (*currentMatFaces)[face+1]*2; glTexCoord2f(m_texcoords[texcoordIndex], m_texcoords[texcoordIndex+1]); } vertexIndex = (*currentMatFaces)[face+1]*3; glNormal3f(m_normals[vertexIndex], m_normals[vertexIndex+1], m_normals[vertexIndex+2]); glVertex3f(m_vertices[vertexIndex]+calculateSpecialTransformX(vertexIndex), m_vertices[vertexIndex+1]+calculateSpecialTransformY(vertexIndex), m_vertices[vertexIndex+2]+calculateSpecialTransformZ(vertexIndex)); if(hasTextureMap){ texcoordIndex = (*currentMatFaces)[face+2]*2; glTexCoord2f(m_texcoords[texcoordIndex], m_texcoords[texcoordIndex+1]); } vertexIndex = (*currentMatFaces)[face+2]*3; glNormal3f(m_normals[vertexIndex], m_normals[vertexIndex+1], m_normals[vertexIndex+2]); glVertex3f(m_vertices[vertexIndex]+calculateSpecialTransformX(vertexIndex), m_vertices[vertexIndex+1]+calculateSpecialTransformY(vertexIndex), m_vertices[vertexIndex+2]+calculateSpecialTransformZ(vertexIndex)); } glEnd(); break; case DRAW_VERTEX_ARRAY: glEnableClientState( GL_VERTEX_ARRAY ); glEnableClientState( GL_NORMAL_ARRAY ); if(hasTextureMap){ glTexCoordPointer( 2, GL_FLOAT, 0, &m_texcoords[0] ); glEnableClientState( GL_TEXTURE_COORD_ARRAY ); } glVertexPointer( 3, GL_FLOAT, 0, &m_vertices[0] ); glNormalPointer(GL_FLOAT, 0, &m_normals[0] ); glDrawElements(GL_TRIANGLES, numFaces, GL_UNSIGNED_SHORT, &(materialsIter->second[0])); glDisableClientState( GL_VERTEX_ARRAY ); glDisableClientState( GL_NORMAL_ARRAY ); if(hasTextureMap){ glDisableClientState( GL_TEXTURE_COORD_ARRAY ); } break; case DRAW_VBO: break; default: std::cout<<"[3DS] ERROR: Invalid mesh draw mode specified"<<std::endl; break; } // switch if (currentMaterial.getOpacity() <1){ glDepthMask(GL_TRUE); glDisable(GL_BLEND); } glPopAttrib(); // GL_LIGHTING_BIT } if (!m_specialTransform) glEndList(); //koniec definicji zawarto�ci listy }//for po window }
void drawSkybox(float size) { bool b1=glIsEnabled(GL_TEXTURE_2D); //new, we left the textures turned on, if it was turned on glDisable(GL_LIGHTING); //turn off lighting, when making the skybox //glDisable(GL_DEPTH_TEST); //turn off depth texting glEnable(GL_TEXTURE_2D); //and turn on texturing glBindTexture(GL_TEXTURE_2D,skybox[SKY_BACK]); //use the texture we want glColor3f(1.0,1.0,1.0); glBegin(GL_QUADS); //and draw a face //back face glTexCoord2f(0,0); //use the correct texture vector3d glVertex3f(size/2,size/2,size/2); //and a vertex glTexCoord2f(1,0); //and repeat it... glVertex3f(-size/2,size/2,size/2); glTexCoord2f(1,1); glVertex3f(-size/2,-size/2,size/2); glTexCoord2f(0,1); glVertex3f(size/2,-size/2,size/2); glEnd(); glBindTexture(GL_TEXTURE_2D,skybox[SKY_LEFT]); glBegin(GL_QUADS); //left face glTexCoord2f(0,0); glVertex3f(-size/2,size/2,size/2); glTexCoord2f(1,0); glVertex3f(-size/2,size/2,-size/2); glTexCoord2f(1,1); glVertex3f(-size/2,-size/2,-size/2); glTexCoord2f(0,1); glVertex3f(-size/2,-size/2,size/2); glEnd(); glBindTexture(GL_TEXTURE_2D,skybox[SKY_FRONT]); glBegin(GL_QUADS); //front face glTexCoord2f(1,0); glVertex3f(size/2,size/2,-size/2); glTexCoord2f(0,0); glVertex3f(-size/2,size/2,-size/2); glTexCoord2f(0,1); glVertex3f(-size/2,-size/2,-size/2); glTexCoord2f(1,1); glVertex3f(size/2,-size/2,-size/2); glEnd(); glBindTexture(GL_TEXTURE_2D,skybox[SKY_RIGHT]); glBegin(GL_QUADS); //right face glTexCoord2f(0,0); glVertex3f(size/2,size/2,-size/2); glTexCoord2f(1,0); glVertex3f(size/2,size/2,size/2); glTexCoord2f(1,1); glVertex3f(size/2,-size/2,size/2); glTexCoord2f(0,1); glVertex3f(size/2,-size/2,-size/2); glEnd(); glBindTexture(GL_TEXTURE_2D,skybox[SKY_TOP]); glBegin(GL_QUADS); //top face glTexCoord2f(1,0); glVertex3f(size/2,size/2,size/2); glTexCoord2f(0,0); glVertex3f(-size/2,size/2,size/2); glTexCoord2f(0,1); glVertex3f(-size/2,size/2,-size/2); glTexCoord2f(1,1); glVertex3f(size/2,size/2,-size/2); glEnd(); glBindTexture(GL_TEXTURE_2D,skybox[SKY_BOTTOM]); glBegin(GL_QUADS); //bottom face glTexCoord2f(1,1); glVertex3f(size/2,-size/2,size/2); glTexCoord2f(0,1); glVertex3f(-size/2,-size/2,size/2); glTexCoord2f(0,0); glVertex3f(-size/2,-size/2,-size/2); glTexCoord2f(1,0); glVertex3f(size/2,-size/2,-size/2); glEnd(); //glEnable(GL_LIGHTING); //turn everything back, which we turned on, and turn everything off, which we have turned on. //glEnable(GL_DEPTH_TEST); if(!b1) glDisable(GL_TEXTURE_2D); }
void drawConstraint(TransInfo *t) { TransCon *tc = &(t->con); if (!ELEM(t->spacetype, SPACE_VIEW3D, SPACE_IMAGE)) return; if (!(tc->mode & CON_APPLY)) return; if (t->flag & T_USES_MANIPULATOR) return; if (t->flag & T_NO_CONSTRAINT) return; /* nasty exception for Z constraint in camera view */ // TRANSFORM_FIX_ME // if((t->flag & T_OBJECT) && G.vd->camera==OBACT && G.vd->persp==V3D_CAMOB) // return; if (tc->drawExtra) { tc->drawExtra(t); } else { if (tc->mode & CON_SELECT) { float vec[3]; char col2[3] = {255,255,255}; int depth_test_enabled; convertViewVec(t, vec, (t->mval[0] - t->con.imval[0]), (t->mval[1] - t->con.imval[1])); add_v3_v3(vec, tc->center); drawLine(t, tc->center, tc->mtx[0], 'X', 0); drawLine(t, tc->center, tc->mtx[1], 'Y', 0); drawLine(t, tc->center, tc->mtx[2], 'Z', 0); glColor3ubv((GLubyte *)col2); depth_test_enabled = glIsEnabled(GL_DEPTH_TEST); if(depth_test_enabled) glDisable(GL_DEPTH_TEST); setlinestyle(1); glBegin(GL_LINE_STRIP); glVertex3fv(tc->center); glVertex3fv(vec); glEnd(); setlinestyle(0); if(depth_test_enabled) glEnable(GL_DEPTH_TEST); } if (tc->mode & CON_AXIS0) { drawLine(t, tc->center, tc->mtx[0], 'X', DRAWLIGHT); } if (tc->mode & CON_AXIS1) { drawLine(t, tc->center, tc->mtx[1], 'Y', DRAWLIGHT); } if (tc->mode & CON_AXIS2) { drawLine(t, tc->center, tc->mtx[2], 'Z', DRAWLIGHT); } } }
void LHBezierNode::draw(void) { float scale = CCDirector::sharedDirector()->getContentScaleFactor(); if(0.0f != LHSettings::sharedInstance()->customAlpha()) { glColor4f(color.origin.x, color.origin.y, color.size.width, color.size.height*LHSettings::sharedInstance()->customAlpha()); glPushMatrix(); glDisableClientState(GL_COLOR_ARRAY); if(NULL != texture) { glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, texture->getName()); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); int size = (int)trianglesHolder.size(); CCPoint* verts = new CCPoint[size* 3]; CCPoint* texcoords = new CCPoint[size* 3]; for(int k = 0; k < (int)trianglesHolder.size();++k) { std::vector<CCPoint> fix = trianglesHolder[k]; for(int j = 0; j < 3; ++j) { CCPoint pt = fix[j]; pt.x *= scale; pt.y *= scale; verts[k*3 + j] = pt; texcoords[k*3 + j].x = pt.x/imageSize.width; texcoords[k*3 + j].y = (winSize.height - pt.y)/imageSize.height; } } glTexCoordPointer(2, GL_FLOAT, 0, texcoords); glVertexPointer(2, GL_FLOAT, 0, verts); glDrawArrays(GL_TRIANGLES, 0, 3*size); bool wasBlend = glIsEnabled(GL_BLEND); glEnable(GL_BLEND); int oldBlendDST = 0; glGetIntegerv(GL_BLEND_DST, &oldBlendDST); int oldBlendSRC = 0; glGetIntegerv(GL_BLEND_SRC, &oldBlendSRC); for(int i = 0; i < blendingTextures.size(); ++i) { CCTexture2D* tex = blendingTextures[i].texture; if(NULL != tex) { glBlendFunc(blendingTextures[i].blendSource, blendingTextures[i].blendDestination); glBindTexture(GL_TEXTURE_2D, tex->getName()); if(blendingTextures[i].tile){ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); } glTexCoordPointer(2, GL_FLOAT, 0, texcoords); glVertexPointer(2, GL_FLOAT, 0, verts); glDrawArrays(GL_TRIANGLES, 0, 3*size); } } glBlendFunc(oldBlendSRC, oldBlendDST); if(!wasBlend) glDisable(GL_BLEND); delete [] verts; delete [] texcoords; } float oldLineWidth = 1.0f; glGetFloatv(GL_LINE_WIDTH, &oldLineWidth); glLineWidth(lineWidth); glDisable(GL_TEXTURE_2D); glDisableClientState(GL_TEXTURE_COORD_ARRAY); glColor4f(lineColor.origin.x, lineColor.origin.y, lineColor.size.width, lineColor.size.height*LHSettings::sharedInstance()->customAlpha()); CCPoint* line_verts = new CCPoint[linesHolder.size()]; for(int i = 0; i < (int)linesHolder.size(); i+=2) { CCPoint pt1 = linesHolder[i]; CCPoint pt2 = linesHolder[i+1]; line_verts[i] = pt1; line_verts[i+1] = pt2; } glVertexPointer(2, GL_FLOAT, 0, line_verts); glDrawArrays(GL_LINES, 0, linesHolder.size()); delete[] line_verts; glEnableClientState(GL_TEXTURE_COORD_ARRAY); glEnableClientState(GL_COLOR_ARRAY); glLineWidth(oldLineWidth); glEnable(GL_TEXTURE_2D); glPopMatrix(); } }
void ParticleSystem::drawParticles(const GLMatrix &transform) { int i, j, k, l; /* Check that the cache is big enough */ if (vertices_cache.size () < particles.size () * VERTEX_COMPONENTS) vertices_cache.resize (particles.size () * VERTEX_COMPONENTS); if (coords_cache.size () < particles.size () * COORD_COMPONENTS) coords_cache.resize (particles.size () * COORD_COMPONENTS); if (colors_cache.size () < particles.size () * COLOR_COMPONENTS) colors_cache.resize (particles.size () * COLOR_COMPONENTS); if (darken > 0) if (dcolors_cache.size () < particles.size () * COLOR_COMPONENTS) dcolors_cache.resize (particles.size () * COLOR_COMPONENTS); GLboolean glBlendEnabled = glIsEnabled (GL_BLEND); if (!glBlendEnabled) glEnable (GL_BLEND); if (tex) { glBindTexture (GL_TEXTURE_2D, tex); glEnable (GL_TEXTURE_2D); } i = j = k = l = 0; GLfloat w, h; GLfloat xMinusW, xPlusW, yMinusH, yPlusH; GLushort r, g, b, a, dark_a; /* for each particle, use two triangles to display it */ foreach (Particle &part, particles) { if (part.life > 0.0f) { w = part.width / 2.0f; h = part.height / 2.0f; r = part.r * 65535.0f; g = part.g * 65535.0f; b = part.b * 65535.0f; a = part.life * part.a * 65535.0f; dark_a = part.life * part.a * 65535.0f * darken; w += w * part.w_mod * part.life; h += h * part.h_mod * part.life; xMinusW = part.x - w; xPlusW = part.x + w; yMinusH = part.y - h; yPlusH = part.y + h; //first triangle vertices_cache[i + 0] = xMinusW; vertices_cache[i + 1] = yMinusH; vertices_cache[i + 2] = part.z; vertices_cache[i + 3] = xMinusW; vertices_cache[i + 4] = yPlusH; vertices_cache[i + 5] = part.z; vertices_cache[i + 6] = xPlusW; vertices_cache[i + 7] = yPlusH; vertices_cache[i + 8] = part.z; //second triangle vertices_cache[i + 9] = xPlusW; vertices_cache[i + 10] = yPlusH; vertices_cache[i + 11] = part.z; vertices_cache[i + 12] = xPlusW; vertices_cache[i + 13] = yMinusH; vertices_cache[i + 14] = part.z; vertices_cache[i + 15] = xMinusW; vertices_cache[i + 16] = yMinusH; vertices_cache[i + 17] = part.z; i += 18; coords_cache[j + 0] = 0.0; coords_cache[j + 1] = 0.0; coords_cache[j + 2] = 0.0; coords_cache[j + 3] = 1.0; coords_cache[j + 4] = 1.0; coords_cache[j + 5] = 1.0; //second coords_cache[j + 6] = 1.0; coords_cache[j + 7] = 1.0; coords_cache[j + 8] = 1.0; coords_cache[j + 9] = 0.0; coords_cache[j + 10] = 0.0; coords_cache[j + 11] = 0.0; j += 12; colors_cache[k + 0] = r; colors_cache[k + 1] = g; colors_cache[k + 2] = b; colors_cache[k + 3] = a; colors_cache[k + 4] = r; colors_cache[k + 5] = g; colors_cache[k + 6] = b; colors_cache[k + 7] = a; colors_cache[k + 8] = r; colors_cache[k + 9] = g; colors_cache[k + 10] = b; colors_cache[k + 11] = a; //second colors_cache[k + 12] = r; colors_cache[k + 13] = g; colors_cache[k + 14] = b; colors_cache[k + 15] = a; colors_cache[k + 16] = r; colors_cache[k + 17] = g; colors_cache[k + 18] = b; colors_cache[k + 19] = a; colors_cache[k + 20] = r; colors_cache[k + 21] = g; colors_cache[k + 22] = b; colors_cache[k + 23] = a; k += 24; if (darken > 0) { dcolors_cache[l + 0] = r; dcolors_cache[l + 1] = g; dcolors_cache[l + 2] = b; dcolors_cache[l + 3] = dark_a; dcolors_cache[l + 4] = r; dcolors_cache[l + 5] = g; dcolors_cache[l + 6] = b; dcolors_cache[l + 7] = dark_a; dcolors_cache[l + 8] = r; dcolors_cache[l + 9] = g; dcolors_cache[l + 10] = b; dcolors_cache[l + 11] = dark_a; //second dcolors_cache[l + 12] = r; dcolors_cache[l + 13] = g; dcolors_cache[l + 14] = b; dcolors_cache[l + 15] = dark_a; dcolors_cache[l + 16] = r; dcolors_cache[l + 17] = g; dcolors_cache[l + 18] = b; dcolors_cache[l + 19] = dark_a; dcolors_cache[l + 20] = r; dcolors_cache[l + 21] = g; dcolors_cache[l + 22] = b; dcolors_cache[l + 23] = dark_a; l += 24; } } } GLVertexBuffer *stream = GLVertexBuffer::streamingBuffer (); if (darken > 0) { glBlendFunc (GL_ZERO, GL_ONE_MINUS_SRC_ALPHA); stream->begin (GL_TRIANGLES); stream->addVertices (i / 3, &vertices_cache[0]); stream->addTexCoords (0, j / 2, &coords_cache[0]); stream->addColors (l / 4, &dcolors_cache[0]); if (stream->end ()) stream->render (transform); } /* draw particles */ glBlendFunc (GL_SRC_ALPHA, blendMode); stream->begin (GL_TRIANGLES); stream->addVertices (i / 3, &vertices_cache[0]); stream->addTexCoords (0, j / 2, &coords_cache[0]); stream->addColors (k / 4, &colors_cache[0]); if (stream->end ()) stream->render (transform); glBlendFunc (GL_ONE, GL_ONE_MINUS_SRC_ALPHA); glDisable (GL_TEXTURE_2D); /* only disable blending if it was disabled before */ if (!glBlendEnabled) glDisable (GL_BLEND); }
bool FireScreen::glPaintOutput (const GLScreenPaintAttrib &attrib, const GLMatrix &transform, const CompRegion ®ion, CompOutput *output, unsigned int mask) { bool status = gScreen->glPaintOutput (attrib, transform, region, output, mask); if ((!init && ps.active) || brightness < 1.0) { GLMatrix sTransform = transform; sTransform.toScreenSpace (output, -DEFAULT_Z_CAMERA); if (brightness < 1.0) { /* cover the screen with a rectangle and darken it * (coded as two GL_TRIANGLES for GLES compatibility) */ GLfloat vertices[18]; GLushort colors[24]; vertices[0] = (GLfloat)output->region ()->extents.x1; vertices[1] = (GLfloat)output->region ()->extents.y1; vertices[2] = 0.0f; vertices[3] = (GLfloat)output->region ()->extents.x1; vertices[4] = (GLfloat)output->region ()->extents.y2; vertices[5] = 0.0f; vertices[6] = (GLfloat)output->region ()->extents.x2; vertices[7] = (GLfloat)output->region ()->extents.y2; vertices[8] = 0.0f; vertices[9] = (GLfloat)output->region ()->extents.x2; vertices[10] = (GLfloat)output->region ()->extents.y2; vertices[11] = 0.0f; vertices[12] = (GLfloat)output->region ()->extents.x2; vertices[13] = (GLfloat)output->region ()->extents.y1; vertices[14] = 0.0f; vertices[15] = (GLfloat)output->region ()->extents.x1; vertices[16] = (GLfloat)output->region ()->extents.y1; vertices[17] = 0.0f; for (int i = 0; i <= 5; ++i) { colors[i*4+0] = 0; colors[i*4+1] = 0; colors[i*4+2] = 0; colors[i*4+3] = (1.0 - brightness) * 65535.0f; } GLVertexBuffer *stream = GLVertexBuffer::streamingBuffer (); GLboolean glBlendEnabled = glIsEnabled (GL_BLEND); if (!glBlendEnabled) glEnable (GL_BLEND); stream->begin (GL_TRIANGLES); stream->addVertices (6, vertices); stream->addColors (6, colors); if (stream->end ()) stream->render (sTransform); /* only disable blending if it was already disabled */ if (!glBlendEnabled) glDisable (GL_BLEND); } if (!init && ps.active) ps.drawParticles (sTransform); } return status; }
static int create_texture(void) { GLuint tex; float *ptr; /* Generate mipmap level 0 */ tex = piglit_rgbw_texture(GL_RGBA, TEX_WIDTH, TEX_WIDTH, GL_FALSE, GL_TRUE, GL_FLOAT); glBindTexture(GL_TEXTURE_2D, tex); if (!piglit_check_gl_error(GL_NO_ERROR)) piglit_report_result(PIGLIT_FAIL); /* Go into appropriate transform feedback or discard state */ if (discard) glEnable(GL_RASTERIZER_DISCARD); if (buffer || prims_written) { float buffer[4096]; buffer[0] = 12345.0; glBindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER, xfb_buf); glBufferData(GL_TRANSFORM_FEEDBACK_BUFFER, sizeof(buffer), buffer, GL_STREAM_READ); glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, 0, xfb_buf); glUseProgram(xfb_prog); glBeginTransformFeedback(GL_POINTS); } if (prims_written) { glBeginQuery(GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN, prims_written_query); } if (prims_generated) { glBeginQuery(GL_PRIMITIVES_GENERATED, prims_generated_query); } /* Ask the implementation to generate the remaining mipmap levels. */ glGenerateMipmapEXT(GL_TEXTURE_2D); if (!piglit_check_gl_error(0)) piglit_report_result(PIGLIT_FAIL); /* Check state */ if (discard) { if (!glIsEnabled(GL_RASTERIZER_DISCARD)) { printf("GL_RASTERIZER_DISCARD state not restored " "after glGenerateMipmapEXT\n"); piglit_report_result(PIGLIT_FAIL); } glDisable(GL_RASTERIZER_DISCARD); } if (buffer || prims_written) { glEndTransformFeedback(); glUseProgram(0); } if (buffer) { ptr = glMapBuffer(GL_TRANSFORM_FEEDBACK_BUFFER_EXT, GL_READ_ONLY); if (ptr[0] != 12345.0) { printf("Transform feedback buffer was overwritten " "during glGenerateMipmapEXT\n"); piglit_report_result(PIGLIT_FAIL); } } if (prims_written) { GLuint result; glEndQuery(GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN); glGetQueryObjectuiv(prims_written_query, GL_QUERY_RESULT, &result); if (result != 0) { printf("PRIMITIVES_WRITTEN counter was incremented " "during glGenerateMipmapEXT\n"); piglit_report_result(PIGLIT_FAIL); } } if (prims_generated) { GLuint result; glEndQuery(GL_PRIMITIVES_GENERATED); glGetQueryObjectuiv(prims_generated_query, GL_QUERY_RESULT, &result); if (result != 0) { printf("PRIMITIVES_GENERATED counter was incremented " "during glGenerateMipmapEXT\n"); piglit_report_result(PIGLIT_FAIL); } } return tex; }
/*! * \qmlmethod string GLStateDumpExt::getGLStateDump(stateDumpEnums options) * \return OpenGL driver state with given options as a human readable string that can be printed. * Optional paremeter \a options may contain bitfields masked together from following options: * \list * \li \c{GLStateDumpExt.DUMP_BASIC_ONLY} Includes only very basic OpenGL state information. * \li \c{GLStateDumpExt.DUMP_VERTEX_ATTRIB_ARRAYS_BIT} Includes all vertex attribute array * information. * \li \c{GLStateDumpExt.DUMP_VERTEX_ATTRIB_ARRAYS_BUFFERS_BIT} Includes size and type * from all currently active vertex attribute arrays (including the currently bound element array) * to verify that there are actual values in the array. * \li \c{GLStateDumpExt.DUMP_FULL} Includes everything. * \endlist */ QString CanvasGLStateDump::getGLStateDump(CanvasGLStateDump::stateDumpEnums options) { #if !defined(QT_OPENGL_ES_2) GLint drawFramebuffer; GLint readFramebuffer; GLboolean polygonOffsetLineEnabled; GLboolean polygonOffsetPointEnabled; GLint boundVertexArray; #endif QString stateDumpStr; GLint renderbuffer; GLfloat clearColor[4]; GLfloat clearDepth; GLboolean isBlendingEnabled = glIsEnabled(GL_BLEND); GLboolean isDepthTestEnabled = glIsEnabled(GL_DEPTH_TEST); GLint depthFunc; GLboolean isDepthWriteEnabled; GLint currentProgram; GLint *vertexAttribArrayEnabledStates = new GLint[m_maxVertexAttribs]; GLint *vertexAttribArrayBoundBuffers = new GLint[m_maxVertexAttribs]; GLint *vertexAttribArraySizes = new GLint[m_maxVertexAttribs]; GLint *vertexAttribArrayTypes = new GLint[m_maxVertexAttribs]; GLint *vertexAttribArrayNormalized = new GLint[m_maxVertexAttribs]; GLint *vertexAttribArrayStrides = new GLint[m_maxVertexAttribs]; GLint activeTexture; GLint texBinding2D; GLint arrayBufferBinding; GLint frontFace; GLboolean isCullFaceEnabled = glIsEnabled(GL_CULL_FACE); GLint cullFaceMode; GLint blendEquationRGB; GLint blendEquationAlpha; GLint blendDestAlpha; GLint blendDestRGB; GLint blendSrcAlpha; GLint blendSrcRGB; GLint scissorBox[4]; GLboolean isScissorTestEnabled = glIsEnabled(GL_SCISSOR_TEST); GLint boundElementArrayBuffer; GLboolean polygonOffsetFillEnabled; GLfloat polygonOffsetFactor; GLfloat polygonOffsetUnits; #if !defined(QT_OPENGL_ES_2) if (!m_isOpenGLES2) { glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &drawFramebuffer); glGetIntegerv(GL_READ_FRAMEBUFFER_BINDING, &readFramebuffer); glGetBooleanv(GL_POLYGON_OFFSET_LINE, &polygonOffsetLineEnabled); glGetBooleanv(GL_POLYGON_OFFSET_POINT, &polygonOffsetPointEnabled); glGetIntegerv(GL_VERTEX_ARRAY_BINDING, &boundVertexArray); } #endif glGetBooleanv(GL_DEPTH_WRITEMASK, &isDepthWriteEnabled); glGetIntegerv(GL_RENDERBUFFER_BINDING, &renderbuffer); glGetFloatv(GL_COLOR_CLEAR_VALUE, clearColor); glGetFloatv(GL_DEPTH_CLEAR_VALUE, &clearDepth); glGetIntegerv(GL_DEPTH_FUNC, &depthFunc); glGetBooleanv(GL_POLYGON_OFFSET_FILL, &polygonOffsetFillEnabled); glGetFloatv(GL_POLYGON_OFFSET_FACTOR, &polygonOffsetFactor); glGetFloatv(GL_POLYGON_OFFSET_UNITS, &polygonOffsetUnits); glGetIntegerv(GL_CURRENT_PROGRAM, ¤tProgram); glGetIntegerv(GL_ACTIVE_TEXTURE, &activeTexture); glGetIntegerv(GL_TEXTURE_BINDING_2D, &texBinding2D ); glGetIntegerv(GL_FRONT_FACE, &frontFace); glGetIntegerv(GL_CULL_FACE_MODE, &cullFaceMode); glGetIntegerv(GL_BLEND_EQUATION_RGB, &blendEquationRGB); glGetIntegerv(GL_BLEND_EQUATION_ALPHA, &blendEquationAlpha); glGetIntegerv(GL_BLEND_DST_ALPHA, &blendDestAlpha); glGetIntegerv(GL_BLEND_DST_RGB, &blendDestRGB); glGetIntegerv(GL_BLEND_SRC_ALPHA, &blendSrcAlpha); glGetIntegerv(GL_BLEND_SRC_RGB, &blendSrcRGB); glGetIntegerv(GL_SCISSOR_BOX, scissorBox); glGetIntegerv(GL_ELEMENT_ARRAY_BUFFER_BINDING, &boundElementArrayBuffer); glGetIntegerv(GL_ARRAY_BUFFER_BINDING, &arrayBufferBinding); #if !defined(QT_OPENGL_ES_2) if (!m_isOpenGLES2) { stateDumpStr.append("GL_DRAW_FRAMEBUFFER_BINDING....."); stateDumpStr.append(QString::number(drawFramebuffer)); stateDumpStr.append("\n"); stateDumpStr.append("GL_READ_FRAMEBUFFER_BINDING....."); stateDumpStr.append(QString::number(readFramebuffer)); stateDumpStr.append("\n"); } #endif stateDumpStr.append("GL_RENDERBUFFER_BINDING........."); stateDumpStr.append(QString::number(renderbuffer)); stateDumpStr.append("\n"); stateDumpStr.append("GL_SCISSOR_TEST................."); stateDumpStr.append(BOOL_TO_STR(isScissorTestEnabled)); stateDumpStr.append("\n"); stateDumpStr.append("GL_SCISSOR_BOX.................."); stateDumpStr.append(QString::number(scissorBox[0])); stateDumpStr.append(", "); stateDumpStr.append(QString::number(scissorBox[1])); stateDumpStr.append(", "); stateDumpStr.append(QString::number(scissorBox[2])); stateDumpStr.append(", "); stateDumpStr.append(QString::number(scissorBox[3])); stateDumpStr.append("\n"); stateDumpStr.append("GL_COLOR_CLEAR_VALUE............"); stateDumpStr.append("r:"); stateDumpStr.append(QString::number(clearColor[0])); stateDumpStr.append(" g:"); stateDumpStr.append(QString::number(clearColor[1])); stateDumpStr.append(" b:"); stateDumpStr.append(QString::number(clearColor[2])); stateDumpStr.append(" a:"); stateDumpStr.append(QString::number(clearColor[3])); stateDumpStr.append("\n"); stateDumpStr.append("GL_DEPTH_CLEAR_VALUE............"); stateDumpStr.append(QString::number(clearDepth)); stateDumpStr.append("\n"); stateDumpStr.append("GL_BLEND........................"); stateDumpStr.append(BOOL_TO_STR(isBlendingEnabled)); stateDumpStr.append("\n"); stateDumpStr.append("GL_BLEND_EQUATION_RGB..........."); stateDumpStr.append(m_map->lookUp(blendEquationRGB)); stateDumpStr.append("\n"); stateDumpStr.append("GL_BLEND_EQUATION_ALPHA........."); stateDumpStr.append(m_map->lookUp(blendEquationAlpha)); stateDumpStr.append("\n"); stateDumpStr.append("GL_DEPTH_TEST..................."); stateDumpStr.append(BOOL_TO_STR(isDepthTestEnabled)); stateDumpStr.append("\n"); stateDumpStr.append("GL_DEPTH_FUNC..................."); stateDumpStr.append(m_map->lookUp(depthFunc)); stateDumpStr.append("\n"); stateDumpStr.append("GL_DEPTH_WRITEMASK.............."); stateDumpStr.append(BOOL_TO_STR(isDepthWriteEnabled)); stateDumpStr.append("\n"); stateDumpStr.append("GL_POLYGON_OFFSET_FILL.........."); stateDumpStr.append(BOOL_TO_STR(polygonOffsetFillEnabled)); stateDumpStr.append("\n"); #if !defined(QT_OPENGL_ES_2) if (!m_isOpenGLES2) { stateDumpStr.append("GL_POLYGON_OFFSET_LINE.........."); stateDumpStr.append(BOOL_TO_STR(polygonOffsetLineEnabled)); stateDumpStr.append("\n"); stateDumpStr.append("GL_POLYGON_OFFSET_POINT........."); stateDumpStr.append(BOOL_TO_STR(polygonOffsetPointEnabled)); stateDumpStr.append("\n"); } #endif stateDumpStr.append("GL_POLYGON_OFFSET_FACTOR........"); stateDumpStr.append(QString::number(polygonOffsetFactor)); stateDumpStr.append("\n"); stateDumpStr.append("GL_POLYGON_OFFSET_UNITS........."); stateDumpStr.append(QString::number(polygonOffsetUnits)); stateDumpStr.append("\n"); stateDumpStr.append("GL_CULL_FACE...................."); stateDumpStr.append(BOOL_TO_STR(isCullFaceEnabled)); stateDumpStr.append("\n"); stateDumpStr.append("GL_CULL_FACE_MODE..............."); stateDumpStr.append(m_map->lookUp(cullFaceMode)); stateDumpStr.append("\n"); stateDumpStr.append("GL_FRONT_FACE..................."); stateDumpStr.append(m_map->lookUp(frontFace)); stateDumpStr.append("\n"); stateDumpStr.append("GL_CURRENT_PROGRAM.............."); stateDumpStr.append(QString::number(currentProgram)); stateDumpStr.append("\n"); stateDumpStr.append("GL_ACTIVE_TEXTURE..............."); stateDumpStr.append(m_map->lookUp(activeTexture)); stateDumpStr.append("\n"); stateDumpStr.append("GL_TEXTURE_BINDING_2D..........."); stateDumpStr.append(QString::number(texBinding2D)); stateDumpStr.append("\n"); stateDumpStr.append("GL_ELEMENT_ARRAY_BUFFER_BINDING."); stateDumpStr.append(QString::number(boundElementArrayBuffer)); stateDumpStr.append("\n"); stateDumpStr.append("GL_ARRAY_BUFFER_BINDING........."); stateDumpStr.append(QString::number(arrayBufferBinding)); stateDumpStr.append("\n"); #if !defined(QT_OPENGL_ES_2) if (!m_isOpenGLES2) { stateDumpStr.append("GL_VERTEX_ARRAY_BINDING........."); stateDumpStr.append(QString::number(boundVertexArray)); stateDumpStr.append("\n"); } #endif if (options && DUMP_VERTEX_ATTRIB_ARRAYS_BIT) { for (int i = 0; i < m_maxVertexAttribs; i++) { glGetVertexAttribiv(i, GL_VERTEX_ATTRIB_ARRAY_ENABLED, &vertexAttribArrayEnabledStates[i]); glGetVertexAttribiv(i, GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING, &vertexAttribArrayBoundBuffers[i]); glGetVertexAttribiv(i, GL_VERTEX_ATTRIB_ARRAY_SIZE, &vertexAttribArraySizes[i]); glGetVertexAttribiv(i, GL_VERTEX_ATTRIB_ARRAY_TYPE, &vertexAttribArrayTypes[i]); glGetVertexAttribiv(i, GL_VERTEX_ATTRIB_ARRAY_NORMALIZED, &vertexAttribArrayNormalized[i]); glGetVertexAttribiv(i, GL_VERTEX_ATTRIB_ARRAY_STRIDE, &vertexAttribArrayStrides[i]); } for (int i = 0; i < m_maxVertexAttribs; i++) { stateDumpStr.append("GL_VERTEX_ATTRIB_ARRAY_"); stateDumpStr.append(QString::number(i)); stateDumpStr.append("\n"); stateDumpStr.append("GL_VERTEX_ATTRIB_ARRAY_ENABLED........."); stateDumpStr.append(BOOL_TO_STR(vertexAttribArrayEnabledStates[i])); stateDumpStr.append("\n"); stateDumpStr.append("GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING.."); stateDumpStr.append(QString::number(vertexAttribArrayBoundBuffers[i])); stateDumpStr.append("\n"); stateDumpStr.append("GL_VERTEX_ATTRIB_ARRAY_SIZE............"); stateDumpStr.append(QString::number(vertexAttribArraySizes[i])); stateDumpStr.append("\n"); stateDumpStr.append("GL_VERTEX_ATTRIB_ARRAY_TYPE............"); stateDumpStr.append(m_map->lookUp(vertexAttribArrayTypes[i])); stateDumpStr.append("\n"); stateDumpStr.append("GL_VERTEX_ATTRIB_ARRAY_NORMALIZED......"); stateDumpStr.append(QString::number(vertexAttribArrayNormalized[i])); stateDumpStr.append("\n"); stateDumpStr.append("GL_VERTEX_ATTRIB_ARRAY_STRIDE.........."); stateDumpStr.append(QString::number(vertexAttribArrayStrides[i])); stateDumpStr.append("\n"); } } if (options && DUMP_VERTEX_ATTRIB_ARRAYS_BUFFERS_BIT) { if (boundElementArrayBuffer != 0) { stateDumpStr.append("GL_ELEMENT_ARRAY_BUFFER................"); stateDumpStr.append(QString::number(boundElementArrayBuffer)); stateDumpStr.append("\n"); stateDumpStr.append(getGLArrayObjectDump(GL_ELEMENT_ARRAY_BUFFER, boundElementArrayBuffer, GL_UNSIGNED_SHORT)); } for (int i = 0; i < m_maxVertexAttribs; i++) { if (vertexAttribArrayEnabledStates[i]) { stateDumpStr.append("GL_ARRAY_BUFFER........................"); stateDumpStr.append(QString::number(vertexAttribArrayBoundBuffers[i])); stateDumpStr.append("\n"); stateDumpStr.append(getGLArrayObjectDump(GL_ARRAY_BUFFER, vertexAttribArrayBoundBuffers[i], vertexAttribArrayTypes[i])); } } } delete[] vertexAttribArrayEnabledStates; delete[] vertexAttribArrayBoundBuffers; delete[] vertexAttribArraySizes; delete[] vertexAttribArrayTypes; delete[] vertexAttribArrayNormalized; delete[] vertexAttribArrayStrides; return stateDumpStr; }
/*----------------------------------------------------------------------------- Name : btgRender Description : renders the background. assumes modelview already set Inputs : Outputs : Return : ----------------------------------------------------------------------------*/ void btgRender() { udword nStar; sdword lightOn, index; GLboolean texOn, blendOn, depthOn; udword* dlast; udword* dnext; static sdword lastFade = 255; #if MR_KEYBOARD_CHEATS extern bool gMosaic; #endif if (btgHead == NULL) { #ifdef _WIN32 btgLoad("BTG\\default.btg"); #else btgLoad("BTG/default.btg"); #endif } #if MR_KEYBOARD_CHEATS glShadeModel(gMosaic ? GL_FLAT : GL_SMOOTH); #else glShadeModel(GL_SMOOTH); #endif glGetFloatv(GL_COLOR_CLEAR_VALUE, _bgColor); for (index = 0; index < 4; index++) { _bgByte[index] = (GLubyte)(_bgColor[index] * 255.0f); } dnext = (udword*)_bgByte; dlast = (udword*)lastbg; depthOn = glIsEnabled(GL_DEPTH_TEST); lightOn = rndLightingEnable(FALSE); texOn = glIsEnabled(GL_TEXTURE_2D); blendOn = glIsEnabled(GL_BLEND); glDisable(GL_DEPTH_TEST); glDisable(GL_CULL_FACE); glDisable(GL_TEXTURE_2D); glEnable(GL_BLEND); rndAdditiveBlends(FALSE); if (useVBO) glBindBuffer(GL_ARRAY_BUFFER, vboTransVerts); //polys if (btgFade != lastFade || *dnext != *dlast) { if (btgFade < 0) { btgFade = 255; } #ifndef _WIN32_FIXME btgColorVertices(); #endif if (useVBO) glBufferData(GL_ARRAY_BUFFER, btgHead->numVerts * sizeof(btgTransVertex), btgTransVerts, GL_STATIC_DRAW); *dlast = *dnext; lastFade = btgFade; } //use DrawElements to render the bg polys glEnableClientState(GL_COLOR_ARRAY); glEnableClientState(GL_VERTEX_ARRAY); if (useVBO) { glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(btgTransVertex), 0); glVertexPointer(3, GL_FLOAT, sizeof(btgTransVertex), (GLvoid*)4); glBindBuffer(GL_ARRAY_BUFFER, 0); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vboIndices); glDrawElements(GL_TRIANGLES, 3 * btgHead->numPolys, GL_UNSIGNED_SHORT, 0); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); } else { glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(btgTransVertex), (GLubyte*)btgTransVerts); glVertexPointer(3, GL_FLOAT, sizeof(btgTransVertex), ((GLubyte*)btgTransVerts) + 4); glDrawElements(GL_TRIANGLES, 3 * btgHead->numPolys, GL_UNSIGNED_SHORT, btgIndices); } glDisableClientState(GL_COLOR_ARRAY); //stars rndPerspectiveCorrection(FALSE); rndAdditiveBlends(TRUE); trClearCurrent(); glEnable(GL_TEXTURE_2D); rndTextureEnvironment(RTE_Modulate); glEnableClientState(GL_TEXTURE_COORD_ARRAY); if (useVBO) { glBindBuffer(GL_ARRAY_BUFFER, vboTransStars); glVertexPointer(3, GL_FLOAT, sizeof(GLfloat) * 5, 0); glTexCoordPointer(2, GL_FLOAT, sizeof(GLfloat) * 5, (GLubyte*)sizeof(vector)); glBindBuffer(GL_ARRAY_BUFFER, 0); } else { glVertexPointer(3, GL_FLOAT, sizeof(GLfloat) * 5, (GLubyte*)btgTransStars); glTexCoordPointer(2, GL_FLOAT, sizeof(GLfloat) * 5, ((GLubyte*)btgTransStars) + sizeof(vector)); } for (nStar = 0; nStar < btgHead->numStars; nStar++) { if (btgStars[nStar].glhandle) { glColor4ub((GLubyte)btgStars[nStar].red, (GLubyte)btgStars[nStar].green, (GLubyte)btgStars[nStar].blue, (GLubyte)btgStars[nStar].alpha); glBindTexture(GL_TEXTURE_2D, btgStars[nStar].glhandle); glDrawArrays(GL_TRIANGLE_STRIP, nStar * 4, 4); } } glDisableClientState(GL_TEXTURE_COORD_ARRAY); glDisableClientState(GL_VERTEX_ARRAY); glDisable(GL_BLEND); rndAdditiveBlends(FALSE); rndLightingEnable(lightOn); if (texOn) glEnable(GL_TEXTURE_2D); if (blendOn) { glEnable(GL_BLEND); } else { glDisable(GL_BLEND); } glEnable(GL_CULL_FACE); if (depthOn) { glEnable(GL_DEPTH_TEST); } else { glDisable(GL_DEPTH_TEST); } }
void GLLabel::DeferredRenderer::draw(void) { /* Bail out if no labels were gathered: */ if(gatheredLabels.empty()) return; /* Save and set up OpenGL state: */ GLbitfield attribPushMask=GL_TEXTURE_BIT; bool lightingOn=glIsEnabled(GL_LIGHTING); if(lightingOn) attribPushMask|=GL_LIGHTING_BIT; glPushAttrib(attribPushMask); glEnable(GL_TEXTURE_2D); if(lightingOn) { glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL,GL_SEPARATE_SPECULAR_COLOR); glTexEnvMode(GLTexEnvEnums::TEXTURE_ENV,GLTexEnvEnums::MODULATE); } else glTexEnvMode(GLTexEnvEnums::TEXTURE_ENV,GLTexEnvEnums::REPLACE); /* Draw each gathered label: */ for(std::vector<const GLLabel*>::iterator lIt=gatheredLabels.begin();lIt!=gatheredLabels.end();++lIt) { const GLLabel* l=*lIt; /* Retrieve the context data item: */ GLLabel::DataItem* dataItem=contextData.retrieveDataItem<GLLabel::DataItem>(*lIt); /* Bind the label texture: */ glBindTexture(GL_TEXTURE_2D,dataItem->textureObjectId); /* Check if the texture object needs to be updated: */ if(dataItem->version!=l->version) { /* Upload the string's texture image: */ l->font->uploadStringTexture(*l,l->background,l->foreground); /* Update the texture version number: */ dataItem->version=l->version; } /* Draw a textured quad: */ glColor4f(1.0f,1.0f,1.0f,l->background[3]); glBegin(GL_QUADS); glNormal3f(0.0f,0.0f,1.0f); glTexCoord(l->textureBox.getCorner(0)); glVertex(l->labelBox.getCorner(0)); glTexCoord(l->textureBox.getCorner(1)); glVertex(l->labelBox.getCorner(1)); glTexCoord(l->textureBox.getCorner(3)); glVertex(l->labelBox.getCorner(3)); glTexCoord(l->textureBox.getCorner(2)); glVertex(l->labelBox.getCorner(2)); glEnd(); } /* Reset OpenGL state: */ glBindTexture(GL_TEXTURE_2D,0); glPopAttrib(); /* Clear the list of labels: */ gatheredLabels.clear(); }
void TheGooniesApp::titleanimation_draw(void) { glClearColor(0, 0, 0, 1); glClear(GL_COLOR_BUFFER_BIT); m_titleanimation_shift -= m_titleanimation_speed; m_titleanimation_shift += 40; m_titleanimation_shift = (m_titleanimation_shift%40)-40; if ((m_state_cycle%8)==0) { if (m_titleanimation_state==0 || m_titleanimation_state==1) { if (m_titleanimation_speed<4) m_titleanimation_speed++; } else { if (m_titleanimation_speed>0) m_titleanimation_speed--; } } m_GLTM->get ("bg_copyright")->draw(0, 0, 0, 0, 1); m_GLTM->get_smooth("title_logo")->draw(46, 17, 0, 0, 1); switch (m_titleanimation_state) { case 0: { float f = float(m_state_cycle) / 50; glColor4f(0, 0, 0, f); #ifndef HAVE_GLES glBegin(GL_QUADS); glVertex3f(0, 256, 0); glVertex3f(0, 400, 0); glVertex3f(640, 400, 0); glVertex3f(640, 256, 0); glEnd(); #else GLfloat vtx1[] = { 0, 256, 0, 0, 400, 0, 640, 400, 0, 640, 256, 0 }; glEnableClientState(GL_VERTEX_ARRAY); glVertexPointer(3, GL_FLOAT, 0, vtx1); glDrawArrays(GL_TRIANGLE_FAN,0,4); glDisableClientState(GL_VERTEX_ARRAY); #endif // film strip { GLTile *strip = m_GLTM->get("intro-film-strip"); for (int x = m_titleanimation_shift; x < 640; x+= 40) { strip->draw(1, 1, 1, f, float(x), 236, 0, 0, 1); strip->draw(1, 1, 1, f, float(x), 400, 0, 0, 1); } } } break; case 1: case 2: { float f = 1; bool scissor_state = (glIsEnabled(GL_SCISSOR_TEST) ? true : false); int scissor_window[4]; if (m_titleanimation_state == 1) f = 1; if (m_titleanimation_state == 2) f = float(50 - m_state_cycle) / 50; glEnable(GL_SCISSOR_TEST); if (scissor_state) glGetIntegerv(GL_SCISSOR_BOX, scissor_window); glScissor(screen_x(0), screen_y(60), screen_x(640), screen_y(184)); glColor4f(0, 0, 0, f); #ifndef HAVE_GLES glBegin(GL_QUADS); glVertex3f(0, 0, 0); glVertex3f(0, 480, 0); glVertex3f(640, 480, 0); glVertex3f(640, 0, 0); glEnd(); #else GLfloat vtx2[] = { 0, 0, 0, 0, 480, 0, 640, 480, 0, 640, 0, 0 }; glEnableClientState(GL_VERTEX_ARRAY); glVertexPointer(3, GL_FLOAT, 0, vtx2); glDrawArrays(GL_TRIANGLE_FAN,0,4); glDisableClientState(GL_VERTEX_ARRAY); #endif // film strip { // int shift = -(m_titleanimation_cycle % 20) * 2; GLTile *strip = m_GLTM->get("intro-film-strip"); for (int x = m_titleanimation_shift; x < 640; x+= 40) { strip->draw(1, 1, 1, f, float(x), 236, 0, 0, 1); strip->draw(1, 1, 1, f, float(x), 400, 0, 0, 1); } } // character: if (m_titleanimation_cycle > 50 && m_titleanimation_cycle <= 300) { // running right: int sp = (m_titleanimation_cycle / 8) % 4; if (sp == 0) m_GLTM->get ("intro-character-r1")->draw(1, 1, 1, f, 512 - (300 - m_titleanimation_cycle)*2.5f, 296, 0, 0, 1); if (sp == 1) m_GLTM->get ("intro-character-r2")->draw(1, 1, 1, f, 512 - (300 - m_titleanimation_cycle)*2.5f, 296, 0, 0, 1); if (sp == 2) m_GLTM->get ("intro-character-r1")->draw(1, 1, 1, f, 512 - (300 - m_titleanimation_cycle)*2.5f, 296, 0, 0, 1); if (sp == 3) m_GLTM->get ("intro-character-r3")->draw(1, 1, 1, f, 512 - (300 - m_titleanimation_cycle)*2.5f, 296, 0, 0, 1); } // if if (m_titleanimation_cycle > 300 && m_titleanimation_cycle <= 312) { // turning: int sp = (m_titleanimation_cycle - 301) / 4; if (sp == 0) m_GLTM->get ("intro-character-turning_rl_1")->draw(1, 1, 1, f, 512, 296, 0, 0, 1); if (sp == 1) m_GLTM->get ("intro-character-turning_rl_2")->draw(1, 1, 1, f, 512, 296, 0, 0, 1); if (sp == 2) m_GLTM->get ("intro-character-turning_rl_3")->draw(1, 1, 1, f, 512, 296, 0, 0, 1); } if (m_titleanimation_cycle > 312 && m_titleanimation_cycle <= 1500) { // standing left: int sp = (m_titleanimation_cycle / 8) % 4; if (sp == 0) m_GLTM->get ("intro-character-standing-l1")->draw(1, 1, 1, f, 512, 296, 0, 0, 1); if (sp == 1) m_GLTM->get ("intro-character-standing-l2")->draw(1, 1, 1, f, 512, 296, 0, 0, 1); if (sp == 2) m_GLTM->get ("intro-character-standing-l3")->draw(1, 1, 1, f, 512, 296, 0, 0, 1); if (sp == 3) m_GLTM->get ("intro-character-standing-l2")->draw(1, 1, 1, f, 512, 296, 0, 0, 1); } // if if (m_titleanimation_cycle > 1500 && m_titleanimation_cycle <= 1850) { int sp = (m_titleanimation_cycle / 8) % 2; int s2 = (m_titleanimation_cycle / 5) % 3; // knocked: if (s2 == 0) m_GLTM->get("intro-character-stars1")->draw(1, 1, 1, f, 532, 334, 0, 0, 1); if (s2 == 1) m_GLTM->get("intro-character-stars2")->draw(1, 1, 1, f, 532, 334, 0, 0, 1); if (s2 == 2) m_GLTM->get("intro-character-stars3")->draw(1, 1, 1, f, 532, 334, 0, 0, 1); if (sp == 0) m_GLTM->get ("intro-character-knocked1")->draw(1, 1, 1, f, 512, 296, 0, 0, 1); if (sp == 1) m_GLTM->get ("intro-character-knocked2")->draw(1, 1, 1, f, 512, 296, 0, 0, 1); } // if if (m_titleanimation_cycle > 1850 && m_titleanimation_cycle <= 1900) { // standing left: int sp = (m_titleanimation_cycle / 8) % 4; if (sp == 0) m_GLTM->get ("intro-character-standing-l1")->draw(1, 1, 1, f, 512, 296, 0, 0, 1); if (sp == 1) m_GLTM->get ("intro-character-standing-l2")->draw(1, 1, 1, f, 512, 296, 0, 0, 1); if (sp == 2) m_GLTM->get ("intro-character-standing-l3")->draw(1, 1, 1, f, 512, 296, 0, 0, 1); if (sp == 3) m_GLTM->get ("intro-character-standing-l2")->draw(1, 1, 1, f, 512, 296, 0, 0, 1); } // if if (m_titleanimation_cycle > 1900 && m_titleanimation_cycle <= 2200) { // running right: int sp = (m_titleanimation_cycle / 8) % 4; if (sp == 0) m_GLTM->get ("intro-character-l1")->draw(1, 1, 1, f, 512 - (m_titleanimation_cycle - 1900)*2.5f, 296, 0, 0, 1); if (sp == 1) m_GLTM->get ("intro-character-l2")->draw(1, 1, 1, f, 512 - (m_titleanimation_cycle - 1900)*2.5f, 296, 0, 0, 1); if (sp == 2) m_GLTM->get ("intro-character-l1")->draw(1, 1, 1, f, 512 - (m_titleanimation_cycle - 1900)*2.5f, 296, 0, 0, 1); if (sp == 3) m_GLTM->get ("intro-character-l3")->draw(1, 1, 1, f, 512 - (m_titleanimation_cycle - 1900)*2.5f, 296, 0, 0, 1); } // if // Mike if (m_titleanimation_cycle > 300 + 0*150 && m_titleanimation_cycle <= 500 + 0*150) { // running right: int sp = (m_titleanimation_cycle / 8) % 4; if (sp == 0) m_GLTM->get ("intro-mike-r1")->draw(1, 1, 1, f, (464 - 0*60) - (500 + 0*150 - m_titleanimation_cycle)*2.5f, 312, 0, 0, 1); if (sp == 1) m_GLTM->get ("intro-mike-r2")->draw(1, 1, 1, f, (464 - 0*60) - (500 + 0*150 - m_titleanimation_cycle)*2.5f, 312, 0, 0, 1); if (sp == 2) m_GLTM->get ("intro-mike-r3")->draw(1, 1, 1, f, (464 - 0*60) - (500 + 0*150 - m_titleanimation_cycle)*2.5f, 312, 0, 0, 1); if (sp == 3) m_GLTM->get ("intro-mike-r2")->draw(1, 1, 1, f, (464 - 0*60) - (500 + 0*150 - m_titleanimation_cycle)*2.5f, 312, 0, 0, 1); } if (m_titleanimation_cycle > 500 + 0*150 && m_titleanimation_cycle <= 1624 + 0*24) { // standing: int sp = (m_titleanimation_cycle / 16) % 2; if (sp == 0) m_GLTM->get ("intro-mike-standing1")->draw(1, 1, 1, f, float(464 - 0*60), 312, 0, 0, 1); if (sp == 1) m_GLTM->get ("intro-mike-standing2")->draw(1, 1, 1, f, float(464 - 0*60), 312, 0, 0, 1); } // Mouth if (m_titleanimation_cycle > 300 + 1*150 && m_titleanimation_cycle <= 500 + 1*150) { // running right: int sp = (m_titleanimation_cycle / 8) % 4; if (sp == 0) m_GLTM->get ("intro-mouth-r1")->draw(1, 1, 1, f, (464 - 1*60) - (500 + 1*150 - m_titleanimation_cycle)*2.5f, 312, 0, 0, 1); if (sp == 1) m_GLTM->get ("intro-mouth-r2")->draw(1, 1, 1, f, (464 - 1*60) - (500 + 1*150 - m_titleanimation_cycle)*2.5f, 312, 0, 0, 1); if (sp == 2) m_GLTM->get ("intro-mouth-r3")->draw(1, 1, 1, f, (464 - 1*60) - (500 + 1*150 - m_titleanimation_cycle)*2.5f, 312, 0, 0, 1); if (sp == 3) m_GLTM->get ("intro-mouth-r2")->draw(1, 1, 1, f, (464 - 1*60) - (500 + 1*150 - m_titleanimation_cycle)*2.5f, 312, 0, 0, 1); } if (m_titleanimation_cycle > 500 + 1*150 && m_titleanimation_cycle <= 1624 + 1*24) { // standing: int sp = (m_titleanimation_cycle / 16) % 2; if (sp == 0) m_GLTM->get ("intro-mouth-standing1")->draw(1, 1, 1, f, float(464 - 1*60), 312, 0, 0, 1); if (sp == 1) m_GLTM->get ("intro-mouth-standing2")->draw(1, 1, 1, f, float(464 - 1*60), 312, 0, 0, 1); } // // Data // // Added some variables to look for best values in the rope effect. Enjoy ^o^. // Should be replaced by constants or something once we feel happy with the values. // Ps: yes, I know Bresenham's algorithm to draw lines. But mee too lazy, too tired, too late :-). // float wave_amplitude = 1.0; // Wave amplitude when launching the rope float wave_lenght = 120.0; // Wave lenght when launching the rope int rope_cycles = 100; // Cycles to reach the other side of the screen float rope_y = 260; // Y coordinate for the left side of the rope float rope_y_delta = 10; // Hight delta between left and right sides float data_weight = 10; // "weight" of Data using the rope float data_shift = -30; // Data shift to adjust Data graphic to the rope :-P int rope_start_cycle = 500 + 1*150 - rope_cycles; GLTile *rope = m_GLTM->get("intro-data-rope"); // Throwing rope if (m_titleanimation_cycle > rope_start_cycle && m_titleanimation_cycle <= rope_start_cycle + rope_cycles) { int fragments = (m_titleanimation_cycle - rope_start_cycle)*64 / rope_cycles; for (int i = 0; i < fragments; ++i) rope->draw(1, 1, 1, f, float(i * 10), float(rope_y + i*10*rope_y_delta/640 + wave_amplitude * sin(i*10 * 2*M_PI/wave_lenght)), 0, 0, 1); } // Data descending if (m_titleanimation_cycle > 300 + 2*150 && m_titleanimation_cycle <= 500 + 2*150) { float x = (464 - 2*60) - (500 + 2*150 - m_titleanimation_cycle)*2.5f; float y = rope_y + data_weight + x*rope_y_delta/640.0f; // The Rope if (x >= 0 && x < 640) { int i; float fst_y_delta = data_weight + x*rope_y_delta/640; float snd_y_delta = rope_y_delta - fst_y_delta; for (i = 0; i < x; i+=10) rope->draw(1, 1, 1, f, float(i), rope_y + (i)*fst_y_delta/x, 0, 0, 1); for (i = 0; i < (640 - x); i+=10) rope->draw(1, 1, 1, f, float(i+x), rope_y + fst_y_delta + (i)*snd_y_delta/(640-x), 0, 0, 1); } else if (m_titleanimation_cycle > rope_start_cycle + rope_cycles) { int i; for (i = 0; i < 640; i+=10) rope->draw(1, 1, 1, f, float(i), rope_y + i*rope_y_delta/640, 0, 0, 1); } // The kiddo int sp = (m_titleanimation_cycle / 8) % 4; if (sp == 0) m_GLTM->get ("intro-data-hang1")->draw(1, 1, 1, f, x+data_shift, y, 0, 0, 1); if (sp == 1) m_GLTM->get ("intro-data-hang2")->draw(1, 1, 1, f, x+data_shift, y, 0, 0, 1); if (sp == 2) m_GLTM->get ("intro-data-hang3")->draw(1, 1, 1, f, x+data_shift, y, 0, 0, 1); if (sp == 3) m_GLTM->get ("intro-data-hang2")->draw(1, 1, 1, f, x+data_shift, y, 0, 0, 1); } else if (m_titleanimation_cycle > rope_start_cycle + rope_cycles) { // Rope dissapearing float rf; if (m_titleanimation_cycle < 900) rf = 1.0; else if (m_titleanimation_cycle > 1000) rf = 0.0; else rf = (1000 - m_titleanimation_cycle) / 100.0f; for (int i = 0; i < 640; i+=10) rope->draw(1, 1, 1, rf, float(i), rope_y + i*rope_y_delta/640, 0, 0, 1); } if (m_titleanimation_cycle > 500 + 2*150 && m_titleanimation_cycle <= 1624 + 2*24) { // standing: int sp = (m_titleanimation_cycle / 16) % 2; if (sp == 0) m_GLTM->get ("intro-data-standing1")->draw(1, 1, 1, f, float(464 - 2*60), 312, 0, 0, 1); if (sp == 1) m_GLTM->get ("intro-data-standing2")->draw(1, 1, 1, f, float(464 - 2*60), 312, 0, 0, 1); } // Chunk if (m_titleanimation_cycle > 300 + 3*150 && m_titleanimation_cycle <= 500 + 3*150) { // running right: int sp = (m_titleanimation_cycle / 8) % 4; if (sp == 0) m_GLTM->get ("intro-chunk-r1")->draw(1, 1, 1, f, (464 - 3*60) - (500 + 3*150 - m_titleanimation_cycle)*2.5f, 312, 0, 0, 1); if (sp == 1) m_GLTM->get ("intro-chunk-r2")->draw(1, 1, 1, f, (464 - 3*60) - (500 + 3*150 - m_titleanimation_cycle)*2.5f, 312, 0, 0, 1); if (sp == 2) m_GLTM->get ("intro-chunk-r3")->draw(1, 1, 1, f, (464 - 3*60) - (500 + 3*150 - m_titleanimation_cycle)*2.5f, 312, 0, 0, 1); if (sp == 3) m_GLTM->get ("intro-chunk-r2")->draw(1, 1, 1, f, (464 - 3*60) - (500 + 3*150 - m_titleanimation_cycle)*2.5f, 312, 0, 0, 1); } if (m_titleanimation_cycle > 500 + 3*150 && m_titleanimation_cycle <= 1624 + 3*24) { // standing: int sp = (m_titleanimation_cycle / 16) % 2; if (sp == 0) m_GLTM->get ("intro-chunk-standing1")->draw(1, 1, 1, f, float(464 - 3*60), 312, 0, 0, 1); if (sp == 1) m_GLTM->get ("intro-chunk-standing2")->draw(1, 1, 1, f, float(464 - 3*60), 312, 0, 0, 1); } // Brand if (m_titleanimation_cycle > 300 + 4*150 && m_titleanimation_cycle <= 500 + 4*150) { // running right: int sp = (m_titleanimation_cycle / 8) % 4; if (sp == 0) m_GLTM->get ("intro-brand-r1")->draw(1, 1, 1, f, (464 - 4*60) - (500 + 4*150 - m_titleanimation_cycle)*2.5f, 312, 0, 0, 1); if (sp == 1) m_GLTM->get ("intro-brand-r2")->draw(1, 1, 1, f, (464 - 4*60) - (500 + 4*150 - m_titleanimation_cycle)*2.5f, 312, 0, 0, 1); if (sp == 2) m_GLTM->get ("intro-brand-r3")->draw(1, 1, 1, f, (464 - 4*60) - (500 + 4*150 - m_titleanimation_cycle)*2.5f, 312, 0, 0, 1); if (sp == 3) m_GLTM->get ("intro-brand-r2")->draw(1, 1, 1, f, (464 - 4*60) - (500 + 4*150 - m_titleanimation_cycle)*2.5f, 312, 0, 0, 1); } if (m_titleanimation_cycle > 500 + 4*150 && m_titleanimation_cycle <= 1624 + 4*24) { // standing: int sp = (m_titleanimation_cycle / 16) % 2; if (sp == 0) m_GLTM->get ("intro-brand-standing1")->draw(1, 1, 1, f, float(464 - 4*60), 312, 0, 0, 1); if (sp == 1) m_GLTM->get ("intro-brand-standing2")->draw(1, 1, 1, f, float(464 - 4*60), 312, 0, 0, 1); } // Andy if (m_titleanimation_cycle > 300 + 5*150 && m_titleanimation_cycle <= 500 + 5*150) { // running right: int sp = (m_titleanimation_cycle / 8) % 4; if (sp == 0) m_GLTM->get ("intro-andy-r1")->draw(1, 1, 1, f, (464 - 5*60) - (500 + 5*150 - m_titleanimation_cycle)*2.5f, 312, 0, 0, 1); if (sp == 1) m_GLTM->get ("intro-andy-r2")->draw(1, 1, 1, f, (464 - 5*60) - (500 + 5*150 - m_titleanimation_cycle)*2.5f, 312, 0, 0, 1); if (sp == 2) m_GLTM->get ("intro-andy-r3")->draw(1, 1, 1, f, (464 - 5*60) - (500 + 5*150 - m_titleanimation_cycle)*2.5f, 312, 0, 0, 1); if (sp == 3) m_GLTM->get ("intro-andy-r2")->draw(1, 1, 1, f, (464 - 5*60) - (500 + 5*150 - m_titleanimation_cycle)*2.5f, 312, 0, 0, 1); } if (m_titleanimation_cycle > 500 + 5*150 && m_titleanimation_cycle <= 1624 + 5*24) { // standing: int sp = (m_titleanimation_cycle / 16) % 2; if (sp == 0) m_GLTM->get ("intro-andy-standing1")->draw(1, 1, 1, f, float(464 - 5*60), 312, 0, 0, 1); if (sp == 1) m_GLTM->get ("intro-andy-standing2")->draw(1, 1, 1, f, float(464 - 5*60), 312, 0, 0, 1); } // Steff if (m_titleanimation_cycle > 300 + 6*150 && m_titleanimation_cycle <= 500 + 6*150) { // running right: int sp = (m_titleanimation_cycle / 8) % 4; if (sp == 0) m_GLTM->get ("intro-steff-r1")->draw(1, 1, 1, f, (464 - 6*60) - (500 + 6*150 - m_titleanimation_cycle)*2.5f, 312, 0, 0, 1); if (sp == 1) m_GLTM->get ("intro-steff-r2")->draw(1, 1, 1, f, (464 - 6*60) - (500 + 6*150 - m_titleanimation_cycle)*2.5f, 312, 0, 0, 1); if (sp == 2) m_GLTM->get ("intro-steff-r3")->draw(1, 1, 1, f, (464 - 6*60) - (500 + 6*150 - m_titleanimation_cycle)*2.5f, 312, 0, 0, 1); if (sp == 3) m_GLTM->get ("intro-steff-r2")->draw(1, 1, 1, f, (464 - 6*60) - (500 + 6*150 - m_titleanimation_cycle)*2.5f, 312, 0, 0, 1); } if (m_titleanimation_cycle > 500 + 6*150 && m_titleanimation_cycle <= 1624 + 6*24) { // standing: int sp = (m_titleanimation_cycle / 16) % 2; if (sp == 0) m_GLTM->get ("intro-steff-standing1")->draw(1, 1, 1, f, float(464 - 6*60), 312, 0, 0, 1); if (sp == 1) m_GLTM->get ("intro-steff-standing2")->draw(1, 1, 1, f, float(464 - 6*60), 312, 0, 0, 1); } // Fratelli: if (m_titleanimation_cycle > 1400 && m_titleanimation_cycle <= 1500) { // wlking left: int sp = (m_titleanimation_cycle / 8) % 2; if (sp == 0) m_GLTM->get ("intro-fratelli-l1")->draw(1, 1, 1, f, 544 + (1500 - m_titleanimation_cycle)*2.5f, 296, 0, 0, 1); if (sp == 1) m_GLTM->get ("intro-fratelli-l2")->draw(1, 1, 1, f, 544 + (1500 - m_titleanimation_cycle)*2.5f, 296, 0, 0, 1); } // if if (m_titleanimation_cycle > 1500 && m_titleanimation_cycle <= 1600) { // standing left: m_GLTM->get ("intro-fratelli-l1")->draw(1, 1, 1, f, 544, 296, 0, 0, 1); } // if if (m_titleanimation_cycle > 1600 && m_titleanimation_cycle <= 1780) { // wlking left: int sp = (m_titleanimation_cycle / 8) % 2; if (sp == 0) m_GLTM->get ("intro-fratelli-l1")->draw(1, 1, 1, f, 544 - (m_titleanimation_cycle - 1600)*2.5f, 296, 0, 0, 1); if (sp == 1) m_GLTM->get ("intro-fratelli-l2")->draw(1, 1, 1, f, 544 - (m_titleanimation_cycle - 1600)*2.5f, 296, 0, 0, 1); } // if if (m_titleanimation_cycle > 1780 && m_titleanimation_cycle <= 1900) { // laughting: int sp = (m_titleanimation_cycle / 8) % 2; if (sp == 0) m_GLTM->get("intro-fratelli-laught-r1")->draw(1, 1, 1, f, 94, 296, 0, 0, 1); if (sp == 1) m_GLTM->get("intro-fratelli-laught-r2")->draw(1, 1, 1, f, 94, 296, 0, 0, 1); } // if if (m_titleanimation_cycle > 1900 && m_titleanimation_cycle <= 2000) { // wlking left: int sp = (m_titleanimation_cycle / 8) % 2; if (sp == 0) m_GLTM->get ("intro-fratelli-l1")->draw(1, 1, 1, f, 94 - (m_titleanimation_cycle - 1900)*2.5f, 296, 0, 0, 1); if (sp == 1) m_GLTM->get ("intro-fratelli-l2")->draw(1, 1, 1, f, 94 - (m_titleanimation_cycle - 1900)*2.5f, 296, 0, 0, 1); } // if if (!scissor_state) glDisable(GL_SCISSOR_TEST); if (scissor_state) glScissor(scissor_window[0], scissor_window[1], scissor_window[2], scissor_window[3]); } break; } // switch } /* TheGooniesApp::titleanimation_draw */
bool OGLRender::RenderTexRect() { glViewportWrapper(0, windowSetting.statusBarHeightToUse, windowSetting.uDisplayWidth, windowSetting.uDisplayHeight); OPENGL_CHECK_ERRORS; GLboolean cullface = glIsEnabled(GL_CULL_FACE); glDisable(GL_CULL_FACE); OPENGL_CHECK_ERRORS; float depth = -(g_texRectTVtx[3].z*2-1); #if SDL_VIDEO_OPENGL glBegin(GL_TRIANGLE_FAN); glColor4f(g_texRectTVtx[3].r, g_texRectTVtx[3].g, g_texRectTVtx[3].b, g_texRectTVtx[3].a); TexCoord(g_texRectTVtx[3]); glVertex3f(g_texRectTVtx[3].x, g_texRectTVtx[3].y, depth); glColor4f(g_texRectTVtx[2].r, g_texRectTVtx[2].g, g_texRectTVtx[2].b, g_texRectTVtx[2].a); TexCoord(g_texRectTVtx[2]); glVertex3f(g_texRectTVtx[2].x, g_texRectTVtx[2].y, depth); glColor4f(g_texRectTVtx[1].r, g_texRectTVtx[1].g, g_texRectTVtx[1].b, g_texRectTVtx[1].a); TexCoord(g_texRectTVtx[1]); glVertex3f(g_texRectTVtx[1].x, g_texRectTVtx[1].y, depth); glColor4f(g_texRectTVtx[0].r, g_texRectTVtx[0].g, g_texRectTVtx[0].b, g_texRectTVtx[0].a); TexCoord(g_texRectTVtx[0]); glVertex3f(g_texRectTVtx[0].x, g_texRectTVtx[0].y, depth); glEnd(); OPENGL_CHECK_ERRORS; #elif SDL_VIDEO_OPENGL_ES2 GLfloat colour[] = { g_texRectTVtx[3].r, g_texRectTVtx[3].g, g_texRectTVtx[3].b, g_texRectTVtx[3].a, g_texRectTVtx[2].r, g_texRectTVtx[2].g, g_texRectTVtx[2].b, g_texRectTVtx[2].a, g_texRectTVtx[1].r, g_texRectTVtx[1].g, g_texRectTVtx[1].b, g_texRectTVtx[1].a, g_texRectTVtx[0].r, g_texRectTVtx[0].g, g_texRectTVtx[0].b, g_texRectTVtx[0].a }; GLfloat tex[] = { g_texRectTVtx[3].tcord[0].u,g_texRectTVtx[3].tcord[0].v, g_texRectTVtx[2].tcord[0].u,g_texRectTVtx[2].tcord[0].v, g_texRectTVtx[1].tcord[0].u,g_texRectTVtx[1].tcord[0].v, g_texRectTVtx[0].tcord[0].u,g_texRectTVtx[0].tcord[0].v }; float w = windowSetting.uDisplayWidth / 2.0f, h = windowSetting.uDisplayHeight / 2.0f, inv = 1.0f; GLfloat vertices[] = { -inv + g_texRectTVtx[3].x / w, inv - g_texRectTVtx[3].y / h, depth, 1, -inv + g_texRectTVtx[2].x / w, inv - g_texRectTVtx[2].y / h, depth, 1, -inv + g_texRectTVtx[1].x / w, inv - g_texRectTVtx[1].y / h, depth, 1, -inv + g_texRectTVtx[0].x / w, inv - g_texRectTVtx[0].y / h, depth, 1 }; glVertexAttribPointer(VS_COLOR, 4, GL_FLOAT,GL_TRUE, 0, &colour ); glVertexAttribPointer(VS_POSITION,4,GL_FLOAT,GL_FALSE,0,&vertices); glVertexAttribPointer(VS_TEXCOORD0,2,GL_FLOAT,GL_FALSE, 0, &tex); OPENGL_CHECK_ERRORS; glDrawArrays(GL_TRIANGLE_FAN,0,4); OPENGL_CHECK_ERRORS; //Restore old pointers glVertexAttribPointer(VS_COLOR, 4, GL_UNSIGNED_BYTE,GL_TRUE, sizeof(uint8)*4, &(g_oglVtxColors[0][0]) ); glVertexAttribPointer(VS_POSITION,4,GL_FLOAT,GL_FALSE,sizeof(float)*5,&(g_vtxProjected5[0][0])); glVertexAttribPointer(VS_TEXCOORD0,2,GL_FLOAT,GL_FALSE, sizeof( TLITVERTEX ), &(g_vtxBuffer[0].tcord[0].u)); #endif if( cullface ) glEnable(GL_CULL_FACE); OPENGL_CHECK_ERRORS; return true; }
void ui_draw_but_NORMAL(uiBut *but, uiWidgetColors *wcol, rcti *rect) { static GLuint displist = 0; int a, old[8]; GLfloat diff[4], diffn[4] = {1.0f, 1.0f, 1.0f, 1.0f}; float vec0[4] = {0.0f, 0.0f, 0.0f, 0.0f}; float dir[4], size; /* store stuff */ glGetMaterialfv(GL_FRONT, GL_DIFFUSE, diff); /* backdrop */ glColor3ubv((unsigned char *)wcol->inner); uiSetRoundBox(UI_CNR_ALL); uiDrawBox(GL_POLYGON, rect->xmin, rect->ymin, rect->xmax, rect->ymax, 5.0f); /* sphere color */ glMaterialfv(GL_FRONT, GL_DIFFUSE, diffn); glCullFace(GL_BACK); glEnable(GL_CULL_FACE); /* disable blender light */ for (a = 0; a < 8; a++) { old[a] = glIsEnabled(GL_LIGHT0 + a); glDisable(GL_LIGHT0 + a); } /* own light */ glEnable(GL_LIGHT7); glEnable(GL_LIGHTING); ui_get_but_vectorf(but, dir); dir[3] = 0.0f; /* glLightfv needs 4 args, 0.0 is sun */ glLightfv(GL_LIGHT7, GL_POSITION, dir); glLightfv(GL_LIGHT7, GL_DIFFUSE, diffn); glLightfv(GL_LIGHT7, GL_SPECULAR, vec0); glLightf(GL_LIGHT7, GL_CONSTANT_ATTENUATION, 1.0f); glLightf(GL_LIGHT7, GL_LINEAR_ATTENUATION, 0.0f); /* transform to button */ glPushMatrix(); glTranslatef(rect->xmin + 0.5f * BLI_rcti_size_x(rect), rect->ymin + 0.5f * BLI_rcti_size_y(rect), 0.0f); if (BLI_rcti_size_x(rect) < BLI_rcti_size_y(rect)) size = BLI_rcti_size_x(rect) / 200.f; else size = BLI_rcti_size_y(rect) / 200.f; glScalef(size, size, size); if (displist == 0) { GLUquadricObj *qobj; displist = glGenLists(1); glNewList(displist, GL_COMPILE); qobj = gluNewQuadric(); gluQuadricDrawStyle(qobj, GLU_FILL); glShadeModel(GL_SMOOTH); gluSphere(qobj, 100.0, 32, 24); glShadeModel(GL_FLAT); gluDeleteQuadric(qobj); glEndList(); } glCallList(displist); /* restore */ glDisable(GL_LIGHTING); glDisable(GL_CULL_FACE); glMaterialfv(GL_FRONT, GL_DIFFUSE, diff); glDisable(GL_LIGHT7); /* AA circle */ glEnable(GL_BLEND); glEnable(GL_LINE_SMOOTH); glColor3ubv((unsigned char *)wcol->inner); glutil_draw_lined_arc(0.0f, M_PI * 2.0, 100.0f, 32); glDisable(GL_BLEND); glDisable(GL_LINE_SMOOTH); /* matrix after circle */ glPopMatrix(); /* enable blender light */ for (a = 0; a < 8; a++) { if (old[a]) glEnable(GL_LIGHT0 + a); } }
void keyboard(unsigned char key, int x, int y) { vec3 look = (at-eye) * 0.1; vec3 right = calcCrossProduct(at-eye, up) * 0.05; switch(key) { case '1': if(glIsEnabled(GL_LIGHT1)) glDisable(GL_LIGHT1); else glEnable(GL_LIGHT1); break; case '2': if(glIsEnabled(GL_LIGHT0)) glDisable(GL_LIGHT0); else glEnable(GL_LIGHT0); break; case 'c': case 'C': circles = !circles; break; case 'r': case 'R': rotate = !rotate; break; case 'o': case 'O': orbits = !orbits; break; case '+': speed += 0.01; break; case '-': speed -= 0.01; break; case 'w': case 'W': eye = eye + look; at = at + look; //eye_speed += 0.01; // schubregelung break; case 's': case 'S': eye = eye - look; at = at - look; //eye_speed -= 0.01; // schubregelung break; case 'a': case 'A': eye = eye - right; at = at - right; break; case 'd': case 'D': eye = eye + right; at = at + right; break; case 'q': case 'Q': up = rotMat3x3(at-eye, -3) * up; break; case 'e': case 'E': up = rotMat3x3(at-eye, 3) * up; break; case 27: exit(0); } }
void ClippingNode::onBeforeVisit() { /////////////////////////////////// // INIT // increment the current layer s_layer++; // mask of the current layer (ie: for layer 3: 00000100) GLint mask_layer = 0x1 << s_layer; // mask of all layers less than the current (ie: for layer 3: 00000011) GLint mask_layer_l = mask_layer - 1; // mask of all layers less than or equal to the current (ie: for layer 3: 00000111) _mask_layer_le = mask_layer | mask_layer_l; // manually save the stencil state _currentStencilEnabled = glIsEnabled(GL_STENCIL_TEST); glGetIntegerv(GL_STENCIL_WRITEMASK, (GLint *)&_currentStencilWriteMask); glGetIntegerv(GL_STENCIL_FUNC, (GLint *)&_currentStencilFunc); glGetIntegerv(GL_STENCIL_REF, &_currentStencilRef); glGetIntegerv(GL_STENCIL_VALUE_MASK, (GLint *)&_currentStencilValueMask); glGetIntegerv(GL_STENCIL_FAIL, (GLint *)&_currentStencilFail); glGetIntegerv(GL_STENCIL_PASS_DEPTH_FAIL, (GLint *)&_currentStencilPassDepthFail); glGetIntegerv(GL_STENCIL_PASS_DEPTH_PASS, (GLint *)&_currentStencilPassDepthPass); // enable stencil use glEnable(GL_STENCIL_TEST); // check for OpenGL error while enabling stencil test CHECK_GL_ERROR_DEBUG(); // all bits on the stencil buffer are readonly, except the current layer bit, // this means that operation like glClear or glStencilOp will be masked with this value glStencilMask(mask_layer); // manually save the depth test state glGetBooleanv(GL_DEPTH_WRITEMASK, &_currentDepthWriteMask); // disable depth test while drawing the stencil //glDisable(GL_DEPTH_TEST); // disable update to the depth buffer while drawing the stencil, // as the stencil is not meant to be rendered in the real scene, // it should never prevent something else to be drawn, // only disabling depth buffer update should do glDepthMask(GL_FALSE); /////////////////////////////////// // CLEAR STENCIL BUFFER // manually clear the stencil buffer by drawing a fullscreen rectangle on it // setup the stencil test func like this: // for each pixel in the fullscreen rectangle // never draw it into the frame buffer // if not in inverted mode: set the current layer value to 0 in the stencil buffer // if in inverted mode: set the current layer value to 1 in the stencil buffer glStencilFunc(GL_NEVER, mask_layer, mask_layer); glStencilOp(!_inverted ? GL_ZERO : GL_REPLACE, GL_KEEP, GL_KEEP); // draw a fullscreen solid rectangle to clear the stencil buffer //ccDrawSolidRect(Vec2::ZERO, ccpFromSize([[Director sharedDirector] winSize]), Color4F(1, 1, 1, 1)); drawFullScreenQuadClearStencil(); /////////////////////////////////// // DRAW CLIPPING STENCIL // setup the stencil test func like this: // for each pixel in the stencil node // never draw it into the frame buffer // if not in inverted mode: set the current layer value to 1 in the stencil buffer // if in inverted mode: set the current layer value to 0 in the stencil buffer glStencilFunc(GL_NEVER, mask_layer, mask_layer); glStencilOp(!_inverted ? GL_REPLACE : GL_ZERO, GL_KEEP, GL_KEEP); // enable alpha test only if the alpha threshold < 1, // indeed if alpha threshold == 1, every pixel will be drawn anyways if (_alphaThreshold < 1) { #if (CC_TARGET_PLATFORM == CC_PLATFORM_MAC || CC_TARGET_PLATFORM == CC_PLATFORM_WINDOWS || CC_TARGET_PLATFORM == CC_PLATFORM_LINUX) // manually save the alpha test state _currentAlphaTestEnabled = glIsEnabled(GL_ALPHA_TEST); glGetIntegerv(GL_ALPHA_TEST_FUNC, (GLint *)&_currentAlphaTestFunc); glGetFloatv(GL_ALPHA_TEST_REF, &_currentAlphaTestRef); // enable alpha testing glEnable(GL_ALPHA_TEST); // check for OpenGL error while enabling alpha test CHECK_GL_ERROR_DEBUG(); // pixel will be drawn only if greater than an alpha threshold glAlphaFunc(GL_GREATER, _alphaThreshold); #else #endif } //Draw _stencil }
void GearsScreen::cubePaintInside (const GLScreenPaintAttrib &sAttrib, const GLMatrix &transform, CompOutput *output, int size, const GLVector &normal) { // CUBE_SCREEN (screen); static GLfloat white[4] = { 1.0, 1.0, 1.0, 1.0 }; GLScreenPaintAttrib sA = sAttrib; sA.yRotate += csScreen->invert () * (360.0f / size) * (csScreen->xRotations () - (screen->vp ().x () * csScreen->nOutput ())); //CompTransform mT = *transform; GLMatrix mT = transform; gScreen->glApplyTransform (sA, output, &mT); // (*s->applyScreenTransform) (s, &sA, output, &mT); glPushMatrix(); glLoadMatrixf (mT.getMatrix ()); glTranslatef (csScreen->outputXOffset (), -csScreen->outputYOffset (), 0.0f); glScalef (csScreen->outputXScale (), csScreen->outputYScale (), 1.0f); bool enabledCull = false; glPushAttrib (GL_COLOR_BUFFER_BIT | GL_TEXTURE_BIT); glDisable (GL_BLEND); if (!glIsEnabled (GL_CULL_FACE) ) { enabledCull = true; glEnable (GL_CULL_FACE); } glPushMatrix(); glRotatef (contentRotation, 0.0, 1.0, 0.0); glScalef (0.05, 0.05, 0.05); glColor4usv (defaultColor); glEnable (GL_NORMALIZE); glEnable (GL_LIGHTING); glEnable (GL_LIGHT1); glDisable (GL_COLOR_MATERIAL); glEnable (GL_DEPTH_TEST); glDepthMask (GL_TRUE); glDepthFunc (GL_LESS); glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); glPushMatrix(); glTranslatef (-3.0, -2.0, 0.0); glRotatef (angle, 0.0, 0.0, 1.0); glCallList (gear1); glPopMatrix(); glPushMatrix(); glTranslatef (3.1, -2.0, 0.0); glRotatef (-2.0 * angle - 9.0, 0.0, 0.0, 1.0); glCallList (gear2); glPopMatrix(); glPushMatrix(); glTranslatef (-3.1, 4.2, 0.0); glRotatef (-2.0 * angle - 25.0, 0.0, 0.0, 1.0); glCallList (gear3); glPopMatrix(); glMaterialfv (GL_FRONT, GL_AMBIENT_AND_DIFFUSE, white); glPopMatrix(); glDisable (GL_LIGHT1); glDisable (GL_NORMALIZE); glEnable (GL_COLOR_MATERIAL); if (!gScreen->lighting ()) glDisable (GL_LIGHTING); glDisable (GL_DEPTH_TEST); if (enabledCull) glDisable (GL_CULL_FACE); glPopMatrix(); glPopAttrib(); damage = true; csScreen->cubePaintInside (sAttrib, transform, output, size, normal); }
//---------------------------------------- bool ofGetLightingEnabled() { return glIsEnabled(GL_LIGHTING); }
void R_DrawParticles ( void ) { particle_t *p, *kill; float grav; int i; float time2, time3; float time1; float dvel; float frametime; unsigned char *at; unsigned char theAlpha; vec3_t up, right; float scale; qboolean alphaTestEnabled; if (gl_particles->value) { GL_Bind(particletexture); alphaTestEnabled = glIsEnabled(GL_ALPHA_TEST); if (alphaTestEnabled) glDisable(GL_ALPHA_TEST); glEnable (GL_BLEND); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); glBegin (GL_TRIANGLES); VectorScale (vup, 1.5, up); VectorScale (vright, 1.5, right); #ifdef UQUAKE frametime = cl.time - cl.oldtime; #else frametime = host_frametime; #endif time3 = frametime * 15; time2 = frametime * 10; // 15; time1 = frametime * 5; #ifdef UQUAKE grav = frametime * sv_gravity->value * 0.05; #else grav = frametime * 800 * 0.05; #endif 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; } 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; } // 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 = gl_particles->value; else scale = gl_particles->value + scale * 0.004; #if 0 // was in uquake, but give it a go glColor3ubv ((byte *)&d_8to24table[(int)p->color]); #else at = (byte *)&d_8to24table[(int)p->color]; if (p->type==pt_fire) theAlpha = 255*(6-p->ramp)/6; // theAlpha = 192; // else if (p->type==pt_explode || p->type==pt_explode2) // theAlpha = 255*(8-p->ramp)/8; else theAlpha = 255; glColor4ub (*at, *(at+1), *(at+2), theAlpha); // glColor3ubv (at); // glColor3ubv ((byte *)&d_8to24table[(int)p->color]); #endif glTexCoord2f (0,0); glVertex3fv (p->org); glTexCoord2f (1,0); glVertex3f (p->org[0] + up[0]*scale, p->org[1] + up[1]*scale, p->org[2] + up[2]*scale); glTexCoord2f (0,1); glVertex3f (p->org[0] + right[0]*scale, p->org[1] + right[1]*scale, p->org[2] + right[2]*scale); 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: // This causes some particles to fall to the // ground. It's been reported as a bug, // so for now it's being fixed. // We can implement it as a feature, but it's // not all that cool. // p->vel[2] -= grav * 20; // break; case pt_slowgrav: p->vel[2] -= grav; break; } } glEnd (); glDisable (GL_BLEND); if (alphaTestEnabled) glEnable(GL_ALPHA_TEST); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); } // if (gl_particles->value) }
// This is the main rendering function that you have to implement and provide to ImGui (via setting up 'RenderDrawListsFn' in the ImGuiIO structure) // If text or lines are blurry when integrating ImGui in your engine: // - in your Render function, try translating your projection matrix by (0.5f,0.5f) or (0.375f,0.375f) void ImGui_ImplGlfwGL3_RenderDrawLists(ImDrawData* draw_data) { // Backup GL state GLint last_program, last_texture, last_array_buffer, last_element_array_buffer, last_vertex_array; glGetIntegerv(GL_CURRENT_PROGRAM, &last_program); glGetIntegerv(GL_TEXTURE_BINDING_2D, &last_texture); glGetIntegerv(GL_ARRAY_BUFFER_BINDING, &last_array_buffer); glGetIntegerv(GL_ELEMENT_ARRAY_BUFFER_BINDING, &last_element_array_buffer); glGetIntegerv(GL_VERTEX_ARRAY_BINDING, &last_vertex_array); GLboolean last_enable_blend = glIsEnabled(GL_BLEND); GLboolean last_enable_cull_face = glIsEnabled(GL_CULL_FACE); GLboolean last_enable_depth_test = glIsEnabled(GL_DEPTH_TEST); GLboolean last_enable_scissor_test = glIsEnabled(GL_SCISSOR_TEST); // Setup render state: alpha-blending enabled, no face culling, no depth testing, scissor enabled glEnable(GL_BLEND); glBlendEquation(GL_FUNC_ADD); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glDisable(GL_CULL_FACE); glDisable(GL_DEPTH_TEST); glEnable(GL_SCISSOR_TEST); glActiveTexture(GL_TEXTURE0); // Handle cases of screen coordinates != from framebuffer coordinates (e.g. retina displays) ImGuiIO& io = ImGui::GetIO(); float fb_height = io.DisplaySize.y * io.DisplayFramebufferScale.y; draw_data->ScaleClipRects(io.DisplayFramebufferScale); // Setup orthographic projection matrix const float ortho_projection[4][4] = { { 2.0f/io.DisplaySize.x, 0.0f, 0.0f, 0.0f }, { 0.0f, 2.0f/-io.DisplaySize.y, 0.0f, 0.0f }, { 0.0f, 0.0f, -1.0f, 0.0f }, {-1.0f, 1.0f, 0.0f, 1.0f }, }; glUseProgram(g_ShaderHandle); glUniform1i(g_AttribLocationTex, 0); glUniformMatrix4fv(g_AttribLocationProjMtx, 1, GL_FALSE, &ortho_projection[0][0]); glBindVertexArray(g_VaoHandle); for (int n = 0; n < draw_data->CmdListsCount; n++) { const ImDrawList* cmd_list = draw_data->CmdLists[n]; const ImDrawIdx* idx_buffer_offset = 0; glBindBuffer(GL_ARRAY_BUFFER, g_VboHandle); glBufferData(GL_ARRAY_BUFFER, (GLsizeiptr)cmd_list->VtxBuffer.size() * sizeof(ImDrawVert), (GLvoid*)&cmd_list->VtxBuffer.front(), GL_STREAM_DRAW); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, g_ElementsHandle); glBufferData(GL_ELEMENT_ARRAY_BUFFER, (GLsizeiptr)cmd_list->IdxBuffer.size() * sizeof(ImDrawIdx), (GLvoid*)&cmd_list->IdxBuffer.front(), GL_STREAM_DRAW); for (const ImDrawCmd* pcmd = cmd_list->CmdBuffer.begin(); pcmd != cmd_list->CmdBuffer.end(); pcmd++) { if (pcmd->UserCallback) { pcmd->UserCallback(cmd_list, pcmd); } else { glBindTexture(GL_TEXTURE_2D, (GLuint)(intptr_t)pcmd->TextureId); glScissor((int)pcmd->ClipRect.x, (int)(fb_height - pcmd->ClipRect.w), (int)(pcmd->ClipRect.z - pcmd->ClipRect.x), (int)(pcmd->ClipRect.w - pcmd->ClipRect.y)); glDrawElements(GL_TRIANGLES, (GLsizei)pcmd->ElemCount, GL_UNSIGNED_SHORT, idx_buffer_offset); } idx_buffer_offset += pcmd->ElemCount; } } // Restore modified GL state glUseProgram(last_program); glBindTexture(GL_TEXTURE_2D, last_texture); glBindBuffer(GL_ARRAY_BUFFER, last_array_buffer); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, last_element_array_buffer); glBindVertexArray(last_vertex_array); if (last_enable_blend) glEnable(GL_BLEND); else glDisable(GL_BLEND); if (last_enable_cull_face) glEnable(GL_CULL_FACE); else glDisable(GL_CULL_FACE); if (last_enable_depth_test) glEnable(GL_DEPTH_TEST); else glDisable(GL_DEPTH_TEST); if (last_enable_scissor_test) glEnable(GL_SCISSOR_TEST); else glDisable(GL_SCISSOR_TEST); }
GLboolean glIsEnabledLogged(GLenum cap) { printf("glIsEnabled(%s)\n", GLEnumName(cap)); return glIsEnabled(cap); }
int main(int argc, char *argv[]) { SDL_Window *window; SDL_GLContext context; // Slightly different SDL initialization if ( SDL_Init(SDL_INIT_VIDEO) != 0 ) { printf("Unable to initialize SDL: %s\n", SDL_GetError()); return 1; } SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 ); // *new* window = SDL_CreateWindow("sdl_fog_density", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 640, 480, SDL_WINDOW_OPENGL); if ( !window ) { printf("Unable to create window: %s\n", SDL_GetError()); return 1; } context = SDL_GL_CreateContext(window); // Set the OpenGL state after creating the context with SDL_SetVideoMode glClearColor( 0, 0, 0, 0 ); glEnable( GL_TEXTURE_2D ); // Needed when we're using the fixed-function pipeline. glViewport( 0, 0, 640, 480 ); glMatrixMode( GL_PROJECTION ); glPushMatrix(); // just for testing glLoadIdentity(); glOrtho( 0, 640, 480, 0, -1000, 1000 ); glMatrixMode( GL_MODELVIEW ); glLoadIdentity(); // Load the OpenGL texture GLuint texture; // Texture object handle SDL_Surface *surface; // Gives us the information to make the texture if ( (surface = IMG_Load("screenshot.png")) ) { // Check that the image's width is a power of 2 if ( (surface->w & (surface->w - 1)) != 0 ) { printf("warning: image.bmp's width is not a power of 2\n"); } // Also check if the height is a power of 2 if ( (surface->h & (surface->h - 1)) != 0 ) { printf("warning: image.bmp's height is not a power of 2\n"); } // Have OpenGL generate a texture object handle for us glGenTextures( 1, &texture ); // Bind the texture object glBindTexture( GL_TEXTURE_2D, texture ); // Set the texture's stretching properties glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); //SDL_LockSurface(surface); // Add some greyness memset(surface->pixels, 0x66, surface->w*surface->h); // Edit the texture object's image data using the information SDL_Surface gives us glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, surface->w, surface->h, 0, GL_RGBA, GL_UNSIGNED_BYTE, surface->pixels ); //SDL_UnlockSurface(surface); } else { printf("SDL could not load image.bmp: %s\n", SDL_GetError()); SDL_Quit(); return 1; } // Free the SDL_Surface only if it was successfully created if ( surface ) { SDL_FreeSurface( surface ); } // Clear the screen before drawing glClear( GL_COLOR_BUFFER_BIT ); // Bind the texture to which subsequent calls refer to glBindTexture( GL_TEXTURE_2D, texture ); glEnable(GL_FOG); GLfloat fogColor[] = { 1.0, 0.5, 0.5, 0.05 }; glFogfv(GL_FOG_COLOR, fogColor); glFogf(GL_FOG_DENSITY, 0.2); glFogi(GL_FOG_MODE, GL_EXP2); assert(glIsEnabled(GL_FOG)); glBegin( GL_QUADS ); glTexCoord2i( 0, 0 ); glVertex3f( 10, 10, 10 ); glTexCoord2i( 1, 0 ); glVertex3f( 300, 10, 10 ); glTexCoord2i( 1, 1 ); glVertex3f( 300, 128, 10 ); glTexCoord2i( 0, 1 ); glVertex3f( 10, 128, 10 ); glTexCoord2f( 0, 0.5 ); glVertex3f( 410, 10, 5 ); glTexCoord2f( 1, 0.5 ); glVertex3f( 600, 10, 6 ); glTexCoord2f( 1, 1 ); glVertex3f( 630, 200, 7 ); glTexCoord2f( 0.5, 1 ); glVertex3f( 310, 250, 8 ); glEnd(); glBegin( GL_TRIANGLE_STRIP ); glTexCoord2i( 0, 0 ); glVertex3f( 100, 300, 1 ); glTexCoord2i( 1, 0 ); glVertex3f( 300, 300, 1 ); glTexCoord2i( 1, 1 ); glVertex3f( 300, 400, 1 ); glTexCoord2i( 0, 1 ); glVertex3f( 500, 410, 1 ); glEnd(); glDisable(GL_TEXTURE_2D); glColor3ub(90, 255, 255); glBegin( GL_QUADS ); glVertex3f( 10, 410, 5 ); glVertex3f( 300, 410, 50 ); glVertex3f( 300, 480, 100 ); glVertex3f( 10, 470, 5 ); glEnd(); glBegin( GL_QUADS ); glColor3f(1.0, 0, 1.0); glVertex3f( 410, 410, 10 ); glColor3f(0, 1.0, 0); glVertex3f( 600, 410, 10 ); glColor3f(0, 0, 1.0); glVertex3f( 600, 480, 10 ); glColor3f(1.0, 1.0, 1.0); glVertex3f( 410, 470, 10 ); glEnd(); SDL_GL_SwapWindow(window); #if !defined(__EMSCRIPTEN__) // Wait for 3 seconds to give us a chance to see the image SDL_Delay(30000); #endif // Now we can delete the OpenGL texture and close down SDL glDeleteTextures( 1, &texture ); SDL_Quit(); return 0; }
// This is the main rendering function that you have to implement and provide to ImGui (via setting up 'RenderDrawListsFn' in the ImGuiIO structure) // If text or lines are blurry when integrating ImGui in your engine: // - in your Render function, try translating your projection matrix by (0.5f,0.5f) or (0.375f,0.375f) void ImGui_ImplSdlGL3_RenderDrawLists(ImDrawData* draw_data) { // Avoid rendering when minimized, scale coordinates for retina displays (screen coordinates != framebuffer coordinates) ImGuiIO& io = ImGui::GetIO(); int fb_width = (int)(io.DisplaySize.x * io.DisplayFramebufferScale.x); int fb_height = (int)(io.DisplaySize.y * io.DisplayFramebufferScale.y); if (fb_width == 0 || fb_height == 0) return; draw_data->ScaleClipRects(io.DisplayFramebufferScale); // Backup GL state GLint last_program; glGetIntegerv(GL_CURRENT_PROGRAM, &last_program); GLint last_texture; glGetIntegerv(GL_TEXTURE_BINDING_2D, &last_texture); GLint last_active_texture; glGetIntegerv(GL_ACTIVE_TEXTURE, &last_active_texture); GLint last_array_buffer; glGetIntegerv(GL_ARRAY_BUFFER_BINDING, &last_array_buffer); GLint last_element_array_buffer; glGetIntegerv(GL_ELEMENT_ARRAY_BUFFER_BINDING, &last_element_array_buffer); GLint last_vertex_array; glGetIntegerv(GL_VERTEX_ARRAY_BINDING, &last_vertex_array); GLint last_blend_src; glGetIntegerv(GL_BLEND_SRC, &last_blend_src); GLint last_blend_dst; glGetIntegerv(GL_BLEND_DST, &last_blend_dst); GLint last_blend_equation_rgb; glGetIntegerv(GL_BLEND_EQUATION_RGB, &last_blend_equation_rgb); GLint last_blend_equation_alpha; glGetIntegerv(GL_BLEND_EQUATION_ALPHA, &last_blend_equation_alpha); GLint last_viewport[4]; glGetIntegerv(GL_VIEWPORT, last_viewport); GLint last_scissor_box[4]; glGetIntegerv(GL_SCISSOR_BOX, last_scissor_box); GLboolean last_enable_blend = glIsEnabled(GL_BLEND); GLboolean last_enable_cull_face = glIsEnabled(GL_CULL_FACE); GLboolean last_enable_depth_test = glIsEnabled(GL_DEPTH_TEST); GLboolean last_enable_scissor_test = glIsEnabled(GL_SCISSOR_TEST); // Setup render state: alpha-blending enabled, no face culling, no depth testing, scissor enabled glEnable(GL_BLEND); glBlendEquation(GL_FUNC_ADD); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glDisable(GL_CULL_FACE); glDisable(GL_DEPTH_TEST); glEnable(GL_SCISSOR_TEST); glActiveTexture(GL_TEXTURE0); // Setup orthographic projection matrix glViewport(0, 0, (GLsizei)fb_width, (GLsizei)fb_height); const float ortho_projection[4][4] = { { 2.0f/io.DisplaySize.x, 0.0f, 0.0f, 0.0f }, { 0.0f, 2.0f/-io.DisplaySize.y, 0.0f, 0.0f }, { 0.0f, 0.0f, -1.0f, 0.0f }, {-1.0f, 1.0f, 0.0f, 1.0f }, }; glUseProgram(g_ShaderHandle); glUniform1i(g_AttribLocationTex, 0); glUniformMatrix4fv(g_AttribLocationProjMtx, 1, GL_FALSE, &ortho_projection[0][0]); glBindVertexArray(g_VaoHandle); for (int n = 0; n < draw_data->CmdListsCount; n++) { const ImDrawList* cmd_list = draw_data->CmdLists[n]; const ImDrawIdx* idx_buffer_offset = 0; glBindBuffer(GL_ARRAY_BUFFER, g_VboHandle); glBufferData(GL_ARRAY_BUFFER, (GLsizeiptr)cmd_list->VtxBuffer.Size * sizeof(ImDrawVert), (GLvoid*)cmd_list->VtxBuffer.Data, GL_STREAM_DRAW); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, g_ElementsHandle); glBufferData(GL_ELEMENT_ARRAY_BUFFER, (GLsizeiptr)cmd_list->IdxBuffer.Size * sizeof(ImDrawIdx), (GLvoid*)cmd_list->IdxBuffer.Data, GL_STREAM_DRAW); for (int cmd_i = 0; cmd_i < cmd_list->CmdBuffer.Size; cmd_i++) { const ImDrawCmd* pcmd = &cmd_list->CmdBuffer[cmd_i]; if (pcmd->UserCallback) { pcmd->UserCallback(cmd_list, pcmd); } else { glBindTexture(GL_TEXTURE_2D, (GLuint)(intptr_t)pcmd->TextureId); glScissor((int)pcmd->ClipRect.x, (int)(fb_height - pcmd->ClipRect.w), (int)(pcmd->ClipRect.z - pcmd->ClipRect.x), (int)(pcmd->ClipRect.w - pcmd->ClipRect.y)); glDrawElements(GL_TRIANGLES, (GLsizei)pcmd->ElemCount, sizeof(ImDrawIdx) == 2 ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT, idx_buffer_offset); } idx_buffer_offset += pcmd->ElemCount; } } // Restore modified GL state glUseProgram(last_program); glActiveTexture(last_active_texture); glBindTexture(GL_TEXTURE_2D, last_texture); glBindVertexArray(last_vertex_array); glBindBuffer(GL_ARRAY_BUFFER, last_array_buffer); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, last_element_array_buffer); glBlendEquationSeparate(last_blend_equation_rgb, last_blend_equation_alpha); glBlendFunc(last_blend_src, last_blend_dst); if (last_enable_blend) glEnable(GL_BLEND); else glDisable(GL_BLEND); if (last_enable_cull_face) glEnable(GL_CULL_FACE); else glDisable(GL_CULL_FACE); if (last_enable_depth_test) glEnable(GL_DEPTH_TEST); else glDisable(GL_DEPTH_TEST); if (last_enable_scissor_test) glEnable(GL_SCISSOR_TEST); else glDisable(GL_SCISSOR_TEST); glViewport(last_viewport[0], last_viewport[1], (GLsizei)last_viewport[2], (GLsizei)last_viewport[3]); glScissor(last_scissor_box[0], last_scissor_box[1], (GLsizei)last_scissor_box[2], (GLsizei)last_scissor_box[3]); }
void CWell::DrawGL(void) { if( m_data.IsEmpty() || !m_bVisible ) return; int n; int lit; int ipl; double* wd; WELLIT* wl; n = m_data.GetSize(); wd = m_data.GetData(); BOOL bLighht = glIsEnabled(GL_LIGHTING); glDisable(GL_LIGHTING); if(m_bSolidLog3D) glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); else { glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); } for(int i=m_nFormat*3, ip=m_nFormat*2; i<n; i += m_nFormat, ip += m_nFormat) { lit = (int) wd[i+m_nFormat-1]; wl = &m_welLit.GetAt(lit); glColor3d(wl->rd, wl->gd, wl->bd); glLineWidth( 5 ); glBegin(GL_LINES); glVertex3d( wd[ip+0], wd[ip+2], -wd[ip+1]); glVertex3d( wd[i+0], wd[i+2], -wd[i+1]); glEnd(); // Draw current layer glLineWidth(1.0f); if( (i % m_nSamplingLog) == 0) { for(int j=4; j<m_nFormat-1; j++) { if(m_showChannel[j] == TRUE) { ipl = i - m_nFormat*m_nSamplingLog; if(ipl < m_nFormat*2) ipl = m_nFormat*2; double u=m_dLogPieStart*PI/180.0; double dU = 2*PI/m_nSamplingRing; //glColor3f(1.0f, 0.0f, 0.0f); CPen* pPen = &m_penArray.GetAt(j); LOGPEN lp; double clr[3]; pPen->GetLogPen(&lp); clr[0] = GetRValue(lp.lopnColor)/255.0; clr[1] = GetGValue(lp.lopnColor)/255.0; clr[2] = GetBValue(lp.lopnColor)/255.0; glColor3dv(clr); while (u<(m_dLogPieEnd*PI/180.0)) { double P00[3],P01[3],P10[3],P11[3]; double dRadip, dRadi; dRadi = m_dRadiusLog3D * (wd[i+j] - wd[0+j])/(wd[m_nFormat+j] - wd[0+j]); dRadip = m_dRadiusLog3D * (wd[ipl+j] - wd[0+j])/(wd[m_nFormat+j] - wd[0+j]); P00[0] = wd[ipl+0] + cos(u)*(dRadip); P00[1] = wd[ipl+2]; P00[2] = -wd[ipl+1] + sin(u)*(dRadip); P01[0] = wd[ipl+0] + cos(u+dU)*(dRadip); P01[1] = wd[ipl+2]; P01[2] = -wd[ipl+1] + sin(u+dU)*(dRadip); P11[0] = wd[i+0] + cos(u+dU)*(dRadi); P11[1] = wd[i+2]; P11[2] = -wd[i+1] + sin(u+dU)*(dRadi); P10[0] = wd[i+0] + cos(u)*(dRadi); P10[1] = wd[i+2]; P10[2] = -wd[i+1] + sin(u)*(dRadi); glBegin(GL_QUADS); glVertex3dv(P00); glVertex3dv(P01); glVertex3dv(P11); glVertex3dv(P10); glEnd(); u+=dU; }; } } } } if(bLighht) glEnable(GL_LIGHTING); else glDisable(GL_LIGHTING); }
void CachedSvgItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { #if defined(Q_OS_WIN) // Disable this on windows because the default Qt5 doesn't ship with full OpenGL support // https://bugreports.qt-project.org/browse/QTBUG-28715 // since this is only used for the PFD and the QML PFD is accelerated this is probably // a non issue QGraphicsSvgItem::paint(painter, option, widget); #else if (painter->paintEngine()->type() != QPaintEngine::OpenGL && painter->paintEngine()->type() != QPaintEngine::OpenGL2) { //Fallback to direct painting QGraphicsSvgItem::paint(painter, option, widget); return; } QRectF br = boundingRect(); QTransform transform = painter->worldTransform(); qreal sceneScale = transform.map(QLineF(0,0,1,0)).length(); bool stencilTestEnabled = glIsEnabled(GL_STENCIL_TEST); bool scissorTestEnabled = glIsEnabled(GL_SCISSOR_TEST); painter->beginNativePainting(); if (stencilTestEnabled) glEnable(GL_STENCIL_TEST); if (scissorTestEnabled) glEnable(GL_SCISSOR_TEST); bool dirty = false; if (!m_texture) { glGenTextures(1, &m_texture); m_context = const_cast<QGLContext*>(QGLContext::currentContext()); dirty = true; } if (!qFuzzyCompare(sceneScale, m_scale)) { m_scale = sceneScale; dirty = true; } int textureWidth = (int(br.width()*m_scale) + 3) & ~3; int textureHeight = (int(br.height()*m_scale) + 3) & ~3; if (dirty) { //qDebug() << "re-render image"; QImage img(textureWidth, textureHeight, QImage::Format_ARGB32); { img.fill(Qt::transparent); QPainter p; p.begin(&img); p.setRenderHints(painter->renderHints()); p.translate(br.topLeft()); p.scale(m_scale, m_scale); QGraphicsSvgItem::paint(&p, option, 0); p.end(); img = img.rgbSwapped(); } glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, m_texture); glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, textureWidth, textureHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, img.bits()); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glDisable(GL_TEXTURE_2D); dirty = false; } glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, m_texture); //texture may be slightly large than svn image, ensure only used area is rendered qreal tw = br.width()*m_scale/textureWidth; qreal th = br.height()*m_scale/textureHeight; glBegin(GL_QUADS); glTexCoord2d(0, 0 ); glVertex3d(br.left(), br.top(), -1); glTexCoord2d(tw, 0 ); glVertex3d(br.right(), br.top(), -1); glTexCoord2d(tw, th); glVertex3d(br.right(), br.bottom(), -1); glTexCoord2d(0, th); glVertex3d(br.left(), br.bottom(), -1); glEnd(); glDisable(GL_TEXTURE_2D); painter->endNativePainting(); #endif }
void csGLStateCacheContext::InitCache() { int i; glGetIntegerv (GL_ALPHA_TEST_FUNC, (GLint*)¶meter_alpha_func); glGetFloatv (GL_ALPHA_TEST_REF, ¶meter_alpha_ref); if (extmgr->CS_GL_EXT_blend_func_separate) { glGetIntegerv (GL_BLEND_SRC_RGB_EXT, (GLint*)&blend_sourceRGB); glGetIntegerv (GL_BLEND_SRC_ALPHA_EXT, (GLint*)&blend_sourceA); glGetIntegerv (GL_BLEND_DST_RGB_EXT, (GLint*)&blend_destinationRGB); glGetIntegerv (GL_BLEND_DST_ALPHA_EXT, (GLint*)&blend_destinationA); } else { glGetIntegerv (GL_BLEND_SRC, (GLint*)&blend_sourceRGB); blend_sourceA = blend_sourceRGB; glGetIntegerv (GL_BLEND_DST, (GLint*)&blend_destinationRGB); blend_destinationA = blend_destinationRGB; } glGetIntegerv (GL_CULL_FACE_MODE, (GLint*)¶meter_cull_mode); glGetIntegerv (GL_DEPTH_FUNC, (GLint*)¶meter_depth_func); glGetBooleanv (GL_DEPTH_WRITEMASK, ¶meter_depth_mask); glGetIntegerv (GL_SHADE_MODEL, (GLint*)¶meter_shade_model); glGetIntegerv (GL_STENCIL_BITS, (GLint*)¶meter_maskl); glGetIntegerv (GL_STENCIL_FUNC, (GLint*)¶meter_stencil_func); glGetIntegerv (GL_STENCIL_VALUE_MASK, (GLint*)¶meter_stencil_mask); glGetIntegerv (GL_STENCIL_REF, ¶meter_stencil_ref); glGetIntegerv (GL_STENCIL_FAIL, (GLint*)¶meter_stencil_fail); glGetIntegerv (GL_STENCIL_PASS_DEPTH_FAIL, (GLint*)¶meter_stencil_zfail); glGetIntegerv (GL_STENCIL_PASS_DEPTH_PASS, (GLint*)¶meter_stencil_zpass); glGetIntegerv (GL_MATRIX_MODE, (GLint*)¶meter_matrixMode); GLboolean writemask[4]; glGetBooleanv (GL_COLOR_WRITEMASK, writemask); parameter_wmRed = writemask[0]; parameter_wmGreen = writemask[1]; parameter_wmBlue = writemask[2]; parameter_wmAlpha = writemask[3]; enabled_GL_DEPTH_TEST = (glIsEnabled (GL_DEPTH_TEST) == GL_TRUE); enabled_GL_BLEND = (glIsEnabled (GL_BLEND) == GL_TRUE); enabled_GL_DITHER = (glIsEnabled (GL_DITHER) == GL_TRUE); enabled_GL_STENCIL_TEST = (glIsEnabled (GL_STENCIL_TEST) == GL_TRUE); enabled_GL_CULL_FACE = (glIsEnabled (GL_CULL_FACE) == GL_TRUE); enabled_GL_POLYGON_OFFSET_FILL = (glIsEnabled (GL_POLYGON_OFFSET_FILL) == GL_TRUE); enabled_GL_LIGHTING = (glIsEnabled (GL_LIGHTING) == GL_TRUE); enabled_GL_ALPHA_TEST = (glIsEnabled (GL_ALPHA_TEST) == GL_TRUE); enabled_GL_TEXTURE_GEN_S = (glIsEnabled (GL_TEXTURE_GEN_S) == GL_TRUE); enabled_GL_TEXTURE_GEN_T = (glIsEnabled (GL_TEXTURE_GEN_T) == GL_TRUE); enabled_GL_TEXTURE_GEN_R = (glIsEnabled (GL_TEXTURE_GEN_R) == GL_TRUE); enabled_GL_TEXTURE_GEN_Q = (glIsEnabled (GL_TEXTURE_GEN_Q) == GL_TRUE); enabled_GL_FOG = (glIsEnabled (GL_FOG) == GL_TRUE); memset (boundtexture.p, 0, numImageUnits * sizeof (GLuint)); currentImageUnit = 0; currentTCUnit = 0; memset (activeUnit, 0, sizeof (activeUnit)); if (extmgr->CS_GL_ARB_multitexture) { for (i = numImageUnits; i-- > 0; ) { extmgr->glActiveTextureARB (GL_TEXTURE0_ARB + i); enabled_GL_TEXTURE_1D[i] = (glIsEnabled (GL_TEXTURE_1D) == GL_TRUE); enabled_GL_TEXTURE_2D[i] = (glIsEnabled (GL_TEXTURE_2D) == GL_TRUE); enabled_GL_TEXTURE_3D[i] = (glIsEnabled (GL_TEXTURE_3D) == GL_TRUE); enabled_GL_TEXTURE_CUBE_MAP[i] = (glIsEnabled (GL_TEXTURE_CUBE_MAP) == GL_TRUE); if (extmgr->CS_GL_ARB_texture_rectangle || extmgr->CS_GL_EXT_texture_rectangle || extmgr->CS_GL_NV_texture_rectangle) enabled_GL_TEXTURE_RECTANGLE_ARB[i] = (glIsEnabled (GL_TEXTURE_RECTANGLE_ARB) == GL_TRUE); else enabled_GL_TEXTURE_RECTANGLE_ARB[i] = false; } for (i = numTexCoords; i-- > 0; ) { extmgr->glClientActiveTextureARB (GL_TEXTURE0_ARB + i); enabled_GL_TEXTURE_COORD_ARRAY[i] = (glIsEnabled (GL_TEXTURE_COORD_ARRAY) == GL_TRUE); glGetIntegerv (GL_TEXTURE_COORD_ARRAY_SIZE, (GLint*)¶meter_tsize[i]); glGetIntegerv (GL_TEXTURE_COORD_ARRAY_STRIDE, (GLint*)¶meter_tstride[i]); glGetIntegerv (GL_TEXTURE_COORD_ARRAY_TYPE, (GLint*)¶meter_ttype[i]); glGetPointerv (GL_TEXTURE_COORD_ARRAY_POINTER, ¶meter_tpointer[i]); if (extmgr->CS_GL_ARB_vertex_buffer_object) glGetIntegerv (GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING_ARB, (GLint*)¶meter_tvbo[i]); } } else { enabled_GL_TEXTURE_1D[0] = (glIsEnabled (GL_TEXTURE_1D) == GL_TRUE); enabled_GL_TEXTURE_2D[0] = (glIsEnabled (GL_TEXTURE_2D) == GL_TRUE); enabled_GL_TEXTURE_3D[0] = (glIsEnabled (GL_TEXTURE_3D) == GL_TRUE); enabled_GL_TEXTURE_CUBE_MAP[0] = (glIsEnabled (GL_TEXTURE_CUBE_MAP) == GL_TRUE); enabled_GL_TEXTURE_COORD_ARRAY[0] = (glIsEnabled (GL_TEXTURE_COORD_ARRAY) == GL_TRUE); if (extmgr->CS_GL_ARB_texture_rectangle || extmgr->CS_GL_EXT_texture_rectangle || extmgr->CS_GL_NV_texture_rectangle) enabled_GL_TEXTURE_RECTANGLE_ARB[0] = (glIsEnabled (GL_TEXTURE_RECTANGLE_ARB) == GL_TRUE); else enabled_GL_TEXTURE_RECTANGLE_ARB[0] = false; glGetIntegerv (GL_TEXTURE_COORD_ARRAY_SIZE, (GLint*)¶meter_tsize[0]); glGetIntegerv (GL_TEXTURE_COORD_ARRAY_STRIDE, (GLint*)¶meter_tstride[0]); glGetIntegerv (GL_TEXTURE_COORD_ARRAY_TYPE, (GLint*)¶meter_ttype[0]); glGetPointerv (GL_TEXTURE_COORD_ARRAY_POINTER, ¶meter_tpointer[0]); if (extmgr->CS_GL_ARB_vertex_buffer_object) glGetIntegerv (GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING_ARB, (GLint*)¶meter_tvbo[0]); for (i = 1 ; i < numImageUnits; i++) { enabled_GL_TEXTURE_1D[i] = enabled_GL_TEXTURE_1D[0]; enabled_GL_TEXTURE_2D[i] = enabled_GL_TEXTURE_2D[0]; enabled_GL_TEXTURE_3D[i] = enabled_GL_TEXTURE_3D[0]; enabled_GL_TEXTURE_CUBE_MAP[i] = enabled_GL_TEXTURE_CUBE_MAP[0]; enabled_GL_TEXTURE_COORD_ARRAY[i] = enabled_GL_TEXTURE_COORD_ARRAY[0]; enabled_GL_TEXTURE_RECTANGLE_ARB[i] = enabled_GL_TEXTURE_RECTANGLE_ARB[0]; parameter_tsize[i] = parameter_tsize[0]; parameter_tstride[i] = parameter_tstride[0]; parameter_ttype[i] = parameter_ttype[0]; parameter_tpointer[i] = parameter_tpointer[0]; } } enabled_GL_SCISSOR_TEST = (glIsEnabled (GL_SCISSOR_TEST) == GL_TRUE); enabled_GL_VERTEX_ARRAY = (glIsEnabled (GL_VERTEX_ARRAY) == GL_TRUE); enabled_GL_COLOR_ARRAY = (glIsEnabled (GL_COLOR_ARRAY) == GL_TRUE); if (extmgr->CS_GL_EXT_secondary_color) enabled_GL_SECONDARY_COLOR_ARRAY_EXT = (glIsEnabled (GL_SECONDARY_COLOR_ARRAY_EXT) == GL_TRUE); else enabled_GL_SECONDARY_COLOR_ARRAY_EXT = false; enabled_GL_NORMAL_ARRAY = (glIsEnabled (GL_NORMAL_ARRAY) == GL_TRUE); if (extmgr->CS_GL_ARB_vertex_program) enabled_GL_VERTEX_PROGRAM_POINT_SIZE_ARB = (glIsEnabled (GL_VERTEX_PROGRAM_POINT_SIZE_ARB) == GL_TRUE); else enabled_GL_VERTEX_PROGRAM_POINT_SIZE_ARB = false; if (extmgr->CS_GL_ARB_point_sprite) enabled_GL_POINT_SPRITE_ARB = (glIsEnabled (GL_POINT_SPRITE_ARB) == GL_TRUE); else enabled_GL_POINT_SPRITE_ARB = false; memset (currentBufferID, 0, sizeof (currentBufferID)); { enum { extVBO = 1, extPBO = 2 }; static const GLenum requiredExt[boCount] = { extVBO, extVBO, extPBO, extPBO }; int boExt = 0; if (extmgr->CS_GL_ARB_vertex_buffer_object) boExt |= extVBO; if (extmgr->CS_GL_ARB_pixel_buffer_object) boExt |= extPBO; for (int b = 0; b < boCount; b++) { if (requiredExt[b] & boExt) { static const GLenum localIndexToGLBufferBinding[boCount] = { GL_ARRAY_BUFFER_BINDING_ARB, GL_ELEMENT_ARRAY_BUFFER_BINDING_ARB, GL_PIXEL_PACK_BUFFER_BINDING_ARB, GL_PIXEL_UNPACK_BUFFER_BINDING_ARB }; glGetIntegerv (localIndexToGLBufferBinding[b], (GLint*)&activeBufferID[b]); } } } memset (currentBufferID, 0, sizeof (currentBufferID)); { static const GLenum localIndexToGLBufferBinding[boCount] = { GL_ELEMENT_ARRAY_BUFFER_BINDING_ARB, GL_ARRAY_BUFFER_BINDING_ARB, GL_PIXEL_PACK_BUFFER_BINDING_ARB, GL_PIXEL_UNPACK_BUFFER_BINDING_ARB }; enum { extVBO = 1, extPBO = 2 }; static const GLenum requiredExt[boCount] = { extVBO, extVBO, extPBO, extPBO }; int boExt = 0; if (extmgr->CS_GL_ARB_vertex_buffer_object) boExt |= extVBO; if (extmgr->CS_GL_ARB_pixel_buffer_object) boExt |= extPBO; for (int b = 0; b < boCount; b++) { if (requiredExt[b] & boExt) { glGetIntegerv (localIndexToGLBufferBinding[b], (GLint*)¤tBufferID[b]); } } } glGetIntegerv (GL_VERTEX_ARRAY_SIZE, (GLint*)¶meter_vsize); glGetIntegerv (GL_VERTEX_ARRAY_STRIDE, (GLint*)¶meter_vstride); glGetIntegerv (GL_VERTEX_ARRAY_TYPE, (GLint*)¶meter_vtype); glGetPointerv (GL_VERTEX_ARRAY_POINTER, ¶meter_vpointer); if (extmgr->CS_GL_ARB_vertex_buffer_object) glGetIntegerv (GL_VERTEX_ARRAY_BUFFER_BINDING_ARB, (GLint*)¶meter_vvbo); glGetIntegerv (GL_NORMAL_ARRAY_STRIDE, (GLint*)¶meter_nstride); glGetIntegerv (GL_NORMAL_ARRAY_TYPE, (GLint*)¶meter_ntype); glGetPointerv (GL_NORMAL_ARRAY_POINTER, ¶meter_npointer); if (extmgr->CS_GL_ARB_vertex_buffer_object) glGetIntegerv (GL_NORMAL_ARRAY_BUFFER_BINDING_ARB, (GLint*)¶meter_nvbo); glGetIntegerv (GL_COLOR_ARRAY_SIZE, (GLint*)¶meter_csize); glGetIntegerv (GL_COLOR_ARRAY_STRIDE, (GLint*)¶meter_cstride); glGetIntegerv (GL_COLOR_ARRAY_TYPE, (GLint*)¶meter_ctype); glGetPointerv (GL_COLOR_ARRAY_POINTER, ¶meter_cpointer); if (extmgr->CS_GL_ARB_vertex_buffer_object) glGetIntegerv (GL_COLOR_ARRAY_BUFFER_BINDING_ARB, (GLint*)¶meter_cvbo); if (extmgr->CS_GL_EXT_secondary_color) { glGetIntegerv (GL_SECONDARY_COLOR_ARRAY_SIZE_EXT, (GLint*)¶meter_scsize); glGetIntegerv (GL_SECONDARY_COLOR_ARRAY_STRIDE_EXT, (GLint*)¶meter_scstride); glGetIntegerv (GL_SECONDARY_COLOR_ARRAY_TYPE_EXT, (GLint*)¶meter_sctype); glGetPointerv (GL_SECONDARY_COLOR_ARRAY_POINTER_EXT, ¶meter_scpointer); if (extmgr->CS_GL_ARB_vertex_buffer_object) glGetIntegerv (GL_SECONDARY_COLOR_ARRAY_BUFFER_BINDING_ARB, (GLint*)¶meter_scvbo); enabled_GL_COLOR_SUM_EXT = glIsEnabled (GL_COLOR_SUM_EXT) != GL_FALSE; } else { parameter_scsize = 0; parameter_scstride = 0; parameter_sctype = 0; parameter_scpointer = 0; enabled_GL_COLOR_SUM_EXT = false; } glGetIntegerv (GL_UNPACK_ALIGNMENT, &pixelUnpackAlignment); GLint v; glGetIntegerv (GL_UNPACK_SWAP_BYTES, &v); pixelUnpackSwapBytes = v != 0; if (extmgr->CS_GL_ARB_color_buffer_float) { GLint clampState; glGetIntegerv (GL_CLAMP_VERTEX_COLOR_ARB, &clampState); this->clampState[clampVertex] = (GLenum)clampState; glGetIntegerv (GL_CLAMP_FRAGMENT_COLOR_ARB, &clampState); this->clampState[clampFragment] = (GLenum)clampState; glGetIntegerv (GL_CLAMP_READ_COLOR_ARB, &clampState); this->clampState[clampRead] = (GLenum)clampState; } }