void bloc::draw(float time, bool picking){ if(!visible || idBloc == 0) return; glPushMatrix(); light(time); glTranslatef(positionX,positionY,positionZ); //glRotatef(orient, 0.0, 1.0, 0.0); --> awfull to detect face if bloc can have orientation float sizeDrawed = size-0.0001; static GLfloat n[6][3] = { {-1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {1.0, 0.0, 0.0}, {0.0, -1.0, 0.0}, {0.0, 0.0, 1.0}, {0.0, 0.0, -1.0} }; static GLint faces[6][4] = { {0, 1, 2, 3}, {3, 2, 6, 7}, {7, 6, 5, 4}, {4, 5, 1, 0}, {5, 6, 2, 1}, {7, 4, 0, 3} }; GLfloat v[8][3]; GLint i; v[0][0] = v[1][0] = v[2][0] = v[3][0] = -sizeDrawed / 2; v[4][0] = v[5][0] = v[6][0] = v[7][0] = sizeDrawed / 2; v[0][1] = v[1][1] = v[4][1] = v[5][1] = -sizeDrawed / 2; v[2][1] = v[3][1] = v[6][1] = v[7][1] = sizeDrawed / 2; v[0][2] = v[3][2] = v[4][2] = v[7][2] = -sizeDrawed / 2; v[1][2] = v[2][2] = v[5][2] = v[6][2] = sizeDrawed / 2; if(idBloc>0){ // Enable texturing and filled polygon mode. glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, texture); } for (i = 5; i >= 0; i--) { if(picking){ glLoadName(i+1); } glBegin(GL_QUADS); glNormal3fv(&n[i][0]); glTexCoord2f(texturePoint[0], texturePoint[3]); glVertex3fv(&v[faces[i][0]][0]); glTexCoord2f(texturePoint[0], texturePoint[2]); glVertex3fv(&v[faces[i][1]][0]); glTexCoord2f(texturePoint[1], texturePoint[2]); glVertex3fv(&v[faces[i][2]][0]); glTexCoord2f(texturePoint[1], texturePoint[3]); glVertex3fv(&v[faces[i][3]][0]); glEnd(); } if(idBloc>0) glDisable(GL_TEXTURE_2D); glPopMatrix(); }
//-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void OverlayTextBox::renderBackgroundAndBorder(OpenGLContext* oglContext, const Vec2ui& position, const Vec2ui& size, bool software) { CVF_CALLSITE_OPENGL(oglContext); // Prepare 2D pixel exact projection to draw texts Camera projCam; projCam.setViewport(position.x(), position.y(), size.x(), size.y()); projCam.setProjectionAsPixelExact2D(); projCam.setViewMatrix(Mat4d::IDENTITY); // Turn off depth test RenderStateDepth depth(false, RenderStateDepth::LESS, false); depth.applyOpenGL(oglContext); ref<ShaderProgram> backgroundShader; float vertexArray[12]; projCam.viewport()->applyOpenGL(oglContext, Viewport::DO_NOT_CLEAR); if (software) { if (ShaderProgram::supportedOpenGL(oglContext)) { ShaderProgram::useNoProgram(oglContext); } #ifndef CVF_OPENGL_ES RenderStateMaterial_FF mat; mat.enableColorMaterial(true); mat.applyOpenGL(oglContext); RenderStateLighting_FF light(false); light.applyOpenGL(oglContext); #endif projCam.applyOpenGL(); } else { glBindBuffer(GL_ARRAY_BUFFER, 0); glEnableVertexAttribArray(ShaderProgram::VERTEX); glVertexAttribPointer(ShaderProgram::VERTEX, 3, GL_FLOAT, GL_FALSE, 0, vertexArray); backgroundShader = oglContext->resourceManager()->getLinkedUnlitColorShaderProgram(oglContext); if (backgroundShader->useProgram(oglContext)) { MatrixState projMatrixState(projCam); backgroundShader->clearUniformApplyTracking(); backgroundShader->applyFixedUniforms(oglContext, projMatrixState); } } Vec3f min(1.0f, 1.0f, 0.0f); Vec3f max(static_cast<float>(size.x() - 1), static_cast<float>(size.y() - 1), 0.0f); // Setup the vertex array float* v1 = &vertexArray[0]; float* v2 = &vertexArray[3]; float* v3 = &vertexArray[6]; float* v4 = &vertexArray[9]; v1[0] = min.x(); v1[1] = min.y(); v1[2] = 0.0f; v2[0] = max.x(); v2[1] = min.y(); v2[2] = 0.0f; v3[0] = max.x(); v3[1] = max.y(); v3[2] = 0.0f; v4[0] = min.x(); v4[1] = max.y(); v4[2] = 0.0f; if (m_drawBackground) { if (software) { #ifndef CVF_OPENGL_ES glColor4fv(m_backgroundColor.ptr()); glBegin(GL_TRIANGLE_FAN); glVertex3fv(v1); glVertex3fv(v2); glVertex3fv(v3); glVertex3fv(v4); glEnd(); #endif } else { // Draw background UniformFloat backgroundColor("u_color", Color4f(m_backgroundColor)); backgroundShader->applyUniform(oglContext, backgroundColor); glDrawArrays(GL_TRIANGLE_FAN, 0, 4); } } if (m_drawBorder) { if (software) { #ifndef CVF_OPENGL_ES glColor3fv(m_borderColor.ptr()); glBegin(GL_LINE_LOOP); glVertex3fv(v1); glVertex3fv(v2); glVertex3fv(v3); glVertex3fv(v4); glEnd(); #endif } else { UniformFloat borderColor("u_color", Color4f(m_borderColor)); backgroundShader->applyUniform(oglContext, borderColor); RenderStateLine line(static_cast<float>(3)); line.applyOpenGL(oglContext); // Draw border glDrawArrays(GL_LINE_LOOP, 0, 4); RenderStateLine resetLine; resetLine.applyOpenGL(oglContext); } } }
static void Render() { static float color[8][3] = { {1.0, 1.0, 0.0}, {1.0, 0.0, 0.0}, {0.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 1.0, 1.0}, {1.0, 1.0, 1.0}, {1.0, 0.0, 1.0}, {0.0, 0.0, 1.0} }; static float cube[8][3] = { {0.5, 0.5, -0.5}, {0.5, -0.5, -0.5}, {-0.5, -0.5, -0.5}, {-0.5, 0.5, -0.5}, {-0.5, 0.5, 0.5}, {0.5, 0.5, 0.5}, {0.5, -0.5, 0.5}, {-0.5, -0.5, 0.5} }; /* Do our drawing, too. */ // glClearColor(0.0, 0.0, 0.0, 1.0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glBegin(GL_QUADS); #ifdef SHADED_CUBE glColor3fv(color[0]); glVertex3fv(cube[0]); glColor3fv(color[1]); glVertex3fv(cube[1]); glColor3fv(color[2]); glVertex3fv(cube[2]); glColor3fv(color[3]); glVertex3fv(cube[3]); glColor3fv(color[3]); glVertex3fv(cube[3]); glColor3fv(color[4]); glVertex3fv(cube[4]); glColor3fv(color[7]); glVertex3fv(cube[7]); glColor3fv(color[2]); glVertex3fv(cube[2]); glColor3fv(color[0]); glVertex3fv(cube[0]); glColor3fv(color[5]); glVertex3fv(cube[5]); glColor3fv(color[6]); glVertex3fv(cube[6]); glColor3fv(color[1]); glVertex3fv(cube[1]); glColor3fv(color[5]); glVertex3fv(cube[5]); glColor3fv(color[4]); glVertex3fv(cube[4]); glColor3fv(color[7]); glVertex3fv(cube[7]); glColor3fv(color[6]); glVertex3fv(cube[6]); glColor3fv(color[5]); glVertex3fv(cube[5]); glColor3fv(color[0]); glVertex3fv(cube[0]); glColor3fv(color[3]); glVertex3fv(cube[3]); glColor3fv(color[4]); glVertex3fv(cube[4]); glColor3fv(color[6]); glVertex3fv(cube[6]); glColor3fv(color[1]); glVertex3fv(cube[1]); glColor3fv(color[2]); glVertex3fv(cube[2]); glColor3fv(color[7]); glVertex3fv(cube[7]); #else /* flat cube */ glColor3f(1.0, 0.0, 0.0); glVertex3fv(cube[0]); glVertex3fv(cube[1]); glVertex3fv(cube[2]); glVertex3fv(cube[3]); glColor3f(0.0, 1.0, 0.0); glVertex3fv(cube[3]); glVertex3fv(cube[4]); glVertex3fv(cube[7]); glVertex3fv(cube[2]); glColor3f(0.0, 0.0, 1.0); glVertex3fv(cube[0]); glVertex3fv(cube[5]); glVertex3fv(cube[6]); glVertex3fv(cube[1]); glColor3f(0.0, 1.0, 1.0); glVertex3fv(cube[5]); glVertex3fv(cube[4]); glVertex3fv(cube[7]); glVertex3fv(cube[6]); glColor3f(1.0, 1.0, 0.0); glVertex3fv(cube[5]); glVertex3fv(cube[0]); glVertex3fv(cube[3]); glVertex3fv(cube[4]); glColor3f(1.0, 0.0, 1.0); glVertex3fv(cube[6]); glVertex3fv(cube[1]); glVertex3fv(cube[2]); glVertex3fv(cube[7]); #endif /* SHADED_CUBE */ glEnd(); glMatrixMode(GL_MODELVIEW); glRotatef(5.0, 1.0, 1.0, 1.0); }
void DrawJet() { GLTVector3 vNormal; // Storeage for calculated surface normal // Set material color glColor3ub(128, 128, 128); glBegin(GL_TRIANGLES); glNormal3f(0.0f, -1.0f, 0.0f); glVertex3f(0.0f, 0.0f, 60.0f); glVertex3f(-15.0f, 0.0f, 30.0f); glVertex3f(15.0f,0.0f,30.0f); GLTVector3 vPoints[3] = {{ 15.0f, 0.0f, 30.0f}, { 0.0f, 15.0f, 30.0f}, { 0.0f, 0.0f, 60.0f}}; // Calculate the normal for the plane gltGetNormalVector(vPoints[0], vPoints[1], vPoints[2], vNormal); glNormal3fv(vNormal); glVertex3fv(vPoints[0]); glVertex3fv(vPoints[1]); glVertex3fv(vPoints[2]); { GLTVector3 vPoints[3] = {{ 0.0f, 0.0f, 60.0f }, { 0.0f, 15.0f, 30.0f }, { -15.0f, 0.0f, 30.0f }}; gltGetNormalVector(vPoints[0], vPoints[1], vPoints[2], vNormal); glNormal3fv(vNormal); glVertex3fv(vPoints[0]); glVertex3fv(vPoints[1]); glVertex3fv(vPoints[2]); } // Body of the Plane //////////////////////// { GLTVector3 vPoints[3] = {{ -15.0f, 0.0f, 30.0f }, { 0.0f, 15.0f, 30.0f }, { 0.0f, 0.0f, -56.0f }}; gltGetNormalVector(vPoints[0], vPoints[1], vPoints[2], vNormal); glNormal3fv(vNormal); glVertex3fv(vPoints[0]); glVertex3fv(vPoints[1]); glVertex3fv(vPoints[2]); } { GLTVector3 vPoints[3] = {{ 0.0f, 0.0f, -56.0f }, { 0.0f, 15.0f, 30.0f }, { 15.0f,0.0f,30.0f }}; gltGetNormalVector(vPoints[0], vPoints[1], vPoints[2], vNormal); glNormal3fv(vNormal); glVertex3fv(vPoints[0]); glVertex3fv(vPoints[1]); glVertex3fv(vPoints[2]); } glNormal3f(0.0f, -1.0f, 0.0f); glVertex3f(15.0f,0.0f,30.0f); glVertex3f(-15.0f, 0.0f, 30.0f); glVertex3f(0.0f, 0.0f, -56.0f); /////////////////////////////////////////////// // Left wing // Large triangle for bottom of wing { GLTVector3 vPoints[3] = {{ 0.0f,2.0f,27.0f }, { -60.0f, 2.0f, -8.0f }, { 60.0f, 2.0f, -8.0f }}; gltGetNormalVector(vPoints[0], vPoints[1], vPoints[2], vNormal); glNormal3fv(vNormal); glVertex3fv(vPoints[0]); glVertex3fv(vPoints[1]); glVertex3fv(vPoints[2]); } { GLTVector3 vPoints[3] = {{ 60.0f, 2.0f, -8.0f}, {0.0f, 7.0f, -8.0f}, {0.0f,2.0f,27.0f }}; gltGetNormalVector(vPoints[0], vPoints[1], vPoints[2], vNormal); glNormal3fv(vNormal); glVertex3fv(vPoints[0]); glVertex3fv(vPoints[1]); glVertex3fv(vPoints[2]); } { GLTVector3 vPoints[3] = {{60.0f, 2.0f, -8.0f}, {-60.0f, 2.0f, -8.0f}, {0.0f,7.0f,-8.0f }}; gltGetNormalVector(vPoints[0], vPoints[1], vPoints[2], vNormal); glNormal3fv(vNormal); glVertex3fv(vPoints[0]); glVertex3fv(vPoints[1]); glVertex3fv(vPoints[2]); } { GLTVector3 vPoints[3] = {{0.0f,2.0f,27.0f}, {0.0f, 7.0f, -8.0f}, {-60.0f, 2.0f, -8.0f}}; gltGetNormalVector(vPoints[0], vPoints[1], vPoints[2], vNormal); glNormal3fv(vNormal); glVertex3fv(vPoints[0]); glVertex3fv(vPoints[1]); glVertex3fv(vPoints[2]); } // Tail section/////////////////////////////// // Bottom of back fin glNormal3f(0.0f, -1.0f, 0.0f); glVertex3f(-30.0f, -0.50f, -57.0f); glVertex3f(30.0f, -0.50f, -57.0f); glVertex3f(0.0f,-0.50f,-40.0f); { GLTVector3 vPoints[3] = {{ 0.0f,-0.5f,-40.0f }, {30.0f, -0.5f, -57.0f}, {0.0f, 4.0f, -57.0f }}; gltGetNormalVector(vPoints[0], vPoints[1], vPoints[2], vNormal); glNormal3fv(vNormal); glVertex3fv(vPoints[0]); glVertex3fv(vPoints[1]); glVertex3fv(vPoints[2]); } { GLTVector3 vPoints[3] = {{ 0.0f, 4.0f, -57.0f }, { -30.0f, -0.5f, -57.0f }, { 0.0f,-0.5f,-40.0f }}; gltGetNormalVector(vPoints[0], vPoints[1], vPoints[2], vNormal); glNormal3fv(vNormal); glVertex3fv(vPoints[0]); glVertex3fv(vPoints[1]); glVertex3fv(vPoints[2]); } { GLTVector3 vPoints[3] = {{ 30.0f,-0.5f,-57.0f }, { -30.0f, -0.5f, -57.0f }, { 0.0f, 4.0f, -57.0f }}; gltGetNormalVector(vPoints[0], vPoints[1], vPoints[2], vNormal); glNormal3fv(vNormal); glVertex3fv(vPoints[0]); glVertex3fv(vPoints[1]); glVertex3fv(vPoints[2]); } { GLTVector3 vPoints[3] = {{ 0.0f,0.5f,-40.0f }, { 3.0f, 0.5f, -57.0f }, { 0.0f, 25.0f, -65.0f }}; gltGetNormalVector(vPoints[0], vPoints[1], vPoints[2], vNormal); glNormal3fv(vNormal); glVertex3fv(vPoints[0]); glVertex3fv(vPoints[1]); glVertex3fv(vPoints[2]); } { GLTVector3 vPoints[3] = {{ 0.0f, 25.0f, -65.0f }, { -3.0f, 0.5f, -57.0f}, { 0.0f,0.5f,-40.0f }}; gltGetNormalVector(vPoints[0], vPoints[1], vPoints[2], vNormal); glNormal3fv(vNormal); glVertex3fv(vPoints[0]); glVertex3fv(vPoints[1]); glVertex3fv(vPoints[2]); } { GLTVector3 vPoints[3] = {{ 3.0f,0.5f,-57.0f }, { -3.0f, 0.5f, -57.0f }, { 0.0f, 25.0f, -65.0f }}; gltGetNormalVector(vPoints[0], vPoints[1], vPoints[2], vNormal); glNormal3fv(vNormal); glVertex3fv(vPoints[0]); glVertex3fv(vPoints[1]); glVertex3fv(vPoints[2]); } glEnd(); }
// // Load OBJ file // int LoadOBJ(const char* file) { int k; int Nv,Nn,Nt; // Number of vertex, normal and textures int Mv,Mn,Mt; // Maximum vertex, normal and textures float* V; // Array of vertexes float* N; // Array of normals float* T; // Array if textures coordinates char* line; // Line pointer char* str; // String pointer // Open file FILE* f = fopen(file,"r"); if (!f) Fatal("Cannot open file %s\n",file); // Reset materials mtl = NULL; Nmtl = 0; // Start new displaylist int list = glGenLists(1); glNewList(list,GL_COMPILE); // Push attributes for textures glPushAttrib(GL_TEXTURE_BIT); // Read vertexes and facets V = N = T = NULL; Nv = Nn = Nt = 0; Mv = Mn = Mt = 0; while ((line = readline(f))) { // Vertex coordinates (always 3) if (line[0]=='v' && line[1]==' ') readcoord(line+2,3,&V,&Nv,&Mv); // Normal coordinates (always 3) else if (line[0]=='v' && line[1] == 'n') readcoord(line+2,3,&N,&Nn,&Mn); // Texture coordinates (always 2) else if (line[0]=='v' && line[1] == 't') readcoord(line+2,2,&T,&Nt,&Mt); // Read and draw facets else if (line[0]=='f') { line++; // Read Vertex/Texture/Normal triplets glBegin(GL_POLYGON); while ((str = getword(&line))) { int Kv,Kt,Kn; // Try Vertex/Texture/Normal triplet if (sscanf(str,"%d/%d/%d",&Kv,&Kt,&Kn)==3) { if (Kv<0 || Kv>Nv/3) Fatal("Vertex %d out of range 1-%d\n",Kv,Nv/3); if (Kn<0 || Kn>Nn/3) Fatal("Normal %d out of range 1-%d\n",Kn,Nn/3); if (Kt<0 || Kt>Nt/2) Fatal("Texture %d out of range 1-%d\n",Kt,Nt/2); } // Try Vertex//Normal pairs else if (sscanf(str,"%d//%d",&Kv,&Kn)==2) { if (Kv<0 || Kv>Nv/3) Fatal("Vertex %d out of range 1-%d\n",Kv,Nv/3); if (Kn<0 || Kn>Nn/3) Fatal("Normal %d out of range 1-%d\n",Kn,Nn/3); Kt = 0; } // Try Vertex index else if (sscanf(str,"%d",&Kv)==1) { if (Kv<0 || Kv>Nv/3) Fatal("Vertex %d out of range 1-%d\n",Kv,Nv/3); Kn = 0; Kt = 0; } // This is an error else Fatal("Invalid facet %s\n",str); // Draw vectors if (Kt) glTexCoord2fv(T+2*(Kt-1)); if (Kn) glNormal3fv(N+3*(Kn-1)); if (Kv) glVertex3fv(V+3*(Kv-1)); } glEnd(); } // Use material else if ((str = readstr(line,"usemtl"))){ SetMaterial(str); } // Load materials else if ((str = readstr(line,"mtllib"))){ LoadMaterial(str); } // Skip this line } fclose(f); // Pop attributes (textures) glPopAttrib(); glEndList(); // Free materials for (k=0;k<Nmtl;k++) free(mtl[k].name); free(mtl); // Free arrays free(V); free(T); free(N); return list; }
static void do_EvalCoord2f( GLcontext* ctx, GLfloat u, GLfloat v ) { /** Color Index **/ if (ctx->Eval.Map2Index) { GLfloat findex; struct gl_2d_map *map = &ctx->EvalMap.Map2Index; GLfloat uu = (u - map->u1) * map->du; GLfloat vv = (v - map->v1) * map->dv; _math_horner_bezier_surf(map->Points, &findex, uu, vv, 1, map->Uorder, map->Vorder); glIndexi( (GLuint) (GLint) findex ); } /** Color **/ if (ctx->Eval.Map2Color4) { GLfloat fcolor[4]; struct gl_2d_map *map = &ctx->EvalMap.Map2Color4; GLfloat uu = (u - map->u1) * map->du; GLfloat vv = (v - map->v1) * map->dv; _math_horner_bezier_surf(map->Points, fcolor, uu, vv, 4, map->Uorder, map->Vorder); glColor4fv( fcolor ); } /** Normal **/ if (ctx->Eval.Map2Normal && (!ctx->Eval.AutoNormal || (!ctx->Eval.Map2Vertex3 && !ctx->Eval.Map2Vertex4))) { GLfloat normal[3]; struct gl_2d_map *map = &ctx->EvalMap.Map2Normal; GLfloat uu = (u - map->u1) * map->du; GLfloat vv = (v - map->v1) * map->dv; _math_horner_bezier_surf(map->Points, normal, uu, vv, 3, map->Uorder, map->Vorder); glNormal3fv( normal ); } /** Texture Coordinates **/ if (ctx->Eval.Map2TextureCoord4) { GLfloat texcoord[4]; struct gl_2d_map *map = &ctx->EvalMap.Map2Texture4; GLfloat uu = (u - map->u1) * map->du; GLfloat vv = (v - map->v1) * map->dv; _math_horner_bezier_surf(map->Points, texcoord, uu, vv, 4, map->Uorder, map->Vorder); glTexCoord4fv( texcoord ); } else if (ctx->Eval.Map2TextureCoord3) { GLfloat texcoord[4]; struct gl_2d_map *map = &ctx->EvalMap.Map2Texture3; GLfloat uu = (u - map->u1) * map->du; GLfloat vv = (v - map->v1) * map->dv; _math_horner_bezier_surf(map->Points, texcoord, uu, vv, 3, map->Uorder, map->Vorder); glTexCoord3fv( texcoord ); } else if (ctx->Eval.Map2TextureCoord2) { GLfloat texcoord[4]; struct gl_2d_map *map = &ctx->EvalMap.Map2Texture2; GLfloat uu = (u - map->u1) * map->du; GLfloat vv = (v - map->v1) * map->dv; _math_horner_bezier_surf(map->Points, texcoord, uu, vv, 2, map->Uorder, map->Vorder); glTexCoord2fv( texcoord ); } else if (ctx->Eval.Map2TextureCoord1) { GLfloat texcoord[4]; struct gl_2d_map *map = &ctx->EvalMap.Map2Texture1; GLfloat uu = (u - map->u1) * map->du; GLfloat vv = (v - map->v1) * map->dv; _math_horner_bezier_surf(map->Points, texcoord, uu, vv, 1, map->Uorder, map->Vorder); glTexCoord1fv( texcoord ); } /** Vertex **/ if(ctx->Eval.Map2Vertex4) { GLfloat vertex[4]; GLfloat normal[3]; struct gl_2d_map *map = &ctx->EvalMap.Map2Vertex4; GLfloat uu = (u - map->u1) * map->du; GLfloat vv = (v - map->v1) * map->dv; if (ctx->Eval.AutoNormal) { GLfloat du[4], dv[4]; _math_de_casteljau_surf(map->Points, vertex, du, dv, uu, vv, 4, map->Uorder, map->Vorder); CROSS_PROD(normal, du, dv); NORMALIZE_3FV(normal); glNormal3fv( normal ); glVertex4fv( vertex ); } else { _math_horner_bezier_surf(map->Points, vertex, uu, vv, 4, map->Uorder, map->Vorder); glVertex4fv( vertex ); } } else if (ctx->Eval.Map2Vertex3) { GLfloat vertex[4]; struct gl_2d_map *map = &ctx->EvalMap.Map2Vertex3; GLfloat uu = (u - map->u1) * map->du; GLfloat vv = (v - map->v1) * map->dv; if (ctx->Eval.AutoNormal) { GLfloat du[3], dv[3]; GLfloat normal[3]; _math_de_casteljau_surf(map->Points, vertex, du, dv, uu, vv, 3, map->Uorder, map->Vorder); CROSS_PROD(normal, du, dv); NORMALIZE_3FV(normal); glNormal3fv( normal ); glVertex3fv( vertex ); } else { _math_horner_bezier_surf(map->Points, vertex, uu, vv, 3, map->Uorder, map->Vorder); glVertex3fv( vertex ); } } }
void cc2DLabel::drawMeOnly3D(CC_DRAW_CONTEXT& context) { assert(!m_points.empty()); //standard case: list names pushing bool pushName = MACRO_DrawEntityNames(context); if (pushName) glPushName(getUniqueID()); const float c_sizeFactor = 4.0f; bool loop=false; size_t count = m_points.size(); switch (count) { case 3: { glPushAttrib(GL_COLOR_BUFFER_BIT); glEnable(GL_BLEND); //we draw the triangle glColor4ub(255,255,0,128); glBegin(GL_TRIANGLES); for (unsigned i=0;i<count;++i) glVertex3fv(m_points[i].cloud->getPoint(m_points[i].index)->u); glEnd(); glPopAttrib(); loop=true; } case 2: { //segment width glPushAttrib(GL_LINE_BIT); glLineWidth(c_sizeFactor); //we draw the segments if (isSelected()) glColor3ubv(ccColor::red); else glColor3ubv(ccColor::green); glBegin(GL_LINES); for (unsigned i=0; i<count; i++) { if (i+1<count || loop) { glVertex3fv(m_points[i].cloud->getPoint(m_points[i].index)->u); glVertex3fv(m_points[(i+1)%count].cloud->getPoint(m_points[(i+1)%count].index)->u); } } glEnd(); glPopAttrib(); } case 1: { //display point marker as spheres { if (!c_unitPointMarker) { c_unitPointMarker = QSharedPointer<ccSphere>(new ccSphere(1.0f,0,"PointMarker",12)); c_unitPointMarker->showColors(true); c_unitPointMarker->setVisible(true); c_unitPointMarker->setEnabled(true); } //build-up point maker own 'context' bool pushName = MACRO_DrawEntityNames(context); CC_DRAW_CONTEXT markerContext = context; markerContext.flags &= (~CC_DRAW_ENTITY_NAMES); //we must remove the 'push name flag' so that the sphere doesn't push its own! markerContext._win = 0; if (isSelected() && !pushName) c_unitPointMarker->setColor(ccColor::red); else c_unitPointMarker->setColor(ccColor::magenta); for (unsigned i=0; i<count; i++) { glMatrixMode(GL_MODELVIEW); glPushMatrix(); const CCVector3* P = m_points[i].cloud->getPoint(m_points[i].index); glTranslatef(P->x,P->y,P->z); glScalef(context.pickedPointsRadius,context.pickedPointsRadius,context.pickedPointsRadius); c_unitPointMarker->draw(markerContext); glPopMatrix(); } } if (m_dispIn3D && !pushName) //no need to display label in point picking mode { QFont font(context._win->getTextDisplayFont()); //font.setPointSize(font.pointSize()+2); font.setBold(true); //draw their name glPushAttrib(GL_DEPTH_BUFFER_BIT); glDisable(GL_DEPTH_TEST); for (unsigned j=0; j<count; j++) { const CCVector3* P = m_points[j].cloud->getPoint(m_points[j].index); QString title = (count == 1 ? getName() : QString("P#%0").arg(m_points[j].index)); context._win->display3DLabel( title, *P+CCVector3(context.pickedPointsTextShift), ccColor::magenta, font); } glPopAttrib(); } } } if (pushName) glPopName(); }
/////////////////////////////////////////////////////////////////////////////// // draw frustum /////////////////////////////////////////////////////////////////////////////// void ModelGL::drawFrustum(float fovY, float aspectRatio, float nearPlane, float farPlane) { float tangent = tanf(fovY/2 * DEG2RAD); float nearHeight = nearPlane * tangent; float nearWidth = nearHeight * aspectRatio; float farHeight = farPlane * tangent; float farWidth = farHeight * aspectRatio; // compute 8 vertices of the frustum float vertices[8][3]; // near top right vertices[0][0] = nearWidth; vertices[0][1] = nearHeight; vertices[0][2] = -nearPlane; // near top left vertices[1][0] = -nearWidth; vertices[1][1] = nearHeight; vertices[1][2] = -nearPlane; // near bottom left vertices[2][0] = -nearWidth; vertices[2][1] = -nearHeight; vertices[2][2] = -nearPlane; // near bottom right vertices[3][0] = nearWidth; vertices[3][1] = -nearHeight; vertices[3][2] = -nearPlane; // far top right vertices[4][0] = farWidth; vertices[4][1] = farHeight; vertices[4][2] = -farPlane; // far top left vertices[5][0] = -farWidth; vertices[5][1] = farHeight; vertices[5][2] = -farPlane; // far bottom left vertices[6][0] = -farWidth; vertices[6][1] = -farHeight; vertices[6][2] = -farPlane; // far bottom right vertices[7][0] = farWidth; vertices[7][1] = -farHeight; vertices[7][2] = -farPlane; float colorLine1[4] = { 0.7f, 0.7f, 0.7f, 0.7f }; float colorLine2[4] = { 0.2f, 0.2f, 0.2f, 0.7f }; float colorPlane[4] = { 0.5f, 0.5f, 0.5f, 0.5f }; glDisable(GL_LIGHTING); glDisable(GL_CULL_FACE); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glBegin(GL_LINES); glColor4fv(colorLine2); glVertex3f(0, 0, 0); glColor4fv(colorLine1); glVertex3fv(vertices[4]); glColor4fv(colorLine2); glVertex3f(0, 0, 0); glColor4fv(colorLine1); glVertex3fv(vertices[5]); glColor4fv(colorLine2); glVertex3f(0, 0, 0); glColor4fv(colorLine1); glVertex3fv(vertices[6]); glColor4fv(colorLine2); glVertex3f(0, 0, 0); glColor4fv(colorLine1); glVertex3fv(vertices[7]); glEnd(); glColor4fv(colorLine1); glBegin(GL_LINE_LOOP); glVertex3fv(vertices[4]); glVertex3fv(vertices[5]); glVertex3fv(vertices[6]); glVertex3fv(vertices[7]); glEnd(); glColor4fv(colorLine1); glBegin(GL_LINE_LOOP); glVertex3fv(vertices[0]); glVertex3fv(vertices[1]); glVertex3fv(vertices[2]); glVertex3fv(vertices[3]); glEnd(); glColor4fv(colorPlane); glBegin(GL_QUADS); glVertex3fv(vertices[0]); glVertex3fv(vertices[1]); glVertex3fv(vertices[2]); glVertex3fv(vertices[3]); glVertex3fv(vertices[4]); glVertex3fv(vertices[5]); glVertex3fv(vertices[6]); glVertex3fv(vertices[7]); glEnd(); glEnable(GL_CULL_FACE); glEnable(GL_LIGHTING); }
void Asteroid::Render(vect2 relative,bool center){ glPushMatrix(); //glMatrixMode (GL_PROJECTION); // Select The Projection Matrix //glLoadIdentity (); //glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer //glLoadIdentity(); // Reset The Current Matrix //glTranslatef(0.0f,0.0f,-5.0f); // Move Into The Screen 5 Units //glEnable(GL_TEXTURE_2D); // Enable Texture Mapping ( NEW ) //glShadeModel(GL_SMOOTH); // Enable Smooth Shading //glClearColor(0.0f, 0.0f, 0.0f, 0.5f); // Black Background //glClearDepth(1.0f); // Depth Buffer Setup //glEnable(GL_DEPTH_TEST); // Enables Depth Testing //glDepthFunc(GL_LEQUAL); // The Type Of Depth Testing To Do //glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Really Nice Perspective if (center){ glTranslatef(-relative.x,-relative.y,0); }else{ glTranslatef(position.x-relative.x,position.y-relative.y,0); } glRotatef(angledeg,1.0f,1.0f,1.0f); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 128, 128, 0, GL_BGR, GL_UNSIGNED_BYTE, bmpdata); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); // Linear Filtering glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); // Linear Filtering glEnable(GL_TEXTURE_2D); // Enable Texture Mapping glShadeModel(GL_SMOOTH); glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); // Set The Blending Function For Translucency glEnable(GL_BLEND); //glCullFace(GL_FRONT_AND_BACK); //glDisable(GL_DEPTH_TEST); //glBindTexture(GL_TEXTURE_2D, textureid); glColor4f(1,1,1,1); /* glBegin(GL_TRIANGLES); glTexCoord2f(0,0); glVertex3f(-1, -1, -0.1f); glTexCoord2f(1.0, 0); glVertex3f(1.0, -1, -0.1f); glTexCoord2f(1.0, 1.0); glVertex3f(1.0, 1.0, -0.0f); glEnd(); */ uint8_t texture_swap = 1; glBegin(GL_TRIANGLE_FAN); glTexCoord2f(0 , 0); glVertex3fv((GLfloat*)&vface[0]); glTexCoord2f(1.0, 0); glVertex3fv((GLfloat*)&vface[1]); for (int i=2;i<=num_faces;i++){ if (texture_swap){ texture_swap = 0; glTexCoord2f(1.0, 1.0); }else{ texture_swap = 1; glTexCoord2f(1.0, 0); } glVertex3fv((GLfloat*)&vface[i]); } if (texture_swap){ texture_swap = 0; glTexCoord2f(1.0, 1.0); }else{ texture_swap = 1; glTexCoord2f(1.0, 0); } glVertex3fv((GLfloat*)&vface[1]); glEnd(); //Bottom glBegin(GL_TRIANGLE_FAN); glTexCoord2f(0 , 0); glVertex3fv((GLfloat*)&vbface[0]); glTexCoord2f(1.0, 0); glVertex3fv((GLfloat*)&vbface[1]); for (int i=2;i<=num_bfaces;i++){ if (texture_swap){ texture_swap = 0; glTexCoord2f(1.0, 1.0); }else{ texture_swap = 1; glTexCoord2f(1.0, 0); } glVertex3fv((GLfloat*)&vbface[i]); } if (texture_swap){ texture_swap = 0; glTexCoord2f(1.0, 1.0); }else{ texture_swap = 1; glTexCoord2f(1.0, 0); } glVertex3fv((GLfloat*)&vbface[1]); glEnd(); glBegin(GL_TRIANGLE_STRIP); glTexCoord2f(0 , 0); glVertex3fv((GLfloat*)&vface[1]); glTexCoord2f(1.0, 0); glVertex3fv((GLfloat*)&vbface[1]); for (int i=2;i<=num_bfaces;i++){ if (texture_swap){ texture_swap = 0; glTexCoord2f(1.0, 1.0); }else{ texture_swap = 1; glTexCoord2f(1.0, 0); } glVertex3fv((GLfloat*)&vface[i]); glVertex3fv((GLfloat*)&vbface[i]); } if (texture_swap){ texture_swap = 0; glTexCoord2f(1.0, 1.0); }else{ texture_swap = 1; glTexCoord2f(1.0, 0); } glVertex3fv((GLfloat*)&vface[1]); glEnd(); /* glBegin(GL_QUADS); // Front Face glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f); // Bottom Left Of The Texture and Quad glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 1.0f); // Bottom Right Of The Texture and Quad glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, 1.0f); // Top Right Of The Texture and Quad glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, 1.0f); // Top Left Of The Texture and Quad // Back Face glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f); // Bottom Right Of The Texture and Quad glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f); // Top Right Of The Texture and Quad glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, 1.0f, -1.0f); // Top Left Of The Texture and Quad glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f); // Bottom Left Of The Texture and Quad // Top Face glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f); // Top Left Of The Texture and Quad glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, 1.0f, 1.0f); // Bottom Left Of The Texture and Quad glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, 1.0f, 1.0f); // Bottom Right Of The Texture and Quad glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, -1.0f); // Top Right Of The Texture and Quad // Bottom Face glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, -1.0f, -1.0f); // Top Right Of The Texture and Quad glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, -1.0f, -1.0f); // Top Left Of The Texture and Quad glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 1.0f); // Bottom Left Of The Texture and Quad glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f); // Bottom Right Of The Texture and Quad // Right face glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f); // Bottom Right Of The Texture and Quad glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, -1.0f); // Top Right Of The Texture and Quad glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, 1.0f, 1.0f); // Top Left Of The Texture and Quad glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 1.0f); // Bottom Left Of The Texture and Quad // Left Face glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f); // Bottom Left Of The Texture and Quad glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f); // Bottom Right Of The Texture and Quad glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, 1.0f, 1.0f); // Top Right Of The Texture and Quad glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f); // Top Left Of The Texture and Quad glEnd(); */ //glDisable(GL_TEXTURE_2D); //glEnable(GL_DEPTH_TEST); glPopMatrix(); }
void wxGL_PMFCanvas::draw_grid(vector3d min, vector3d max, vector3d point){ ERROR_CHECK; int u, v, w; switch(UI_plane){ case XZ_PLANE: u=0; v=2; w=1; break; case XY_PLANE: u=0; v=1; w=2; break; case YZ_PLANE: u=1; v=2; w=0; break; default: u=0; v=2; w=1; } vector3d pnt; pnt[w] = point[w]; glColor4ubv( (GLubyte*)color(255,255,255,255).col); // float rad = Distance(get_eye_pos(), point); float rad = (max.x-min.x+max.y-min.y+max.z-min.z)/3.0f; glLineWidth(1.1f); glBegin(GL_LINES); float i; float scale = pow(10.0f, int(log(abs(rad)))/int(log(10.0f))-2); //how far the types of grid lines will be apart //make finest lines around the thing your editing float u_dir = point[u]/abs(point[u]) * 0.5; float v_dir = point[v]/abs(point[v]) * 0.5; float pu = int((point[u])/scale+u_dir)*scale; float pv = int((point[v])/scale+v_dir)*scale; for(i = -10; i<11; i++){ pnt[u] = scale * i + pu; pnt[v] = scale * 10 + pv; glVertex3fv((GLfloat *)&pnt); pnt[u] = scale * i + pu; pnt[v] = scale * -10 + pv; glVertex3fv((GLfloat *)&pnt); pnt[v] = scale * i + pv; pnt[u] = scale * 10 + pu; glVertex3fv((GLfloat *)&pnt); pnt[v] = scale * i + pv; pnt[u] = scale * -10 + pu; glVertex3fv((GLfloat *)&pnt); } //make lines withing the bounding box scale *= 10.0f; glEnd(); ERROR_CHECK; glLineWidth(2.1f); glBegin(GL_LINES); float min_u = int((min[u]-(1.0f))/scale)*scale; float max_u = int((max[u]+(1.0f))/scale)*scale; float min_v = int((min[v]-(1.0f))/scale)*scale; float max_v = int((max[v]+(1.0f))/scale)*scale; for(i = min_u; i<=max_u; i+=scale){ pnt[u] = i; pnt[v] = max_v; glVertex3fv((GLfloat *)&pnt); pnt[u] = i; pnt[v] = min_v; glVertex3fv((GLfloat *)&pnt); } for(i = min_v; i<=max_v; i+=scale){ pnt[v] = i; pnt[u] = max_u; glVertex3fv((GLfloat *)&pnt); pnt[v] = i; pnt[u] = min_u; glVertex3fv((GLfloat *)&pnt); } glEnd(); ERROR_CHECK; glLineWidth(3.1f); glBegin(GL_LINES); scale *= 10; //make big lines for(i = -10; i<11; i++){ pnt[u] = scale * i; pnt[v] = scale * 10; glVertex3fv((GLfloat *)&pnt); pnt[u] = scale * i; pnt[v] = scale * -10; glVertex3fv((GLfloat *)&pnt); pnt[v] = scale * i; pnt[u] = scale * 10; glVertex3fv((GLfloat *)&pnt); pnt[v] = scale * i; pnt[u] = scale * -10; glVertex3fv((GLfloat *)&pnt); } glEnd(); ERROR_CHECK; glLineWidth(1.0f); ERROR_CHECK; }
void drawobject (object3D *obj) { int *p = NULL; float *n = NULL; if (obj) { if (!obj->vbo_geladen) { // haben keine VBOs glBegin (GL_TRIANGLES); for (int i=0; i < obj->numtris; ++i) { switch (obj->normal_mode) { case 0: //set no normals p=&obj->tris[3*i]; glVertex3fv (&obj->points[3*p[0]]); glVertex3fv (&obj->points[3*p[1]]); glVertex3fv (&obj->points[3*p[2]]); break; case 1: //set surface normal n = &(obj->f_normals[3*i]); glNormal3fv(n); p=&obj->tris[3*i]; glVertex3fv (&obj->points[3*p[0]]); glVertex3fv (&obj->points[3*p[1]]); glVertex3fv (&obj->points[3*p[2]]); break; case 2: p=&obj->tris[3*i]; // set vertex normals glNormal3fv (&obj->p_normals[3*p[0]]); glVertex3fv (&obj->points[3*p[0]]); glNormal3fv (&obj->p_normals[3*p[1]]); glVertex3fv (&obj->points[3*p[1]]); glNormal3fv (&obj->p_normals[3*p[2]]); glVertex3fv (&obj->points[3*p[2]]); break; } } glEnd(); } else { // haben VBOs glEnableClientState(GL_VERTEX_ARRAY); if (obj->normal_mode == 2) { // Normalen per Vertex glEnableClientState(GL_NORMAL_ARRAY); glBindBuffer(GL_ARRAY_BUFFER, obj->vbos[3]); // Normals per Vertex glNormalPointer(GL_FLOAT, 0, 0); } glBindBuffer(GL_ARRAY_BUFFER, obj->vbos[0]); // Points glVertexPointer(3, GL_FLOAT, 0, 0); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, obj->vbos[1]); // Indexes glDrawElements(GL_TRIANGLES, 3 * obj->numtris, GL_UNSIGNED_INT, 0); glBindBuffer(GL_ARRAY_BUFFER, 0); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); if (obj->normal_mode == 2) { // Normalen per Vertex glDisableClientState(GL_NORMAL_ARRAY); } glDisableClientState(GL_VERTEX_ARRAY); } } }
void wxGL_PMFCanvas::draw_omnipoints(){ static geo_sphere sphere(3); if(omni.flags & OMNIPOINT_DONT_DRAW) return; glEnable(GL_BLEND); glBlendFunc(GL_ONE,GL_ONE); glDisable(GL_CULL_FACE); GLfloat ambientLight[4]={0.25f,0.25f,0.25f,1.0f}; glLightfv(GL_LIGHT0,GL_AMBIENT,ambientLight); glDepthMask(GL_FALSE); unsigned int i; unsigned int j; if (GLEE_ARB_vertex_buffer_object) { glBindBuffer(GL_ARRAY_BUFFER, omni_point_buffer.buffer); glLockArraysEXT( 0, omni_point_buffer.n_verts); ERROR_CHECK; glEnableClientState(GL_NORMAL_ARRAY); glEnableClientState(GL_VERTEX_ARRAY); glVertexPointer(3,GL_FLOAT, omni_point_buffer.vertex_size, (void*)NULL); glNormalPointer(GL_FLOAT, omni_point_buffer.vertex_size, (void*)((vector3d*)NULL + 1)); } for(i = 0; i<omni.point.size(); i++){ for(j = 0; j<omni.point[i].size(); j++){ color col = omni.unselected; if(i == (unsigned)omni_selected_list){ col = omni.selected_list; if(j == (unsigned)omni_selected_item) col = omni.selected_item; } //invalid radius so it's ok if we set it to anyhting //and the rest of the code assumes a sane rad if(!(omni.flags & OMNIPOINT_RAD)) omni.point[i][j].rad = model.get_avg_dimintion()/61.80f; if (GLEE_ARB_vertex_buffer_object) { glPushMatrix(); vector3d pnt = omni.point[i][j].pos+model.get_model_offset(omni.point[i][j].model); glTranslatef(pnt.x, pnt.y, pnt.z); if(omni.flags & OMNIPOINT_ANY_PATH){ //sphere.draw(omni.point[i][j].pos+model.get_model_offset(omni.point[i][j].model), model.get_avg_dimintion()/30.0f, 2, col*10); float r = model.get_avg_dimintion()/30.0f; glScalef(r,r,r); color col2 = col*10; glColor4ubv( (GLubyte*)col2.col); glDrawArrays(GL_TRIANGLES, 0, omni_point_buffer.n_verts); glScalef(1.0f/r,1.0f/r,1.0f/r); } glColor4ubv( (GLubyte*)col.col); glScalef(omni.point[i][j].rad, omni.point[i][j].rad, omni.point[i][j].rad); //sphere.draw(omni.point[i][j].pos+model.get_model_offset(omni.point[i][j].model), omni.point[i][j].rad, 2, col); glDrawArrays(GL_TRIANGLES, 0, omni_point_buffer.n_verts); glPopMatrix(); } else { sphere.draw(omni.point[i][j].pos+model.get_model_offset(omni.point[i][j].model), omni.point[i][j].rad, 2, col); if(omni.flags & OMNIPOINT_ANY_PATH) sphere.draw(omni.point[i][j].pos+model.get_model_offset(omni.point[i][j].model), model.get_avg_dimintion()/30.0f, 2, col*10); } } } if (GLEE_ARB_vertex_buffer_object) { glColor4ubv( (GLubyte*)color(255,255,255,255).col); glUnlockArraysEXT(); glBindBuffer(GL_ARRAY_BUFFER, 0); glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_NORMAL_ARRAY); ERROR_CHECK; } GLfloat AmbientLight[4]={1.0f,1.0f,1.0f,1.0f}; glLightfv(GL_LIGHT0,GL_AMBIENT,AmbientLight); glLineWidth(2.5f); if(omni.flags & OMNIPOINT_ANY_PATH) for(i = 0; i<omni.point.size(); i++){ glBegin(GL_LINE_STRIP); for(j = 0; j<omni.point[i].size(); j++){ color col = omni.unselected; if(i == (unsigned)omni_selected_list){ col = omni.selected_item; } col = col * 4.0f; glColor4ubv( (GLubyte*)col.col); vector3d v(omni.point[i][j].pos+model.get_model_offset(omni.point[i][j].model)); glVertex3fv((GLfloat *)&(v)); } if (omni.flags & OMNIPOINT_CLOSED_PATH) { color col = omni.unselected; if(i == (unsigned)omni_selected_list){ col = omni.selected_item; } col = col * 4.0f; glColor4ubv( (GLubyte*)col.col); vector3d v(omni.point[i][0].pos+model.get_model_offset(omni.point[i][0].model)); glVertex3fv((GLfloat *)&(v)); } glEnd(); } glDisable(GL_BLEND); glBegin(GL_LINES); if(omni.flags & OMNIPOINT_NORM) for(i = 0; i<omni.point.size(); i++){ for(j = 0; j<omni.point[i].size(); j++){ color col = omni.unselected; if(i == (unsigned)omni_selected_list){ col = omni.selected_list; if(j == (unsigned)omni_selected_item) col = omni.selected_item; } glColor4ubv( (GLubyte*)col.col); vector3d v(omni.point[i][j].pos+model.get_model_offset(omni.point[i][j].model)); glVertex3fv((GLfloat *)&(v)); if(omni.flags & OMNIPOINT_COMMON_NORMAL) { vector3d vec(omni.point[i][0].norm * omni.point[i][0].rad); vec = omni.point[i][j].pos + model.get_model_offset(omni.point[i][j].model) + vec * 2.5f; glVertex3fv((GLfloat *)&(vec)); } else { vector3d vec(omni.point[i][j].norm * omni.point[i][0].rad); vec = omni.point[i][j].pos + model.get_model_offset(omni.point[i][j].model) + vec * 2.5f; glVertex3fv((GLfloat *)&(vec)); } } } glEnd(); glColor4ubv( (GLubyte*)color(255,255,255,255).col); glDepthMask(GL_TRUE); glLineWidth(1.05f); }
void CMaterialViewer::Draw3D(float TimeDelta) { if (IsTexture && ShowChannels) return; static const CVec3 origin = { -150, 100, 100 }; // static const CVec3 origin = { -150, 50, 50 }; CVec3 lightPosV; viewAxis.UnTransformVector(origin, lightPosV); #if 0 // show light source glDisable(GL_LIGHTING); BindDefaultMaterial(true); glBegin(GL_LINES); glColor3f(1, 0, 0); CVec3 tmp; tmp = lightPosV; tmp[0] -= 20; glVertex3fv(tmp.v); tmp[0] += 40; glVertex3fv(tmp.v); tmp = lightPosV; tmp[1] -= 20; glVertex3fv(tmp.v); tmp[1] += 40; glVertex3fv(tmp.v); tmp = lightPosV; tmp[2] -= 20; glVertex3fv(tmp.v); tmp[2] += 40; glVertex3fv(tmp.v); glEnd(); #endif glColor3f(1, 1, 1); if (!IsTexture) { glEnable(GL_LIGHTING); // no lighting for textures float lightPos[4]; lightPos[0] = lightPosV[0]; lightPos[1] = lightPosV[1]; lightPos[2] = lightPosV[2]; lightPos[3] = 0; glLightfv(GL_LIGHT0, GL_POSITION, lightPos); // glMaterialf(GL_FRONT, GL_SHININESS, 20); } // bind material UUnrealMaterial *Mat = static_cast<UUnrealMaterial*>(Object); Mat->SetMaterial(); // check tangent space GLint aNormal = -1; GLint aTangent = -1; // GLint aBinormal = -1; const CShader *Sh = GCurrentShader; if (Sh) { aNormal = Sh->GetAttrib("normal"); aTangent = Sh->GetAttrib("tangent"); // aBinormal = Sh->GetAttrib("binormal"); } // and draw box ... #define A 100 // vertex #define V000 {-A, -A, -A} #define V001 {-A, -A, A} #define V010 {-A, A, -A} #define V011 {-A, A, A} #define V100 { A, -A, -A} #define V101 { A, -A, A} #define V110 { A, A, -A} #define V111 { A, A, A} static const CVec3 box[] = { V001, V000, V010, V011, // near (x=-A) V111, V110, V100, V101, // far (x=+A) V101, V100, V000, V001, // left (y=-A) V011, V010, V110, V111, // right (y=+A) V010, V000, V100, V110, // bottom (z=-A) V001, V011, V111, V101, // top (z=+A) #undef A }; #define REP4(...) {__VA_ARGS__},{__VA_ARGS__},{__VA_ARGS__},{__VA_ARGS__} static const CVec4 normal[] = { REP4(-1, 0, 0, 1 ), REP4( 1, 0, 0, 1 ), REP4( 0,-1, 0, 1 ), REP4( 0, 1, 0, 1 ), REP4( 0, 0,-1, 1 ), REP4( 0, 0, 1, 1 ) }; static const CVec3 tangent[] = { REP4( 0,-1, 0 ), REP4( 0, 1, 0 ), REP4( 1, 0, 0 ), REP4(-1, 0, 0 ), REP4( 1, 0, 0 ), REP4(-1, 0, 0 ) }; // static const CVec3 binormal[] = // { // REP4( 0, 0, 1 ), // REP4( 0, 0, 1 ), // REP4( 0, 0, 1 ), // REP4( 0, 0, 1 ), // REP4( 0,-1, 0 ), // REP4( 0,-1, 0 ) // }; #undef REP4 static const float tex[][2] = { {0, 0}, {0, 1}, {1, 1}, {1, 0}, {0, 0}, {0, 1}, {1, 1}, {1, 0}, {0, 0}, {0, 1}, {1, 1}, {1, 0}, {0, 0}, {0, 1}, {1, 1}, {1, 0}, {0, 0}, {0, 1}, {1, 1}, {1, 0}, {0, 0}, {0, 1}, {1, 1}, {1, 0} }; static const int inds[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11, 12,13,14,15, 16,17,18,19, 20,21,22,23 }; #if 0 // verify tangents, should be suitable for binormal computation in shaders // (note: we're not verifying correspondence with UV coordinates) for (int i = 0; i < 24; i++) { CVec4 n4 = normal[i]; CVec3 n = n4.ToVec3(); CVec3 t = tangent[i]; CVec3 b = binormal[i]; CVec3 b2; cross(n, t, b2); VectorScale(b2, n4[3], b2); float dd = VectorDistance(b2, b); if (dd > 0.001f) appPrintf("dist[%d] = %g\n", i, dd); } #endif glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glEnableClientState(GL_NORMAL_ARRAY); glVertexPointer(3, GL_FLOAT, sizeof(CVec3), box); glNormalPointer(GL_FLOAT, sizeof(CVec4), normal); glTexCoordPointer(2, GL_FLOAT, 0, tex); if (aNormal >= 0) { glEnableVertexAttribArray(aNormal); // send 4 components to decode binormal in shader glVertexAttribPointer(aNormal, 4, GL_FLOAT, GL_FALSE, sizeof(CVec4), normal); } if (aTangent >= 0) { glEnableVertexAttribArray(aTangent); glVertexAttribPointer(aTangent, 3, GL_FLOAT, GL_FALSE, sizeof(CVec3), tangent); } // if (aBinormal >= 0) // { // glEnableVertexAttribArray(aBinormal); // glVertexAttribPointer(aBinormal, 3, GL_FLOAT, GL_FALSE, sizeof(CVec3), binormal); // } glDrawElements(GL_QUADS, ARRAY_COUNT(inds), GL_UNSIGNED_INT, inds); glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_TEXTURE_COORD_ARRAY); glDisableClientState(GL_NORMAL_ARRAY); // disable tangents if (aNormal >= 0) glDisableVertexAttribArray(aNormal); if (aTangent >= 0) glDisableVertexAttribArray(aTangent); // if (aBinormal >= 0) // glDisableVertexAttribArray(aBinormal); BindDefaultMaterial(true); #if 0 glBegin(GL_LINES); glColor3f(0.2, 0.2, 1); for (int i = 0; i < ARRAY_COUNT(box); i++) { glVertex3fv(box[i].v); CVec3 tmp; VectorMA(box[i], 20, normal[i], tmp); glVertex3fv(tmp.v); } glEnd(); glColor3f(1, 1, 1); #endif }
void Skybox::drawImplementation(osg::RenderInfo& renderInfo) const{ int positionCote=mSize/2; Vec3Array* boxVertices = new osg::Vec3Array; boxVertices->push_back(Vec3f(-positionCote,-positionCote,-positionCote)); //back bottom left 0 boxVertices->push_back(Vec3f(positionCote,-positionCote,-positionCote)); //back bottom right 1 boxVertices->push_back(Vec3f(positionCote,positionCote,-positionCote)); //back up right 2 boxVertices->push_back(Vec3f(-positionCote,positionCote,-positionCote)); //back up left 3 boxVertices->push_back(Vec3f(-positionCote,-positionCote,positionCote)); //front bottom left 4 boxVertices->push_back(Vec3f(positionCote,-positionCote,positionCote)); //front bottom right 5 boxVertices->push_back(Vec3f(positionCote,positionCote,positionCote)); //front up right 6 boxVertices->push_back(Vec3f(-positionCote,positionCote,positionCote)); //front up left 7 osg::ref_ptr<osg::Texture2D> texture (new osg::Texture2D(image.get())); osg::ref_ptr<osg::StateSet> texSS (new osg::StateSet); texture->setInternalFormat(GL_RGBA); texture->setFilter(osg::Texture2D::MIN_FILTER, osg::Texture2D::LINEAR); texture->setFilter(osg::Texture2D::MAG_FILTER, osg::Texture2D::LINEAR); texSS->setTextureAttributeAndModes (0, texture.get(), osg::StateAttribute::ON); texSS->setMode(GL_LIGHTING,osg::StateAttribute::OFF); renderInfo.getState()->apply(texSS.get()); boxVertices->at(0)._v; glBegin(GL_QUADS); glTexCoord2f(1.0/4.0, 1.01/3.0);glVertex3fv(boxVertices->at(0)._v); glTexCoord2f(2.0/4.0, 1.01/3.0);glVertex3fv(boxVertices->at(1)._v); glTexCoord2f(2.0/4.0, 1.99/3.0);glVertex3fv(boxVertices->at(2)._v); glTexCoord2f(1.0/4.0, 1.99/3.0);glVertex3fv(boxVertices->at(3)._v); glTexCoord2f(1.0/4.0, 1.01/3.0);glVertex3fv(boxVertices->at(0)._v); glTexCoord2f(0, 1.01/3.0);glVertex3fv(boxVertices->at(4)._v); glTexCoord2f(0, 1.99/3.0);glVertex3fv(boxVertices->at(7)._v); glTexCoord2f(1.0/4.0, 1.99/3.0);glVertex3fv(boxVertices->at(3)._v); glTexCoord2f(1, 1.01/3.0);glVertex3fv(boxVertices->at(4)._v); glTexCoord2f(3.0/4.0, 1.01/3.0);glVertex3fv(boxVertices->at(5)._v); glTexCoord2f(3.0/4.0, 1.99/3.0);glVertex3fv(boxVertices->at(6)._v); glTexCoord2f(1, 1.99/3.0);glVertex3fv(boxVertices->at(7)._v); glTexCoord2f(2.0/4.0, 1.01/3.0);glVertex3fv(boxVertices->at(1)._v); glTexCoord2f(3.0/4.0, 1.01/3.0);glVertex3fv(boxVertices->at(5)._v); glTexCoord2f(3.0/4.0, 1.99/3.0);glVertex3fv(boxVertices->at(6)._v); glTexCoord2f(2.0/4.0, 1.99/3.0);glVertex3fv(boxVertices->at(2)._v); glTexCoord2f(1.01/4.0, 0);glVertex3fv(boxVertices->at(0)._v); glTexCoord2f(1.99/4.0, 0);glVertex3fv(boxVertices->at(1)._v); glTexCoord2f(1.99/4.0, 1.0/3.0);glVertex3fv(boxVertices->at(5)._v); glTexCoord2f(1.01/4.0, 1.0/3.0);glVertex3fv(boxVertices->at(4)._v); glTexCoord2f(1.99/4.0, 2.0/3.0);glVertex3fv(boxVertices->at(2)._v); glTexCoord2f(1.01/4.0, 2.0/3.0);glVertex3fv(boxVertices->at(3)._v); glTexCoord2f(1.01/4.0, 1);glVertex3fv(boxVertices->at(7)._v); glTexCoord2f(1.99/4.0, 1);glVertex3fv(boxVertices->at(6)._v); glEnd(); renderInfo.getState()->apply(); }
/* ================= R_DrawSpriteModel ================= */ void R_DrawSpriteModel (entity_t *e) { //vec3_t point; mspriteframe_t *frame; float *up, *right; vec3_t v_forward, v_right, v_up; msprite_t *psprite; // don't even bother culling, because it's just a single // polygon without a surface cache frame = R_GetSpriteFrame (e); psprite = currententity->model->cache.data; if (psprite->type == SPR_ORIENTED) { // bullet marks on walls AngleVectors (currententity->angles, v_forward, v_right, v_up); up = v_up; right = v_right; } else { // normal sprite up = vup; right = vright; } glColor4ub (255,255,255,255); GL_DisableMultitexture(); GL_Bind(frame->gl_texturenum); glEnable (GL_ALPHA_TEST); #ifdef ESQUAKE float quadTexCoord[] = { 0, 1, 0, 0, 1, 0, 1, 1 }; float quadVertices3[3*4]; vec_t * pVec = quadVertices3; VectorMA (e->origin, frame->down, up, pVec); VectorMA (pVec, frame->left, right, pVec); pVec += 3; VectorMA (e->origin, frame->up, up, pVec); VectorMA (pVec, frame->left, right, pVec); pVec += 3; VectorMA (e->origin, frame->up, up, pVec); VectorMA (pVec, frame->right, right, pVec); pVec += 3; VectorMA (e->origin, frame->down, up, pVec); VectorMA (pVec, frame->right, right, pVec); glTexCoordPointer(2, GL_FLOAT, sizeof(GLfloat)*2, quadTexCoord); glVertexPointer(3, GL_FLOAT, sizeof(GLfloat)*3, quadVertices3); glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glDrawArrays(GL_TRIANGLE_FAN, 0, 4); glDisableClientState(GL_TEXTURE_COORD_ARRAY); glDisableClientState(GL_VERTEX_ARRAY); #else glBegin (GL_QUADS); glTexCoord2f (0, 1); VectorMA (e->origin, frame->down, up, point); VectorMA (point, frame->left, right, point); glVertex3fv (point); glTexCoord2f (0, 0); VectorMA (e->origin, frame->up, up, point); VectorMA (point, frame->left, right, point); glVertex3fv (point); glTexCoord2f (1, 0); VectorMA (e->origin, frame->up, up, point); VectorMA (point, frame->right, right, point); glVertex3fv (point); glTexCoord2f (1, 1); VectorMA (e->origin, frame->down, up, point); VectorMA (point, frame->right, right, point); glVertex3fv (point); glEnd (); #endif glDisable (GL_ALPHA_TEST); }
void Light::light_draw (const AABB& aabb_light, RenderStateFlags state) const { Vector3 points[6]; light_vertices(aabb_light, points); if (state & RENDER_LIGHTING) { const float f = 0.70710678f; // North, East, South, West const Vector3 normals[8] = { Vector3(0, f, f), Vector3(f, 0, f), Vector3(0, -f, f), Vector3(-f, 0, f), Vector3( 0, f, -f), Vector3(f, 0, -f), Vector3(0, -f, -f), Vector3(-f, 0, -f), }; glBegin(GL_TRIANGLES); glVertex3fv(points[0]); glVertex3fv(points[2]); glNormal3fv(normals[0]); glVertex3fv(points[3]); glVertex3fv(points[0]); glVertex3fv(points[3]); glNormal3fv(normals[1]); glVertex3fv(points[4]); glVertex3fv(points[0]); glVertex3fv(points[4]); glNormal3fv(normals[2]); glVertex3fv(points[5]); glVertex3fv(points[0]); glVertex3fv(points[5]); glNormal3fv(normals[3]); glVertex3fv(points[2]); glEnd(); glBegin(GL_TRIANGLE_FAN); glVertex3fv(points[1]); glVertex3fv(points[2]); glNormal3fv(normals[7]); glVertex3fv(points[5]); glVertex3fv(points[1]); glVertex3fv(points[5]); glNormal3fv(normals[6]); glVertex3fv(points[4]); glVertex3fv(points[1]); glVertex3fv(points[4]); glNormal3fv(normals[5]); glVertex3fv(points[3]); glVertex3fv(points[1]); glVertex3fv(points[3]); glNormal3fv(normals[4]); glVertex3fv(points[2]); glEnd(); } else { const unsigned int indices[] = { 0, 2, 3, 0, 3, 4, 0, 4, 5, 0, 5, 2, 1, 2, 5, 1, 5, 4, 1, 4, 3, 1, 3, 2 }; glVertexPointer(3, GL_FLOAT, 0, points); glDrawElements(GL_TRIANGLES, sizeof(indices) / sizeof(indices[0]), RenderIndexTypeID, indices); } }
void GL_DrawAliasShadow (aliashdr_t *paliashdr, int posenum) { //float s, t, l; //int i, j; //int index; //trivertx_t *v; trivertx_t *verts; //int list; int *order; //float *normal; float height, lheight; int count; lheight = currententity->origin[2] - lightspot[2]; height = 0; verts = (trivertx_t *)((byte *)paliashdr + paliashdr->posedata); verts += posenum * paliashdr->poseverts; order = (int *)((byte *)paliashdr + paliashdr->commands); height = -lheight + 1.0; #ifdef ESQUAKE while (1) { GLenum mode; // get the vertex count and primitive type count = *order++; if (!count) break; // done if (count < 0) { count = -count; mode = GL_TRIANGLE_FAN; } else mode = GL_TRIANGLE_STRIP; const GLsizei arraySize = count; float vertArray[count*3]; float * point = vertArray; do { // texture coordinates come from the draw list // (skipped for shadows) glTexCoord2fv ((float *)order); order += 2; // normals and vertexes come from the frame list point[0] = verts->v[0] * paliashdr->scale[0] + paliashdr->scale_origin[0]; point[1] = verts->v[1] * paliashdr->scale[1] + paliashdr->scale_origin[1]; point[2] = verts->v[2] * paliashdr->scale[2] + paliashdr->scale_origin[2]; point[0] -= shadevector[0]*(point[2]+lheight); point[1] -= shadevector[1]*(point[2]+lheight); point[2] = height; // height -= 0.001; point += 3; verts++; } while (--count); glDrawArrays(mode, 0, arraySize); } #else while (1) { vec3_t point; // get the vertex count and primitive type count = *order++; if (!count) break; // done if (count < 0) { count = -count; glBegin (GL_TRIANGLE_FAN); } else glBegin (GL_TRIANGLE_STRIP); do { // texture coordinates come from the draw list // (skipped for shadows) glTexCoord2fv ((float *)order); order += 2; // normals and vertexes come from the frame list point[0] = verts->v[0] * paliashdr->scale[0] + paliashdr->scale_origin[0]; point[1] = verts->v[1] * paliashdr->scale[1] + paliashdr->scale_origin[1]; point[2] = verts->v[2] * paliashdr->scale[2] + paliashdr->scale_origin[2]; point[0] -= shadevector[0]*(point[2]+lheight); point[1] -= shadevector[1]*(point[2]+lheight); point[2] = height; // height -= 0.001; glVertex3fv (point); verts++; } while (--count); glEnd (); } #endif }
// // Override the abstract Create function to make this // a real class. // Create works its way through the text in the scanner one // line at a time. Each line must contain a command and a set // of arguments. Create examines the command and then calls // on helper functions to do the right things with the arguments. // bool CGLAList::Create() { if (mScan == NULL) { // Quit if there is no scanner return false; } // // Work through the file. // Each line should begin with a command and then be // followed by a set of numeric arguments. // Lexeme* cLex; CSymbol* cSym = NULL; bool finished = false; Start(); while ((cLex = mScan->NextLex())->lex != LEof) { if (cLex->lex == LNewLine || cLex->lex==LSpace) continue; if (cLex->lex == LWord) { // Hope we have a command #ifdef DEBUG eprintf("Word %s ", cLex->sVal); wxLogMessage(gMsgBuff); #endif cSym = gSymTab->LookUpWord(cLex->sVal); // // Now read in the arguments. // int nArg = GetArgList(); #ifdef DEBUG eprintf("Found %d arguments",nArg); wxLogMessage(gMsgBuff); for (int ii = 0; ii < nArg; ++ii) { eprintf(" %f", gArguments[ii]); wxLogMessage(gMsgBuff); } wxLogMessage("\r\n"); #endif if (cSym != NULL) { // // Found a valid command, dispatch a function // to handle it. // #ifdef DEBUG eprintf("matches symbol %d\r\n",cSym->mSym); wxLogMessage(gMsgBuff); #endif switch (cSym->mSym) { case kGLColor: if (nArg >= 3) { GLfloat color[4]; color[0] = gArguments[0]; color[1] = gArguments[1]; color[2] = gArguments[2]; if (nArg > 3) { color[3] = gArguments[3]; } else { color[3] = 1.0f; } glMaterialfv(GL_FRONT, GL_AMBIENT, color); glMaterialfv(GL_FRONT, GL_SPECULAR, color); glColor3fv(color); } break; case kGLPoint: if (nArg >= 3) { glBegin(GL_POINTS); glVertex3fv(gArguments); glEnd(); mBounds->AddPoint3fv(&gArguments[0]); } break; case kGLTranslate: if (nArg >= 3) { glTranslatef(gArguments[0],gArguments[1],gArguments[2]); } break; case kGLLine: BuildLine(nArg); break; case kGLPolyLine: BuildPolyLine(nArg); break; case kGLSphere: BuildSphere(nArg); break; case kGLBox: BuildBox(nArg); break; case kGLTriangle: BuildTriangle(nArg); break; case kGLCylinder: BuildCylinder(nArg); break; case kGLCap: BuildCap(nArg); break; case kGLEnd: finished = true; break; default: eprintf("CGLAList.Create: Unimplemented GLA verb %s.\r\n", cSym->mName); break; } } else { eprintf("CGLAList.Create: %s is an unrecognised GLA verb.\r\n", cLex->sVal); } } else { // Did not find a command // // Print a message. // eprintf("CGLAList.Create: Cound not find a command on line %lu.\r\n", mScan->LineNumber()); eprintf("%s", mScan->GetLine()); } if (finished) break; // // Eat tokens til we get to the // end of the line (or a premature EOF) // while ((cLex = mScan->NextLex())->lex != LNewLine && cLex->lex != LEof); } // end while End(); ReleaseScanner(); return true; }
static void do_EvalCoord1f(GLcontext* ctx, GLfloat u) { /** Color Index **/ if (ctx->Eval.Map1Index) { GLfloat findex; struct gl_1d_map *map = &ctx->EvalMap.Map1Index; GLfloat uu = (u - map->u1) * map->du; _math_horner_bezier_curve(map->Points, &findex, uu, 1, map->Order); glIndexi( (GLint) findex ); } /** Color **/ if (ctx->Eval.Map1Color4) { GLfloat fcolor[4]; struct gl_1d_map *map = &ctx->EvalMap.Map1Color4; GLfloat uu = (u - map->u1) * map->du; _math_horner_bezier_curve(map->Points, fcolor, uu, 4, map->Order); glColor4fv( fcolor ); } /** Normal Vector **/ if (ctx->Eval.Map1Normal) { GLfloat normal[3]; struct gl_1d_map *map = &ctx->EvalMap.Map1Normal; GLfloat uu = (u - map->u1) * map->du; _math_horner_bezier_curve(map->Points, normal, uu, 3, map->Order); glNormal3fv( normal ); } /** Texture Coordinates **/ if (ctx->Eval.Map1TextureCoord4) { GLfloat texcoord[4]; struct gl_1d_map *map = &ctx->EvalMap.Map1Texture4; GLfloat uu = (u - map->u1) * map->du; _math_horner_bezier_curve(map->Points, texcoord, uu, 4, map->Order); glTexCoord4fv( texcoord ); } else if (ctx->Eval.Map1TextureCoord3) { GLfloat texcoord[4]; struct gl_1d_map *map = &ctx->EvalMap.Map1Texture3; GLfloat uu = (u - map->u1) * map->du; _math_horner_bezier_curve(map->Points, texcoord, uu, 3, map->Order); glTexCoord3fv( texcoord ); } else if (ctx->Eval.Map1TextureCoord2) { GLfloat texcoord[4]; struct gl_1d_map *map = &ctx->EvalMap.Map1Texture2; GLfloat uu = (u - map->u1) * map->du; _math_horner_bezier_curve(map->Points, texcoord, uu, 2, map->Order); glTexCoord2fv( texcoord ); } else if (ctx->Eval.Map1TextureCoord1) { GLfloat texcoord[4]; struct gl_1d_map *map = &ctx->EvalMap.Map1Texture1; GLfloat uu = (u - map->u1) * map->du; _math_horner_bezier_curve(map->Points, texcoord, uu, 1, map->Order); glTexCoord1fv( texcoord ); } /** Vertex **/ if (ctx->Eval.Map1Vertex4) { GLfloat vertex[4]; struct gl_1d_map *map = &ctx->EvalMap.Map1Vertex4; GLfloat uu = (u - map->u1) * map->du; _math_horner_bezier_curve(map->Points, vertex, uu, 4, map->Order); glVertex4fv( vertex ); } else if (ctx->Eval.Map1Vertex3) { GLfloat vertex[4]; struct gl_1d_map *map = &ctx->EvalMap.Map1Vertex3; GLfloat uu = (u - map->u1) * map->du; _math_horner_bezier_curve(map->Points, vertex, uu, 3, map->Order); glVertex3fv( vertex ); } }
void FontView::Draw(bool clearAndSwap, unsigned startX, unsigned startY, unsigned width, unsigned height) { if (clearAndSwap) { glClearDepth(1.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); } glViewport(startX, startY, width, height); glBindTexture( GL_TEXTURE_2D, _texture); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glEnable(GL_TEXTURE_2D); glColor3f(1.0f, 1.0f, 1.0f); glDisable(GL_LIGHTING); glShadeModel(GL_SMOOTH); glMatrixMode( GL_PROJECTION ); glLoadIdentity(); glFrustum(-(float)width / 2.0f, (float)width / 2.0f, -(float)height / 2.0f, (float)height / 2.0f, 1.0f, 1000.0f); glMatrixMode( GL_MODELVIEW ); glLoadIdentity(); glBlendFunc(GL_ONE, GL_ONE); glEnable(GL_BLEND); glDisable(GL_DEPTH_TEST); glBegin(GL_QUADS); if (_fitView) { glTexCoord2f(0.0f, 0.0f); glVertex3f(-(float)width * 0.5f, (float)height * 0.5f, -1.0f); glTexCoord2f(_clip.Points[0], 0.0f); glVertex3f((float)width * 0.5f, (float)height * 0.5f, -1.0f); glTexCoord2f(_clip.Points[0], _clip.Points[1]); glVertex3f((float)width * 0.5f, -(float)height * 0.5f, -1.0f); glTexCoord2f(0.0f, _clip.Points[1]); glVertex3f(-(float)width * 0.5f, -(float)height * 0.5f, -1.0f); } else { glTexCoord2f(0.0f, 0.0f); glVertex3fv(_quadPoints); glTexCoord2f(_clip.Points[0], 0.0f); glVertex3fv(_quadPoints + 3); glTexCoord2f(_clip.Points[0], _clip.Points[1]); glVertex3fv(_quadPoints + 6); glTexCoord2f(0.0f, _clip.Points[1]); glVertex3fv(_quadPoints + 9); } glEnd(); glDisable(GL_BLEND); if (clearAndSwap) SDL_GL_SwapBuffers(); }
void R_DrawParticles (void) { particle_t *p, *kill; float grav; int i; float time2, time3; float time1; float dvel; float frametime; #ifdef GLQUAKE vec3_t up, right; float scale; GL_Bind(particletexture); 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); #else D_StartParticles (); VectorScale (vright, xscaleshrink, r_pright); VectorScale (vup, yscaleshrink, r_pup); VectorCopy (vpn, r_ppn); #endif frametime = cl.time - cl.oldtime; time3 = frametime * 15; time2 = frametime * 10; // 15; time1 = frametime * 5; grav = frametime * sv_gravity.value * 0.05; dvel = 4*frametime; for ( ;; ) { kill = active_particles; if (kill && kill->die < cl.time) { active_particles = kill->next; kill->next = free_particles; free_particles = kill; continue; } break; } for (p=active_particles ; p ; p=p->next) { for ( ;; ) { kill = p->next; if (kill && kill->die < cl.time) { p->next = kill->next; kill->next = free_particles; free_particles = kill; continue; } break; } #ifdef GLQUAKE // hack a scale up to keep particles from disapearing scale = (p->org[0] - r_origin[0])*vpn[0] + (p->org[1] - r_origin[1])*vpn[1] + (p->org[2] - r_origin[2])*vpn[2]; if (scale < 20) scale = 1; else scale = 1 + scale * 0.004; glColor3ubv ((byte *)&d_8to24table[(int)p->color]); 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); #else D_DrawParticle (p); #endif p->org[0] += p->vel[0]*frametime; p->org[1] += p->vel[1]*frametime; p->org[2] += p->vel[2]*frametime; switch (p->type) { case pt_static: break; case pt_fire: p->ramp += time1; if (p->ramp >= 6) p->die = -1; else p->color = ramp3[(int)p->ramp]; p->vel[2] += grav; break; case pt_explode: p->ramp += time2; if (p->ramp >=8) p->die = -1; else p->color = ramp1[(int)p->ramp]; for (i=0 ; i<3 ; i++) p->vel[i] += p->vel[i]*dvel; p->vel[2] -= grav; break; case pt_explode2: p->ramp += time3; if (p->ramp >=8) p->die = -1; else p->color = ramp2[(int)p->ramp]; for (i=0 ; i<3 ; i++) p->vel[i] -= p->vel[i]*frametime; p->vel[2] -= grav; break; case pt_blob: for (i=0 ; i<3 ; i++) p->vel[i] += p->vel[i]*dvel; p->vel[2] -= grav; break; case pt_blob2: for (i=0 ; i<2 ; i++) p->vel[i] -= p->vel[i]*dvel; p->vel[2] -= grav; break; case pt_grav: #ifdef QUAKE2 p->vel[2] -= grav * 20; break; #endif case pt_slowgrav: p->vel[2] -= grav; break; } } #ifdef GLQUAKE glEnd (); glDisable (GL_BLEND); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); #else D_EndParticles (); #endif }
void RAS_OpenGLRasterizer::FlushDebugShapes(SCA_IScene *scene) { std::vector<OglDebugShape> &debugShapes = m_debugShapes[scene]; if (debugShapes.empty()) return; // DrawDebugLines GLboolean light, tex; light= glIsEnabled(GL_LIGHTING); tex= glIsEnabled(GL_TEXTURE_2D); if (light) glDisable(GL_LIGHTING); if (tex) glDisable(GL_TEXTURE_2D); // draw lines glBegin(GL_LINES); for (unsigned int i = 0; i < debugShapes.size(); i++) { if (debugShapes[i].m_type != OglDebugShape::LINE) continue; glColor4f(debugShapes[i].m_color[0], debugShapes[i].m_color[1], debugShapes[i].m_color[2], 1.0f); const MT_Scalar *fromPtr = &debugShapes[i].m_pos.x(); const MT_Scalar *toPtr= &debugShapes[i].m_param.x(); glVertex3fv(fromPtr); glVertex3fv(toPtr); } glEnd(); // draw circles for (unsigned int i = 0; i < debugShapes.size(); i++) { if (debugShapes[i].m_type != OglDebugShape::CIRCLE) continue; glBegin(GL_LINE_LOOP); glColor4f(debugShapes[i].m_color[0], debugShapes[i].m_color[1], debugShapes[i].m_color[2], 1.0f); static const MT_Vector3 worldUp(0.0f, 0.0f, 1.0f); MT_Vector3 norm = debugShapes[i].m_param; MT_Matrix3x3 tr; if (norm.fuzzyZero() || norm == worldUp) { tr.setIdentity(); } else { MT_Vector3 xaxis, yaxis; xaxis = MT_cross(norm, worldUp); yaxis = MT_cross(xaxis, norm); tr.setValue(xaxis.x(), xaxis.y(), xaxis.z(), yaxis.x(), yaxis.y(), yaxis.z(), norm.x(), norm.y(), norm.z()); } MT_Scalar rad = debugShapes[i].m_param2.x(); int n = (int)debugShapes[i].m_param2.y(); for (int j = 0; j<n; j++) { MT_Scalar theta = j*(float)M_PI*2/n; MT_Vector3 pos(cosf(theta) * rad, sinf(theta) * rad, 0.0f); pos = pos*tr; pos += debugShapes[i].m_pos; const MT_Scalar* posPtr = &pos.x(); glVertex3fv(posPtr); } glEnd(); } if (light) glEnable(GL_LIGHTING); if (tex) glEnable(GL_TEXTURE_2D); debugShapes.clear(); }
// These are convenience functions which allow us to call OpenGL // methods on Vec3f objects inline void glVertex (const Vec3f &a) { glVertex3fv(a.getPtr()); }
void RAS_OpenGLRasterizer::IndexPrimitives_3DText(RAS_MeshSlot& ms, class RAS_IPolyMaterial* polymat) { bool obcolor = ms.m_bObjectColor; MT_Vector4& rgba = ms.m_RGBAcolor; RAS_MeshSlot::iterator it; const STR_String& mytext = ((CValue*)m_clientobject)->GetPropertyText("Text"); // handle object color if (obcolor) { glDisableClientState(GL_COLOR_ARRAY); glColor4d(rgba[0], rgba[1], rgba[2], rgba[3]); } else glEnableClientState(GL_COLOR_ARRAY); for (ms.begin(it); !ms.end(it); ms.next(it)) { RAS_TexVert *vertex; size_t i, j, numvert; numvert = it.array->m_type; if (it.array->m_type == RAS_DisplayArray::LINE) { // line drawing, no text glBegin(GL_LINES); for (i=0; i<it.totindex; i+=2) { vertex = &it.vertex[it.index[i]]; glVertex3fv(vertex->getXYZ()); vertex = &it.vertex[it.index[i+1]]; glVertex3fv(vertex->getXYZ()); } glEnd(); } else { // triangle and quad text drawing for (i=0; i<it.totindex; i+=numvert) { float v[4][3]; const float *v_ptr[4] = {NULL}; const float *uv_ptr[4] = {NULL}; int glattrib, unit; for (j=0; j<numvert; j++) { vertex = &it.vertex[it.index[i+j]]; v[j][0] = vertex->getXYZ()[0]; v[j][1] = vertex->getXYZ()[1]; v[j][2] = vertex->getXYZ()[2]; v_ptr[j] = v[j]; uv_ptr[j] = vertex->getUV(0); } // find the right opengl attribute glattrib = -1; if (GLEW_ARB_vertex_program) for (unit=0; unit<m_attrib_num; unit++) if (m_attrib[unit] == RAS_TEXCO_UV) glattrib = unit; GPU_render_text( polymat->GetMTexPoly(), polymat->GetDrawingMode(), mytext, mytext.Length(), polymat->GetMCol(), v_ptr, uv_ptr, glattrib); ClearCachingInfo(); } } } glDisableClientState(GL_COLOR_ARRAY); }
void setTexture(int i) { switch (globalscene->mList[i].texWay) { case 0: /* 画出物体 */ obj_display(globalscene->mList[i].obejct); break; case 1: // 必须要开启alpha test 把透明的地方挖空! glEnable(GL_ALPHA_TEST); glAlphaFunc(GL_GREATER, 0.5f); glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, globalscene->mList[i].texObject1); //glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); /* 画出物体 */ obj_display(globalscene->mList[i].obejct); /* 关闭贴图 */ glDisable(GL_TEXTURE_2D); glDisable(GL_ALPHA_TEST); glBindTexture(GL_TEXTURE_2D, 0); break; case 2: //bind texture 0 glActiveTexture(GL_TEXTURE0); glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, globalscene->mList[i].texObject1); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE); glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_MODULATE); //bind texture 1 glActiveTexture(GL_TEXTURE1); glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, globalscene->mList[i].texObject2); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE); glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_MODULATE); /* 画出物体 */ // 两幅贴图的物体,贴图方式有所不同,需要另外完成,画图功能,不能直接调用 obj_display() { int lastMaterial = -1; for(size_t k=0;k < globalscene->mList[i].obejct->fTotal;++k) { // set material property if this face used different material if(lastMaterial !=globalscene->mList[i].obejct->faceList[k].m) { lastMaterial = (int)globalscene->mList[i].obejct->faceList[k].m; glMaterialfv(GL_FRONT, GL_AMBIENT , globalscene->mList[i].obejct->mList[lastMaterial].Ka); glMaterialfv(GL_FRONT, GL_DIFFUSE , globalscene->mList[i].obejct->mList[lastMaterial].Kd); glMaterialfv(GL_FRONT, GL_SPECULAR , globalscene->mList[i].obejct->mList[lastMaterial].Ks); glMaterialfv(GL_FRONT, GL_SHININESS, &globalscene->mList[i].obejct->mList[lastMaterial].Ns); //you can obtain the texture name by object->mList[lastMaterial].map_Kd //load them once in the main function before mainloop //bind them in display function here } glBegin(GL_TRIANGLES); for (size_t j=0;j<3;++j) { //textex corrd. glMultiTexCoord2fv(GL_TEXTURE0, globalscene->mList[i].obejct->tList[globalscene->mList[i].obejct->faceList[k][j].t].ptr); glMultiTexCoord2fv(GL_TEXTURE1, globalscene->mList[i].obejct->tList[globalscene->mList[i].obejct->faceList[k][j].t].ptr); glNormal3fv(globalscene->mList[i].obejct->nList[globalscene->mList[i].obejct->faceList[k][j].n].ptr); glVertex3fv(globalscene->mList[i].obejct->vList[globalscene->mList[i].obejct->faceList[k][j].v].ptr); } glEnd(); } } //unbind texture 1 glActiveTexture(GL_TEXTURE1); glDisable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, 0); //unbind texture 0 glActiveTexture(GL_TEXTURE0); glDisable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, 0); break; case 3: //bind texture 0 glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP); glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP); glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP); glEnable(GL_TEXTURE_GEN_S); glEnable(GL_TEXTURE_GEN_T); glEnable(GL_TEXTURE_GEN_R); glEnable(GL_TEXTURE_CUBE_MAP); glBindTexture(GL_TEXTURE_CUBE_MAP, globalscene->mList[i].texObject1); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); /* 画出物体 */ obj_display(globalscene->mList[i].obejct); /* 关闭贴图 */ glDisable(GL_TEXTURE_GEN_S); glDisable(GL_TEXTURE_GEN_T); glDisable(GL_TEXTURE_GEN_R); glDisable(GL_TEXTURE_CUBE_MAP); glBindTexture(GL_TEXTURE_CUBE_MAP, 0); break; } }
void Renderer::drawCovers(bool showTarget){ #ifdef COVER_ALPHA glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_ALPHA_TEST); glAlphaFunc(GL_GREATER,0.1f); #endif if (cfgHighlightWidth == 0) showTarget = false; if (appInstance->albumCollection->getCount() == 0) return; float centerOffset = displayPos->getCenteredOffset(); CollectionPos centerCover = displayPos->getCenteredPos(); CollectionPos firstCover = displayPos->getOffsetPos(coverPos.getFirstCover() + 1); CollectionPos lastCover = displayPos->getOffsetPos(coverPos.getLastCover()); lastCover++; // getOffsetPos does not return the end() element CollectionPos targetCover = appInstance->albumCollection->getTargetPos(); int offset = appInstance->albumCollection->rank(firstCover) - appInstance->albumCollection->rank(centerCover); for (CollectionPos p = firstCover; p != lastCover; ++p, ++offset){ float co = -centerOffset + offset; shared_ptr<ImgTexture> tex = texLoader->getLoadedImgTexture(p); tex->glBind(); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); // calculate darkening float g = 1-(min(1.0f,(abs(co)-2)/5))*0.5f; if (abs(co) < 2) g = 1; /*float g = 1 - (abs(co)-2)*0.2f; g = 1 - abs(co)*0.1f; g = 1 - abs(zRot)/80; g= 1; if (g < 0) g = 0;*/ glColor3f( g, g, g); glVectord origin(0, 0.5, 0); glQuad coverQuad = coverPos.getCoverQuad(co, tex->getAspect()); glPushName(SELECTION_CENTER + offset); glBegin(GL_QUADS); if (glFogCoordf) glFogCoordf((GLfloat)coverPos.distanceToMirror(coverQuad.topLeft)); glTexCoord2f(0.0f, 1.0f); // top left glVertex3fv((GLfloat*)&(coverQuad.topLeft.x)); if (glFogCoordf) glFogCoordf((GLfloat)coverPos.distanceToMirror(coverQuad.topRight)); glTexCoord2f(1.0f, 1.0f); // top right glVertex3fv((GLfloat*)&(coverQuad.topRight.x)); if (glFogCoordf) glFogCoordf((GLfloat)coverPos.distanceToMirror(coverQuad.bottomRight)); glTexCoord2f(1.0f, 0.0f); // bottom right glVertex3fv((GLfloat*)&(coverQuad.bottomRight.x)); if (glFogCoordf) glFogCoordf((GLfloat)coverPos.distanceToMirror(coverQuad.bottomLeft)); glTexCoord2f(0.0f, 0.0f); // bottom left glVertex3fv((GLfloat*)&(coverQuad.bottomLeft.x)); glEnd(); glPopName(); if (showTarget){ if (p == targetCover){ bool clipPlane = false; if (glIsEnabled(GL_CLIP_PLANE0)){ glDisable(GL_CLIP_PLANE0); clipPlane = true; } showTarget = false; glColor3f(GetRValue(cfgTitleColor) / 255.0f, GetGValue(cfgTitleColor) / 255.0f, GetBValue(cfgTitleColor) / 255.0f); glPolygonMode(GL_FRONT_AND_BACK,GL_LINE); glDisable(GL_TEXTURE_2D); glLineWidth((GLfloat)cfgHighlightWidth); glPolygonOffset(-1.0f, -1.0f); glEnable(GL_POLYGON_OFFSET_LINE); glEnable(GL_VERTEX_ARRAY); glVertexPointer(3, GL_FLOAT, 0, (void*) &coverQuad); glDrawArrays(GL_QUADS, 0, 4); glDisable(GL_POLYGON_OFFSET_LINE); glEnable(GL_TEXTURE_2D); if (clipPlane) glEnable(GL_CLIP_PLANE0); } } } #ifdef COVER_ALPHA glDisable(GL_BLEND); glDisable(GL_ALPHA_TEST); #endif }
void renderlevelobjects(void) { int count,count2; int objectnum; float vec[3]; float angle; for (count=0;count<level.numofobjects;count++) { if (level.object[count].type==1) { glDisable(GL_TEXTURE_2D); for (count2=0;count2<16;count2++) { glBegin(GL_TRIANGLES); glColor4f(0.0f,0.0f,0.0f,1.0f); angle=(float)count2*pi/8.0f; vec[0]=level.object[count].position[0]+cos(angle)*0.9f; vec[1]=level.object[count].position[1]-sin(angle)*0.9f; vec[2]=0.0f; glVertex3fv(vec); angle=(float)(count2+1)*pi/8.0f; vec[0]=level.object[count].position[0]+cos(angle)*0.9f; vec[1]=level.object[count].position[1]-sin(angle)*0.9f; vec[2]=0.0f; glVertex3fv(vec); glVertex3fv(level.object[count].position); glEnd(); } glEnable(GL_TEXTURE_2D); } if (level.object[count].type>=2 && level.object[count].type<=5) { glBindTexture(GL_TEXTURE_2D,texture[level.object[count].texturenum+256].glname); glBegin(GL_QUADS); glColor4f(1.0f,1.0f,1.0f,1.0f); glTexCoord2f(0.0f,0.0f); glVertex3f(level.object[count].position[0]-level.object[count].size[0]*0.5f,level.object[count].position[1]+level.object[count].size[1]*0.5f,0.0f); glTexCoord2f(1.0f,0.0f); glVertex3f(level.object[count].position[0]+level.object[count].size[0]*0.5f,level.object[count].position[1]+level.object[count].size[1]*0.5f,0.0f); glTexCoord2f(1.0f,1.0f); glVertex3f(level.object[count].position[0]+level.object[count].size[0]*0.5f,level.object[count].position[1]-level.object[count].size[1]*0.5f,0.0f); glTexCoord2f(0.0f,1.0f); glVertex3f(level.object[count].position[0]-level.object[count].size[0]*0.5f,level.object[count].position[1]-level.object[count].size[1]*0.5f,0.0f); glEnd(); } if (level.object[count].type==6 || level.object[count].type==7 || level.object[count].type==17) { glBindTexture(GL_TEXTURE_2D,texture[level.object[count].texturenum+256].glname); for (count2=0;count2<16;count2++) { glBegin(GL_TRIANGLES); glColor4f(1.0f,1.0f,1.0f,1.0f); angle=(float)count2*pi/8.0f; vec[0]=level.object[count].position[0]+cos(angle)*level.object[count].size[0]*0.5f; vec[1]=level.object[count].position[1]-sin(angle)*level.object[count].size[1]*0.5f; vec[2]=0.0f; glTexCoord2f(0.5f+cos(angle)*0.5f,0.5f+sin(angle)*0.5f); glVertex3fv(vec); angle=(float)(count2+1)*pi/8.0f; vec[0]=level.object[count].position[0]+cos(angle)*level.object[count].size[0]*0.5f; vec[1]=level.object[count].position[1]-sin(angle)*level.object[count].size[1]*0.5f; vec[2]=0.0f; glTexCoord2f(0.5f+cos(angle)*0.5f,0.5f+sin(angle)*0.5f); glVertex3fv(vec); glTexCoord2f(0.5f,0.5f); glVertex3fv(level.object[count].position); glEnd(); } } if (level.object[count].type==8) { glBindTexture(GL_TEXTURE_2D,texture[level.object[count].texturenum+256].glname); glBegin(GL_QUADS); glColor4f(1.0f,1.0f,1.0f,1.0f); glTexCoord2f(0.0f,0.0f); glVertex3f(level.object[count].position[0]-0.25f,level.object[count].position[1]+0.25f,0.0f); glTexCoord2f(1.0f,0.0f); glVertex3f(level.object[count].position[0]+0.25f,level.object[count].position[1]+0.25f,0.0f); glTexCoord2f(1.0f,1.0f); glVertex3f(level.object[count].position[0]+0.25f,level.object[count].position[1]-0.25f,0.0f); glTexCoord2f(0.0f,1.0f); glVertex3f(level.object[count].position[0]-0.25f,level.object[count].position[1]-0.25f,0.0f); glEnd(); } if (level.object[count].type==9 || level.object[count].type==10) { glBindTexture(GL_TEXTURE_2D,texture[level.object[count].texturenum+256].glname); glBegin(GL_QUADS); glColor4f(1.0f,1.0f,1.0f,1.0f); glTexCoord2f(0.0f,0.0f); glVertex3f(level.object[count].position[0]-0.5f,level.object[count].position[1]+0.5f,0.0f); glTexCoord2f(1.0f,0.0f); glVertex3f(level.object[count].position[0]+0.5f,level.object[count].position[1]+0.5f,0.0f); glTexCoord2f(1.0f,1.0f); glVertex3f(level.object[count].position[0]+0.5f,level.object[count].position[1],0.0f); glTexCoord2f(0.0f,1.0f); glVertex3f(level.object[count].position[0]-0.5f,level.object[count].position[1],0.0f); glEnd(); } if (level.object[count].type>=20 && level.object[count].type<40) { glBindTexture(GL_TEXTURE_2D,texture[animation[level.object[count].type-20].stand[0]].glname); glBegin(GL_QUADS); glColor4f(1.0f,1.0f,1.0f,1.0f); glTexCoord2f(0.0f,0.0f); glVertex3f(level.object[count].position[0]-level.object[count].size[0]*0.5f,level.object[count].position[1]+level.object[count].size[1]*0.5f,0.0f); glTexCoord2f(1.0f,0.0f); glVertex3f(level.object[count].position[0]+level.object[count].size[0]*0.5f,level.object[count].position[1]+level.object[count].size[1]*0.5f,0.0f); glTexCoord2f(1.0f,1.0f); glVertex3f(level.object[count].position[0]+level.object[count].size[0]*0.5f,level.object[count].position[1]-level.object[count].size[1]*0.5f,0.0f); glTexCoord2f(0.0f,1.0f); glVertex3f(level.object[count].position[0]-level.object[count].size[0]*0.5f,level.object[count].position[1]-level.object[count].size[1]*0.5f,0.0f); glEnd(); } if (level.object[count].type==11) { glBindTexture(GL_TEXTURE_2D,texture[level.object[count].texturenum+256].glname); glBegin(GL_QUADS); glColor4f(1.0f,1.0f,1.0f,1.0f); glTexCoord2f(0.0f,0.0f); glVertex3f(level.object[count].position[0]-0.125f,level.object[count].position[1]+0.5f,0.0f); glTexCoord2f(1.0f,0.0f); glVertex3f(level.object[count].position[0]+0.125f,level.object[count].position[1]+0.5f,0.0f); glTexCoord2f(1.0f,1.0f); glVertex3f(level.object[count].position[0]+0.25f,level.object[count].position[1]-0.5f,0.0f); glTexCoord2f(0.0f,1.0f); glVertex3f(level.object[count].position[0]-0.25f,level.object[count].position[1]-0.5f,0.0f); glEnd(); } if (level.object[count].type==12) { glBindTexture(GL_TEXTURE_2D,texture[level.object[count].texturenum+256].glname); glBegin(GL_QUADS); glColor4f(1.0f,1.0f,1.0f,1.0f); glTexCoord2f(0.0f,0.0f); glVertex3f(level.object[count].position[0]-0.5f,level.object[count].position[1]+0.25f,0.0f); glTexCoord2f(1.0f,0.0f); glVertex3f(level.object[count].position[0]+0.5f,level.object[count].position[1]+0.125f,0.0f); glTexCoord2f(1.0f,1.0f); glVertex3f(level.object[count].position[0]+0.5f,level.object[count].position[1]-0.125f,0.0f); glTexCoord2f(0.0f,1.0f); glVertex3f(level.object[count].position[0]-0.5f,level.object[count].position[1]-0.25f,0.0f); glEnd(); } if (level.object[count].type==13) { glBindTexture(GL_TEXTURE_2D,texture[level.object[count].texturenum+256].glname); glBegin(GL_QUADS); glColor4f(1.0f,1.0f,1.0f,1.0f); glTexCoord2f(0.0f,0.0f); glVertex3f(level.object[count].position[0]-0.25f,level.object[count].position[1]+0.5f,0.0f); glTexCoord2f(1.0f,0.0f); glVertex3f(level.object[count].position[0]+0.25f,level.object[count].position[1]+0.5f,0.0f); glTexCoord2f(1.0f,1.0f); glVertex3f(level.object[count].position[0]+0.125f,level.object[count].position[1]-0.5f,0.0f); glTexCoord2f(0.0f,1.0f); glVertex3f(level.object[count].position[0]-0.125f,level.object[count].position[1]-0.5f,0.0f); glEnd(); } if (level.object[count].type==14) { glBindTexture(GL_TEXTURE_2D,texture[level.object[count].texturenum+256].glname); glBegin(GL_QUADS); glColor4f(1.0f,1.0f,1.0f,1.0f); glTexCoord2f(0.0f,0.0f); glVertex3f(level.object[count].position[0]-0.5f,level.object[count].position[1]+0.125f,0.0f); glTexCoord2f(1.0f,0.0f); glVertex3f(level.object[count].position[0]+0.5f,level.object[count].position[1]+0.25f,0.0f); glTexCoord2f(1.0f,1.0f); glVertex3f(level.object[count].position[0]+0.5f,level.object[count].position[1]-0.25f,0.0f); glTexCoord2f(0.0f,1.0f); glVertex3f(level.object[count].position[0]-0.5f,level.object[count].position[1]-0.125f,0.0f); glEnd(); } if (level.object[count].type==15 || level.object[count].type==16 || level.object[count].type==18) { glDisable(GL_TEXTURE_2D); glBegin(GL_LINES); glColor4f(1.0f,1.0f,1.0f,1.0f); glVertex3f(level.object[count].position[0]-level.object[count].size[0]*0.5f,level.object[count].position[1]+level.object[count].size[1]*0.5f,0.0f); glVertex3f(level.object[count].position[0]+level.object[count].size[0]*0.5f,level.object[count].position[1]+level.object[count].size[1]*0.5f,0.0f); glVertex3f(level.object[count].position[0]+level.object[count].size[0]*0.5f,level.object[count].position[1]+level.object[count].size[1]*0.5f,0.0f); glVertex3f(level.object[count].position[0]+level.object[count].size[0]*0.5f,level.object[count].position[1]-level.object[count].size[1]*0.5f,0.0f); glVertex3f(level.object[count].position[0]+level.object[count].size[0]*0.5f,level.object[count].position[1]-level.object[count].size[1]*0.5f,0.0f); glVertex3f(level.object[count].position[0]-level.object[count].size[0]*0.5f,level.object[count].position[1]-level.object[count].size[1]*0.5f,0.0f); glVertex3f(level.object[count].position[0]-level.object[count].size[0]*0.5f,level.object[count].position[1]-level.object[count].size[1]*0.5f,0.0f); glVertex3f(level.object[count].position[0]-level.object[count].size[0]*0.5f,level.object[count].position[1]+level.object[count].size[1]*0.5f,0.0f); glEnd(); glEnable(GL_TEXTURE_2D); } glDisable(GL_TEXTURE_2D); glBegin(GL_LINES); glColor4f(0.5f,0.5f,0.5f,1.0f); if (count==editor.objectnum) glColor4f(0.0f,1.0f,0.0f,1.0f); else if (editor.objectnum!=-1) { if (count==level.object[editor.objectnum].link) glColor4f(1.0f,0.0f,0.0f,1.0f); } vec[0]=level.object[count].position[0]-0.5f; vec[1]=level.object[count].position[1]+0.5f; vec[2]=0.0f; glVertex3fv(vec); vec[0]=level.object[count].position[0]+0.5f; vec[1]=level.object[count].position[1]-0.5f; vec[2]=0.0f; glVertex3fv(vec); vec[0]=level.object[count].position[0]+0.5f; vec[1]=level.object[count].position[1]+0.5f; vec[2]=0.0f; glVertex3fv(vec); vec[0]=level.object[count].position[0]-0.5f; vec[1]=level.object[count].position[1]-0.5f; vec[2]=0.0f; glVertex3fv(vec); glEnd(); glEnable(GL_TEXTURE_2D); } glDisable(GL_TEXTURE_2D); glBegin(GL_LINES); for (count=0;count<level.numofropes;count++) if (level.rope[count].obj1!=-1 && level.rope[count].obj2!=-1) { if (level.rope[count].type==1) glColor4f(0.75f,0.75f,0.0f,1.0f); if (level.rope[count].type==2) glColor4f(1.0f,1.0f,0.0f,1.0f); if (level.rope[count].type==3) glColor4f(0.5f,0.5f,0.5f,1.0f); if (level.rope[count].type==4) glColor4f(0.75f,0.75f,0.75f,1.0f); if (level.rope[count].type>=5 && level.rope[count].type<10) glColor4f(0.75f,0.0f,0.75f,1.0f); if (level.rope[count].type==10) glColor4f(0.0f,0.75f,0.75f,1.0f); objectnum=level.rope[count].obj1; copyvector(vec,level.object[objectnum].position); if (level.object[objectnum].type>=2 && level.object[objectnum].type<=5) { if (level.rope[count].obj1part==0) { vec[0]-=level.object[objectnum].size[0]*0.5f; vec[1]+=level.object[objectnum].size[1]*0.5f; } if (level.rope[count].obj1part==1) { vec[0]+=level.object[objectnum].size[0]*0.5f; vec[1]+=level.object[objectnum].size[1]*0.5f; } if (level.rope[count].obj1part==2) { vec[0]+=level.object[objectnum].size[0]*0.5f; vec[1]-=level.object[objectnum].size[1]*0.5f; } if (level.rope[count].obj1part==3) { vec[0]-=level.object[objectnum].size[0]*0.5f; vec[1]-=level.object[objectnum].size[1]*0.5f; } } if (level.object[objectnum].type>=6 && level.object[objectnum].type<=7) { if (level.rope[count].obj1part==0) vec[0]+=level.object[objectnum].size[0]*0.5f; if (level.rope[count].obj1part==4) vec[1]-=level.object[objectnum].size[1]*0.5f; if (level.rope[count].obj1part==8) vec[0]-=level.object[objectnum].size[0]*0.5f; if (level.rope[count].obj1part==12) vec[1]+=level.object[objectnum].size[1]*0.5f; } glVertex3fv(vec); objectnum=level.rope[count].obj2; copyvector(vec,level.object[objectnum].position); if (level.object[objectnum].type>=2 && level.object[objectnum].type<=5) { if (level.rope[count].obj2part==0) { vec[0]-=level.object[objectnum].size[0]*0.5f; vec[1]+=level.object[objectnum].size[1]*0.5f; } if (level.rope[count].obj2part==1) { vec[0]+=level.object[objectnum].size[0]*0.5f; vec[1]+=level.object[objectnum].size[1]*0.5f; } if (level.rope[count].obj2part==2) { vec[0]+=level.object[objectnum].size[0]*0.5f; vec[1]-=level.object[objectnum].size[1]*0.5f; } if (level.rope[count].obj2part==3) { vec[0]-=level.object[objectnum].size[0]*0.5f; vec[1]-=level.object[objectnum].size[1]*0.5f; } } if (level.object[objectnum].type>=6 && level.object[objectnum].type<=7) { if (level.rope[count].obj2part==0) vec[0]+=level.object[objectnum].size[0]*0.5f; if (level.rope[count].obj2part==4) vec[1]-=level.object[objectnum].size[1]*0.5f; if (level.rope[count].obj2part==8) vec[0]-=level.object[objectnum].size[0]*0.5f; if (level.rope[count].obj2part==12) vec[1]+=level.object[objectnum].size[1]*0.5f; } glVertex3fv(vec); } glEnd(); glEnable(GL_TEXTURE_2D); }
static int test05(int size, int num) { int y; float v0[3], v1[3], v2[3], v3[3]; float cv0[3], cv1[3], cv2[3], cv3[3]; float tv0[3], tv1[3], tv2[3], tv3[3]; v0[0] = 320 - size / 2; v0[1] = 240 - size / 2; v0[2] = 0.0; v1[0] = 320 + size / 2; v1[1] = 240 - size / 2; v1[2] = 0.0; v2[0] = 320 - size / 2; v2[1] = 240 + size / 2; v2[2] = 0.0; v3[0] = 320 + size / 2; v3[1] = 240 + size / 2; v3[2] = 0.0; cv0[0] = 1.0; cv0[1] = 0.0; cv0[2] = 0.0; cv1[0] = 1.0; cv1[1] = 1.0; cv1[2] = 0.0; cv2[0] = 1.0; cv2[1] = 0.0; cv2[2] = 1.0; cv3[0] = 1.0; cv3[1] = 1.0; cv3[2] = 1.0; tv0[0] = 0.0; tv0[1] = 0.0; tv0[2] = 0.0; tv1[0] = 1.0; tv1[1] = 0.0; tv1[2] = 0.0; tv2[0] = 0.0; tv2[1] = 1.0; tv2[2] = 0.0; tv3[0] = 1.0; tv3[1] = 1.0; tv3[2] = 0.0; glBegin(GL_TRIANGLE_STRIP); for (y = 0; y < num; y++) { glColor3fv(cv0); glTexCoord2fv(tv0); glVertex3fv(v0); glColor3fv(cv1); glTexCoord2fv(tv1); glVertex3fv(v1); glColor3fv(cv2); glTexCoord2fv(tv2); glVertex3fv(v2); glColor3fv(cv3); glTexCoord2fv(tv3); glVertex3fv(v3); } glEnd(); return 4 * num - 2; }
////////////////////////////////////////////////////////// // renderShape // ///////////////////////////////////////////////////////// void surface3d :: renderShape(GemState *state){ if(m_drawType==GL_DEFAULT_GEM)m_drawType=FILL; int n, m; float norm[3]; glNormal3f(0.0f, 0.0f, 1.0f); glLineWidth(m_linewidth); GLfloat xsize = 1.0f; GLfloat ysize = 1.0f; GLfloat ysize0= 0.0f; if (GemShape::m_texType && GemShape::m_texNum>=3) { xsize = GemShape::m_texCoords[1].s; ysize0 = GemShape::m_texCoords[2].t; ysize = GemShape::m_texCoords[1].t; } GLfloat ysizediff = ysize0 - ysize; GLfloat affich_X=static_cast<GLfloat>(nb_pts_affich_X); GLfloat affich_Y=static_cast<GLfloat>(nb_pts_affich_Y); GLfloat control_X=static_cast<GLfloat>(nb_pts_control_X); GLfloat control_Y=static_cast<GLfloat>(nb_pts_control_Y); switch (m_drawType){ case LINE: { if (GemShape::m_texType) { for (n = 0; n < nb_pts_affich_X+1; n++) { glBegin(GL_LINE_STRIP); for (m = 0; m < nb_pts_affich_Y+1; m++){ glTexCoord2f(xsize*n/affich_X, ysize+ysizediff*m/affich_Y); interpolate(n/affich_X, m/affich_Y); } glEnd(); } for(m = 0; m < nb_pts_affich_Y+1; m++) { glBegin(GL_LINE_STRIP); for(n = 0; n < nb_pts_affich_X+1; n++){ glTexCoord2f(xsize*n/affich_X, ysize+ysizediff*m/affich_Y); interpolate(n/affich_X, m/affich_Y); } glEnd(); } } else { for(n = 0; n < nb_pts_affich_X+1; n++) { glBegin(GL_LINE_STRIP); for(m = 0; m < nb_pts_affich_Y+1; m++){ interpolate(n/affich_X, m/affich_Y); } glEnd(); } for(m = 0; m < nb_pts_affich_Y+1; m++) { glBegin(GL_LINE_STRIP); for(n = 0; n < nb_pts_affich_X+1; n++){ interpolate(n/affich_X, m/affich_Y); } glEnd(); } } } break; case FILL: { if (GemShape::m_texType) for(n = 0; n < nb_pts_affich_X; n++) { glBegin(GL_TRIANGLE_STRIP); for(m = 0; m < nb_pts_affich_Y+1; m++) { glTexCoord2f(xsize*n/affich_X, ysize+ysizediff*m/affich_Y); interpolate(n/affich_X, m/affich_Y); glTexCoord2f(xsize*(n+1)/affich_X, ysize+ysizediff*m/affich_Y); interpolate((n+1)/affich_X, m/affich_Y); } glEnd(); } else for(n = 0; n < nb_pts_affich_X; n++) { glBegin(GL_TRIANGLE_STRIP); for(m = 0; m < nb_pts_affich_Y+1; m++) { interpolate(n/affich_X, m/affich_Y); interpolate((n+1)/affich_X, m/affich_Y); } glEnd(); } } break; case POINT: { glBegin(GL_POINTS); if (GemShape::m_texType) for(n = 0; n < nb_pts_affich_X+1; n++) { for(m = 0; m < nb_pts_affich_Y+1; m++) { glTexCoord2f(xsize*n/affich_X, ysize+ysizediff*m/affich_Y); interpolate(n/affich_X, m/affich_Y); } } else for(n = 0; n < nb_pts_affich_X+1; n++) { for(m = 0; m < nb_pts_affich_Y+1; m++) interpolate(n/affich_X, m/affich_Y); } glEnd(); } break; case LINE1: { if (GemShape::m_texType) for(n = 0; n < nb_pts_affich_X; n++) { glBegin(GL_LINE_STRIP); for(m = 0; m < nb_pts_affich_Y; m++) { glTexCoord2f(xsize*n/affich_X, ysize+ysizediff*m/affich_Y); interpolate(n/affich_X, m/affich_Y); } glEnd(); } else for(n = 0; n < nb_pts_affich_X; n++) { glBegin(GL_LINE_STRIP); for(m = 0; m < nb_pts_affich_Y; m++) { interpolate(n/affich_X, m/affich_Y); } glEnd(); } } break; case LINE2: { if (GemShape::m_texType) for(m = 0; m < nb_pts_affich_Y+1; m++) { glBegin(GL_LINE_STRIP); for(n = 0; n < nb_pts_affich_X+1; n++) { interpolate(n/affich_X, m/affich_Y); } glEnd(); } else for(m = 0; m < nb_pts_affich_Y+1; m++) { glBegin(GL_LINE_STRIP); for(n = 0; n < nb_pts_affich_X+1; n++) { glTexCoord2f(xsize*n/affich_X, ysize+ysizediff*m/affich_Y); interpolate(n/affich_X, m/affich_Y); } glEnd(); } } break; case LINE3: { if (GemShape::m_texType) for(n = 0; n < nb_pts_affich_X; n++) { glBegin(GL_LINES); for(m = 0; m < nb_pts_affich_Y; m++) { glTexCoord2f(xsize*n/affich_X, ysize+ysizediff*m/affich_Y); interpolate(n/affich_X, m/affich_Y); } glEnd(); } else for(n = 0; n < nb_pts_affich_X; n++) { glBegin(GL_LINES); for(m = 0; m < nb_pts_affich_Y; m++) { interpolate(n/affich_X, m/affich_Y); } glEnd(); } } break; case LINE4: { if (GemShape::m_texType) for(m = 0; m < nb_pts_affich_Y; m++) { glBegin(GL_LINES); for(n = 0; n < nb_pts_affich_X; n++) { glTexCoord2f(xsize*n/affich_X, ysize+ysizediff*m/affich_Y); interpolate(n/affich_X, m/affich_Y); } glEnd(); } else for(m = 0; m < nb_pts_affich_Y; m++) { glBegin(GL_LINES); for(n = 0; n < nb_pts_affich_X; n++) { interpolate(n/affich_X, m/affich_Y); } glEnd(); } } break; case CONTROL_FILL: { if (GemShape::m_texType) for(n = 0; n < nb_pts_control_X-1; n++) for(m = 0; m < nb_pts_control_Y-1; m++) { Matrix::generateNormal((GLfloat*)&m_posXYZ[n+m*nb_pts_control_X], (GLfloat*)&m_posXYZ[n+m*nb_pts_control_X+1], (GLfloat*)&m_posXYZ[n+(m+1)*nb_pts_control_X], norm); glNormal3fv(norm); glBegin(GL_TRIANGLE_STRIP); glTexCoord2f(xsize*n/(control_X-1.), ysize+ysizediff*m/(control_Y-1.)); glVertex3fv((GLfloat*)&m_posXYZ[n+m*nb_pts_control_X]); glTexCoord2f(xsize*(n+1.)/(control_X-1.), ysize+ysizediff*m/(control_Y-1.)); glVertex3fv((GLfloat*)&m_posXYZ[n+m*nb_pts_control_X+1]); glTexCoord2f(xsize*n/(control_X-1.), ysize+ysizediff*(m+1.)/(control_Y-1.)); glVertex3fv((GLfloat*)&m_posXYZ[n+(m+1)*nb_pts_control_X]); glEnd(); Matrix::generateNormal((GLfloat*)&m_posXYZ[n+1+(m+1)*nb_pts_control_X], (GLfloat*)&m_posXYZ[n+1+m*nb_pts_control_X], (GLfloat*)&m_posXYZ[n+(m+1)*nb_pts_control_X], norm); glNormal3fv(norm); glBegin(GL_TRIANGLE_STRIP); glTexCoord2f(xsize*(n+1.)/(control_X-1.), ysize+ysizediff*(m+1)/(control_Y-1.)); glVertex3fv((GLfloat*)&m_posXYZ[n+1+(m+1)*nb_pts_control_X]); glTexCoord2f(xsize*(n+1.)/(control_X-1.), ysize+ysizediff*m/(control_Y-1.)); glVertex3fv((GLfloat*)&m_posXYZ[n+1+m*nb_pts_control_X]); glTexCoord2f(xsize*n/(control_X-1.), ysize+ysizediff*(m+1.)/(control_Y-1.)); glVertex3fv((GLfloat*)&m_posXYZ[n+(m+1)*nb_pts_control_X]); glEnd(); } else for(n = 0; n < nb_pts_control_X-1; n++) for(m = 0; m < nb_pts_control_Y-1; m++) { Matrix::generateNormal((GLfloat*)&m_posXYZ[n+m*nb_pts_control_X], (GLfloat*)&m_posXYZ[n+m*nb_pts_control_X+1], (GLfloat*)&m_posXYZ[n+(m+1)*nb_pts_control_X], norm); glNormal3fv(norm); glBegin(GL_TRIANGLE_STRIP); glVertex3fv((GLfloat*)&m_posXYZ[n+m*nb_pts_control_X]); glVertex3fv((GLfloat*)&m_posXYZ[n+m*nb_pts_control_X+1]); glVertex3fv((GLfloat*)&m_posXYZ[n+(m+1)*nb_pts_control_X]); glEnd(); Matrix::generateNormal((GLfloat*)&m_posXYZ[n+1+(m+1)*nb_pts_control_X], (GLfloat*)&m_posXYZ[n+(1+m)*nb_pts_control_X], (GLfloat*)&m_posXYZ[n+1+m*nb_pts_control_X], norm); glNormal3fv(norm); glBegin(GL_TRIANGLE_STRIP); glVertex3fv((GLfloat*)&m_posXYZ[n+1+(m+1)*nb_pts_control_X]); glVertex3fv((GLfloat*)&m_posXYZ[n+(m+1)*nb_pts_control_X]); glVertex3fv((GLfloat*)&m_posXYZ[n+1+m*nb_pts_control_X]); glEnd(); } } break; case CONTROL_POINT: { if (GemShape::m_texType) for(n = 0; n < nb_pts_control_X; n++) for(m = 0; m < nb_pts_control_Y; m++) { glBegin(GL_POINTS); glTexCoord2f(xsize*n/(control_X-1.), ysize+ysizediff*m/(control_Y-1.)); glVertex3fv((GLfloat*)&m_posXYZ[n+m*nb_pts_control_X]); glEnd(); } else for(n = 0; n < nb_pts_control_X; n++) for(m = 0; m < nb_pts_control_Y; m++) { glBegin(GL_POINTS); glVertex3fv((GLfloat*)&m_posXYZ[n+m*nb_pts_control_X]); glEnd(); } } break; case CONTROL_LINE: { if (GemShape::m_texType){ for(n = 0; n < nb_pts_control_X; n++) { glBegin(GL_LINE_STRIP); for(m = 0; m < nb_pts_control_Y; m++){ glTexCoord2f(xsize*n/(control_X-1.), ysize+ysizediff*m/(control_Y-1.)); glVertex3fv((GLfloat*)&m_posXYZ[n+m*nb_pts_control_X]); } glEnd(); } for(m = 0; m < nb_pts_control_Y; m++) { glBegin(GL_LINE_STRIP); for(n = 0; n < nb_pts_control_X; n++){ glTexCoord2f(xsize*n/(control_X-1.), ysize+ysizediff*m/(control_Y-1.)); glVertex3fv((GLfloat*)&m_posXYZ[n+m*nb_pts_control_X]); } glEnd(); } } else { for(n = 0; n < nb_pts_control_X; n++) { glBegin(GL_LINE_STRIP); for(m = 0; m < nb_pts_control_Y; m++) glVertex3fv((GLfloat*)&m_posXYZ[n+m*nb_pts_control_X]); glEnd(); } for(m = 0; m < nb_pts_control_Y; m++) { glBegin(GL_LINE_STRIP); for(n = 0; n < nb_pts_control_X; n++) glVertex3fv((GLfloat*)&m_posXYZ[n+m*nb_pts_control_X]); glEnd(); } } } break; case CONTROL_LINE2: { if (GemShape::m_texType) for(m = 0; m < nb_pts_control_Y; m++) { glBegin(GL_LINE_STRIP); for(n = 0; n < nb_pts_control_X; n++) { glTexCoord2f(xsize*n/(control_X-1.), ysize+ysizediff*m/(control_Y-1.)); glVertex3fv((GLfloat*)&m_posXYZ[n+m*nb_pts_control_X]); } glEnd(); } else for(m = 0; m < nb_pts_control_Y; m++) { glBegin(GL_LINE_STRIP); for(n = 0; n < nb_pts_control_X; n++) glVertex3fv((GLfloat*)&m_posXYZ[n+m*nb_pts_control_X]); glEnd(); } } break; case CONTROL_LINE1: { if (GemShape::m_texType) for(n = 0; n < nb_pts_control_X; n++) { glBegin(GL_LINE_STRIP); for(m = 0; m < nb_pts_control_Y; m++) { glTexCoord2f(xsize*n/(control_X-1.), ysize+ysizediff*m/(control_Y-1.)); glVertex3fv((GLfloat*)&m_posXYZ[n+m*nb_pts_control_X]); } glEnd(); } else for(n = 0; n < nb_pts_control_X; n++) { glBegin(GL_LINE_STRIP); for(m = 0; m < nb_pts_control_Y; m++) glVertex3fv((GLfloat*)&m_posXYZ[n+m*nb_pts_control_X]); glEnd(); } } return; } }
void Ctr2SufManager::renderContour() { if( inresize ) return; /////////////////////////////////////////////////////////////////////////// /*cout<<"rendrecontour now!"<<endl; cout<<"planenum:"<<planenum<<endl; for( int i = 0; i < planenum; i ++ ) cout<<showctredgenum[ i ]<<" "; cout<<endl;*/ ////////////////////////////////////////////////////////////////////////// // int ctrnum = ctrvers.size(); ////////////////////////////////////////////////////////////////////////// // cout<<"ctrnum:"<<ctrnum<<endl; ////////////////////////////////////////////////////////////////////////// if( planenum == 0) return; //show the edges glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(20, (float)width/(float)height,nearplane, farplane * 3 ); glMatrixMode(GL_MODELVIEW); glPolygonMode ( GL_FRONT_AND_BACK, GL_LINE ); glLineWidth( 5 ) ; glColor3f(1,1,0); glDisable(GL_LIGHTING); glBegin(GL_LINES); ////////////////////////////////////////////////////////////////////////// //cout<<"planenum:"<<planenum<<endl; ////////////////////////////////////////////////////////////////////////// for( int i = 0; i < planenum; i ++) { ////////////////////////////////////////////////////////////////////////// //cout<<"edgenum:"<<showctredgenum[ i ]<<endl; ////////////////////////////////////////////////////////////////////////// for( int j = 0;j < showctredgenum[ i ]; j++) { int v1 = showctredges[ i ][ 2*j ]; int v2 = showctredges[ i ][ 2*j + 1 ]; // glVertex3fv( &ctrvers[ i ][ v1*3 ]); // glVertex3fv( &ctrvers[ i ][ v2*3 ]); ////////////////////////////////////////////////////////////////////////// //cout<<"("<<v1<<","<<v2<<")"<<" "; ////////////////////////////////////////////////////////////////////////// glVertex3fv( &showctrvers[ i ][ v1* 3] ); glVertex3fv( &showctrvers[ i ][ v2* 3] ); } ////////////////////////////////////////////////////////////////////////// //cout<<endl; ////////////////////////////////////////////////////////////////////////// } glEnd(); //glPointSize(6); //glColor3f(0,0,0); //glBegin(GL_POINTS); //for( int i =0; i < ctrplanenum; i ++) //{ // for( int j = 0; j< ctrvernum[ i ]; j ++) // { // glVertex3fv(&ctrver[i][3*j]); // } //} //glEnd(); glEnable(GL_LIGHTING); // restore the farplane glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(20, (float)width/(float)height, nearplane, farplane); // get back to GL_MODELVIEW matrix glMatrixMode(GL_MODELVIEW); glPolygonMode ( GL_FRONT_AND_BACK, GL_FILL ); glLineWidth( 1 ); //glDisable(GL_LIGHTING); //glBegin(GL_LINES); //glColor3f( 1, 0, 1); //glLineWidth( 2 ); ////show conotur one by one //for( int i = 0; i < planenum; i ++) //{ // for( int j = 0;j < pctredgenum[ i ]; j++) // { // int v1 = pctredges[ i ][ 4*j ]; // int v2 = pctredges[ i ][ 4*j + 1 ]; // // glVertex3fv( &ctrvers[ i ][ v1*3 ]); // // glVertex3fv( &ctrvers[ i ][ v2*3 ]); // glVertex3fv( &showctrvers[ i ][ v1* 3] ); // glVertex3fv( &showctrvers[ i ][ v2* 3] ); // } //} //glEnd(); //glEnable(GL_LIGHTING); }