void DrawCircleArea(float cx, float cy, float cz, float r, int num_segments) { GLfloat vertex[4]; int PI = 3.141592653; const GLfloat delta_angle = 2.0*PI / num_segments; glBegin(GL_TRIANGLE_FAN); vertex[0] = cx; vertex[1] = cy; vertex[2] = cz; vertex[3] = 1.0; glVertex4fv(vertex); //draw the vertex on the contour of the circle for (int i = 0; i < num_segments; i++) { vertex[0] = cos(delta_angle*i) * r + cx; vertex[1] = sin(delta_angle*i) * r + cy; vertex[2] = cz; vertex[3] = 1.0; glVertex4fv(vertex); } vertex[0] = 1.0 * r + cx; vertex[1] = 0.0 * r + cy; vertex[2] = cz; vertex[3] = 1.0; glVertex4fv(vertex); glEnd(); }
/*********************************************************** compile map for fast display ***********************************************************/ void MapModel::Compile(int YLimit) { Uncompile(); MapFace * ptr = _faces; glNewList(_list_name, GL_COMPILE); glBegin(GL_TRIANGLES); for(int i=0; i<_nbfaces; ++i, ++ptr) { glTexCoord3fv(ptr->p1Text); glNormal3fv(ptr->p1Norm); glVertex4fv(ptr->p1Vertex); glTexCoord3fv(ptr->p2Text); glNormal3fv(ptr->p2Norm); glVertex4fv(ptr->p2Vertex); glTexCoord3fv(ptr->p3Text); glNormal3fv(ptr->p3Norm); glVertex4fv(ptr->p3Vertex); } glEnd(); glEndList(); }
void App::drawEnvironment(const float4x4 &mvp) { renderer->reset(); renderer->setShader(skyboxShaders[radialSelect][constMipSelect]); renderer->setTexture("EnvCube", cubeEnv); renderer->setTexture("Env2D", radialEnv); renderer->setShaderConstant1f("mipBias", mipBias->getValue()); renderer->setDepthState(noDepthWrite); renderer->apply(); float4x4 iMvp = !mvp; float4 v0( 0, 2, 1, 1); float4 v1( 3, -1, 1, 1); float4 v2(-3, -1, 1, 1); glBegin(GL_TRIANGLES); glTexCoord4fv(iMvp * v0); glVertex4fv(v0); glTexCoord4fv(iMvp * v1); glVertex4fv(v1); glTexCoord4fv(iMvp * v2); glVertex4fv(v2); glEnd(); }
void House::drawTriangle(GLfloat vertices[][4], int iv1, int iv2, int iv3, int ic) { glBegin(renderMode); { glColor3fv(colors[ic]); /*note the explicit use of homogeneous coords below: glVertex4f*/ glVertex4fv(vertices[iv1]); glVertex4fv(vertices[iv2]); glVertex4fv(vertices[iv3]); } glEnd(); }
/*********************************** FUNCTION: draw_quad ARGS: - a vertex array - 4 indices into the vertex array defining a quad face - an index into the color array. RETURN: none DOES: helper drawing function; draws one quad. For the normal to work out, follow left-hand-rule (i.e., counter clock wise) *************************************/ void draw_quad(GLfloat vertices[][4], int iv1, int iv2, int iv3, int iv4, int ic) { glBegin(crt_render_mode); { glColor3fv(colors[ic]); /*note the explicit use of homogeneous coords below: glVertex4f*/ glVertex4fv(vertices[iv1]); glVertex4fv(vertices[iv2]); glVertex4fv(vertices[iv3]); glVertex4fv(vertices[iv4]); } glEnd(); }
/*********************************** FUNCTION: draw_param_quad ARGS: - a 50 by 50 by 4 vertex array - 2 indices into the vertex array defining the top left of a quad face - an index into the color array. RETURN: none DOES: helper drawing function; draws one quad. *************************************/ void draw_param_quad(GLfloat vertices[][50][4], int line, int col, int ic) { glBegin(crt_render_mode); { glColor3fv(colors[ic]); /*note the explicit use of homogeneous coords below: glVertex4f*/ glVertex4fv(vertices[line][col]); glVertex4fv(vertices[line+1][col]); glVertex4fv(vertices[line+1][col+1]); glVertex4fv(vertices[line][col+1]); } glEnd(); }
void drawCube(int colorIndex) { for (int i = 0; i < 6; ++i) { glBegin(GL_POLYGON); glColor3fv(&cubeColors[colorIndex][i][0]); glNormal3fv(&cubeNormals[i][0]); glVertex4fv(&cubeVertexes[i][0][0]); glVertex4fv(&cubeVertexes[i][1][0]); glVertex4fv(&cubeVertexes[i][2][0]); glVertex4fv(&cubeVertexes[i][3][0]); glEnd(); } }
static void drawOct(void) { int i; for (i = 0; i < 8; ++i) { glNormal3f(0.0, 0.0, 1.0); glBegin(GL_TRIANGLE_FAN); glVertex4fv(&oct_vertices[i][0][0]); glVertex4fv(&oct_vertices[i][1][0]); glVertex4fv(&oct_vertices[i][2][0]); glEnd(); } }
void drawScene( ){ int i; for (i = 0; i < 6; ++i) { glBegin(GL_POLYGON); glColor3fv(&cubeColors[i][0]); glVertex4fv(&cubeVertexes[i][0][0]); glVertex4fv(&cubeVertexes[i][1][0]); glVertex4fv(&cubeVertexes[i][2][0]); glVertex4fv(&cubeVertexes[i][3][0]); glEnd(); } }
static void drawOctSides(void) { int i; for (i = 0; i < 8; ++i) { glNormal3fv(&oct_side_normals[i][0]); glBegin(GL_POLYGON); glVertex4fv(&oct_side_vertices[i][0][0]); glVertex4fv(&oct_side_vertices[i][1][0]); glVertex4fv(&oct_side_vertices[i][2][0]); glVertex4fv(&oct_side_vertices[i][3][0]); glEnd(); } }
GLvoid CRender::draw_circle(const GLfloat radius,const GLuint num_vertex, const GLfloat x, const GLfloat y) { GLfloat vertex[4]; //GLfloat texcoord[2]; const GLfloat delta_angle = (GLfloat)2.0*Pi/num_vertex; //glEnable(GL_TEXTURE_2D); //glBindTexture(GL_TEXTURE_2D,texID); //glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_REPLACE); glBegin(GL_TRIANGLE_FAN); //draw the vertex at the center of the circle //texcoord[0] = 0.5; //texcoord[1] = 0.5; //glTexCoord2fv(texcoord); vertex[0] = x; vertex[1] = y; vertex[2] = 0.0; vertex[3] = 1.0; glVertex4fv(vertex); for(GLuint i = 0; i < num_vertex ; i++) { //texcoord[0] = (cos(delta_angle*i) + 1.0)*0.5; //texcoord[1] = (sin(delta_angle*i) + 1.0)*0.5; //glTexCoord2fv(texcoord); vertex[0] = cos(delta_angle*i) * radius + x; vertex[1] = sin(delta_angle*i) * radius + y; vertex[2] = 0.0; vertex[3] = 1.0; glVertex4fv(vertex); } //texcoord[0] = (1.0 + 1.0)*0.5; //texcoord[1] = (0.0 + 1.0)*0.5; //glTexCoord2fv(texcoord); vertex[0] = (GLfloat)(1.0 * radius + x); vertex[1] = (GLfloat)(0.0 * radius + y); vertex[2] = 0.0; vertex[3] = 1.0; glVertex4fv(vertex); glEnd(); //glDisable(GL_TEXTURE_2D); }
void drawScene() { for (int i = 0; i < 6; i++) { glPushMatrix(); glBegin(GL_POLYGON); glColor3fv(&cubeColors[i][0]); glVertex4fv(&cubeVertexes[i][0][0]); glVertex4fv(&cubeVertexes[i][1][0]); glVertex4fv(&cubeVertexes[i][2][0]); glVertex4fv(&cubeVertexes[i][3][0]); glEnd(); glPopMatrix(); } }
// I thought about making a lookup table for this, but it would involve an STL map of STL vectors // and some weird function casts, so I'm doing it the naive way instead. void GeomRenderer::sendVertex(GLuint vertexIndex) { assert(vertexData.size >= 2 && vertexData.size <= 4); switch(vertexData.type) { case GL_SHORT: if (vertexData.size == 2) glVertex2sv((const GLshort*)((const char*)vertexData.pointer + vertexIndex*vertexData.stride)); if (vertexData.size == 3) glVertex3sv((const GLshort*)((const char*)vertexData.pointer + vertexIndex*vertexData.stride)); if (vertexData.size == 4) glVertex4sv((const GLshort*)((const char*)vertexData.pointer + vertexIndex*vertexData.stride)); break; case GL_INT: if (vertexData.size == 2) glVertex2iv((const GLint*)((const char*)vertexData.pointer + vertexIndex*vertexData.stride)); if (vertexData.size == 3) glVertex3iv((const GLint*)((const char*)vertexData.pointer + vertexIndex*vertexData.stride)); if (vertexData.size == 4) glVertex4iv((const GLint*)((const char*)vertexData.pointer + vertexIndex*vertexData.stride)); break; case GL_FLOAT: if (vertexData.size == 2) glVertex2fv((const GLfloat*)((const char*)vertexData.pointer + vertexIndex*vertexData.stride)); if (vertexData.size == 3) glVertex3fv((const GLfloat*)((const char*)vertexData.pointer + vertexIndex*vertexData.stride)); if (vertexData.size == 4) glVertex4fv((const GLfloat*)((const char*)vertexData.pointer + vertexIndex*vertexData.stride)); break; case GL_DOUBLE: if (vertexData.size == 2) glVertex2dv((const GLdouble*)((const char*)vertexData.pointer + vertexIndex*vertexData.stride)); if (vertexData.size == 3) glVertex3dv((const GLdouble*)((const char*)vertexData.pointer + vertexIndex*vertexData.stride)); if (vertexData.size == 4) glVertex4dv((const GLdouble*)((const char*)vertexData.pointer + vertexIndex*vertexData.stride)); break; } }
void VectorFieldRenderer::drawQuadric(GLfloat verts[50][50][4], int rs, int vs){ glBegin(GL_LINE_LOOP); glColor3f(1.0,0.0,0.0); for(int i = 0; i < rs; i++) for(int j = 0; j < vs; j++){ glVertex4fv(verts[i][j]); glVertex4fv(verts[i][j+1]); glVertex4fv(verts[i+1][j]); glVertex4fv(verts[i+1][j+1]); } glEnd(); }
void draw_quads(GLfloat vertices[12][12][4], int iv1a, int iv1b, int iv2a, int iv2b, int iv3a, int iv3b, int iv4a, int iv4b, GLfloat* color) { glMatrixMode(GL_MODELVIEW); glBegin(GL_POLYGON); { glColor3fv(color); glVertex4fv(vertices[iv1a][iv1b]); glVertex4fv(vertices[iv2a][iv2b]); glVertex4fv(vertices[iv3a][iv3b]); glVertex4fv(vertices[iv4a][iv4b]); } glEnd(); }
void drawball(void) { register int i,j; for (i=0; i < UDIV; i++) { for (j=0; j < VDIV; j++) { glBegin(GL_POLYGON); glVertex4fv( ballobj[i][j] ); glVertex4fv( ballobj[i+1][j] ); glVertex4fv( ballobj[i+1][j+1] ); glVertex4fv( ballobj[i][j+1] ); glEnd(); } } }
static void drawCube(GLfloat color[4], GLfloat ambient[4]) { int i; glMaterialfv(GL_FRONT, GL_DIFFUSE, color); glMaterialfv(GL_FRONT, GL_AMBIENT, ambient); for (i = 0; i < 6; ++i) { glNormal3fv(&cube_normals[i][0]); glBegin(GL_POLYGON); glVertex4fv(&cube_vertexes[i][0][0]); glVertex4fv(&cube_vertexes[i][1][0]); glVertex4fv(&cube_vertexes[i][2][0]); glVertex4fv(&cube_vertexes[i][3][0]); glEnd(); } }
// should be moved to render justgoingtothrowthatoutthere // render is in app instead of common currently, so that would have to be changed void RenderMesh(Camera* pCamera, Shader* pShader, Mesh* pMesh, const Vec4f& position, const Mat4f& orientation) { if(pShader == NULL) return; // should go away when we sort if(pMesh == NULL) return; // should go away when we sort pShader->StartUsing(); pShader->SetPosition(&position); pShader->SetOrientation(&orientation); pShader->SetCameraParams(pCamera); GLuint colorHandle = pShader->GetColorHandle(); // this is getting ugly to look at in a hurry // need to do buffers soon int numTris = pMesh->getNumberTriangles(); int startTriangle = 0; int endTriangle = numTris; glBegin(GL_TRIANGLES); Vec4f a, b, c; Vec4f colorA, colorB, colorC; //int colorIndex = 0; for (int t = startTriangle; t < endTriangle && t < numTris; t++) { pMesh->getTriangle(t, a, b, c); if(colorHandle != -1) { pMesh->getColors(t, colorA, colorB, colorC); glVertexAttrib4fv(colorHandle, colorA.raw()); } glVertex4fv(a.raw()); if(colorHandle != -1) { glVertexAttrib4fv(colorHandle, colorB.raw()); } glVertex4fv(b.raw()); if(colorHandle != -1) { glVertexAttrib4fv(colorHandle, colorC.raw()); } glVertex4fv(c.raw()); //if ((t+1) % 2 == 0) { // colorIndex = (colorIndex + 1) % colorArray.size(); //} } glEnd(); pShader->StopUsing(); }
enum piglit_result piglit_display(void) { /* * Simply draw a textured tri. The texture is solid red. * The tri is clipped. */ static const GLfloat v[3][4] = { { 10.0, 10.0, 0.0, 1.0 }, { 10.0, 1.0, 0.0, 1.0 }, { 1.0, 1.0, 0.0, 1.0 }, }; static const GLfloat t[3][2] = { { 0, 0 }, { 1, 0 }, { 1, 1 } }; static const GLfloat red[4] = { 1, 0, 0, 1 }; enum piglit_result result; make_texture(); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glBegin(GL_TRIANGLES); glTexCoord2fv(t[0]); glVertex4fv(v[0]); glTexCoord2fv(t[1]); glVertex4fv(v[1]); glTexCoord2fv(t[2]); glVertex4fv(v[2]); glEnd(); if (piglit_probe_pixel_rgb(piglit_width-5, piglit_height-20, red)) result = PIGLIT_PASS; else result = PIGLIT_FAIL; piglit_present_results(); return result; }
void draw_cube(GLfloat vertices[121][121][4], GLfloat normals[121][121][4], GLfloat tex[4][2], int iv1a, int iv1b, int iv2a, int iv2b, int iv3a, int iv3b, int iv4a, int iv4b, int ic) { glBegin(crt_render_mode); { //glColor3fv(colors[ic]); /*note the explicit use of homogeneous coords below: glVertex4f*/ glNormal3fv(normals[iv1a][iv1b]); glTexCoord2fv(tex[0]); glVertex4fv(vertices[iv1a][iv1b]); glTexCoord2fv(tex[1]); glVertex4fv(vertices[iv2a][iv2b]); glTexCoord2fv(tex[2]); glVertex4fv(vertices[iv3a][iv3b]); glTexCoord2fv(tex[3]); glVertex4fv(vertices[iv4a][iv4b]); } glEnd(); }
void draw_axes() { glLineWidth( 5.0 ); //glDisable(GL_LIGHTING); glBegin(GL_LINES); { glColor3fv(colors[1]); glVertex4fv(vertices_axes[0]); glVertex4fv(vertices_axes[1]); glColor3fv(colors[4]); glVertex4fv(vertices_axes[0]); glVertex4fv(vertices_axes[2]); glColor3fv(colors[6]); glVertex4fv(vertices_axes[0]); glVertex4fv(vertices_axes[3]); } glEnd(); glLineWidth( 1.0 ); //glEnable(GL_LIGHTING); }
/* ============================== R_FS_RasterizeLMap1Bfr static specular light map ============================== */ void R_FS_RasterizeTMapsBfr_lmap1( void ) { int i, j, num; glEnableClientState( GL_VERTEX_ARRAY ); glVertexPointer( 4, GL_FLOAT, 0, fs_vertex_array ); glEnableClientState( GL_TEXTURE_COORD_ARRAY ); glTexCoordPointer( 2, GL_FLOAT, 0, fs_lmap1_texcoord_array ); glEnable( GL_TEXTURE_2D ); glEnable(GL_BLEND); glTexEnvi( GL_TEXTURE_2D, GL_TEXTURE_ENV_MODE, GL_MODULATE ); glBlendFunc( GL_ONE, GL_ONE ); for ( i = 0; i < MAX_LIGHTPAGES; i++ ) { num = fs_lmap1num[i]; if ( !num ) continue; glBindTexture( GL_TEXTURE_2D, r_lightpages[i].texobj ); for( j = 0; j < num; j++ ) { int *faceptr; int pointnum; int k, elmt; faceptr = fs_lmap1facebfr[i][j]; if ( !faceptr ) break; pointnum = *faceptr++; // maps flag faceptr++; elmt = *faceptr++; glBegin( GL_TRIANGLE_FAN ); for ( k = 0; k < pointnum; k++, elmt++ ) { glTexCoord2fv( fs_lmap1_texcoord_array[elmt] ); glVertex4fv( fs_vertex_array[elmt] ); } glEnd(); } } }
void draw_quads(GLfloat vertices[121][121][4], GLfloat normals[121][121][4], GLfloat tex[121][121][2], int iv1a, int iv1b, int iv2a, int iv2b, int iv3a, int iv3b, int iv4a, int iv4b, int ic) { glMatrixMode(GL_TEXTURE); glLoadIdentity(); glScalef(-1.0, 1.0, 1.0); glMatrixMode(GL_MODELVIEW); glBegin(crt_render_mode); { // glColor3fv(colors[ic]); glNormal3fv(normals[iv1a][iv1b]); glTexCoord2fv(tex[iv1a][iv1b]); glVertex4fv(vertices[iv1a][iv1b]); glTexCoord2fv(tex[iv2a][iv2b]); glVertex4fv(vertices[iv2a][iv2b]); glTexCoord2fv(tex[iv3a][iv3b]); glVertex4fv(vertices[iv3a][iv3b]); glTexCoord2fv(tex[iv4a][iv4b]); glVertex4fv(vertices[iv4a][iv4b]); } glEnd(); }
void SoGLCoordinateElement::send(int index) const // //////////////////////////////////////////////////////////////////////// { #ifdef DEBUG if (index < 0 || index >= numCoords) SoDebugError::post("SoGLCoordinateElement::send", "Index (%d) is out of range 0 - %d", index, numCoords - 1); #endif /* DEBUG */ if (coordsAre3D) glVertex3fv(coords3[index].getValue()); else glVertex4fv(coords4[index].getValue()); }
void Curva::dibujarInmediato() //Dibujo inmediato sin DL { glBegin(GL_LINE_STRIP); for (int i=0; i<101; i++){ glVertex4fv(glm::value_ptr(q(i*0.01f))); }; glEnd(); glBegin(GL_LINES); for (float u=0; u<=1; u+=0.01){ Vector pos=q(u).xyz; //cuidado con el swizzle. Devuelve referencias no objetos del tipo Vector incn=n(u)*0.1f; Vector incb=b(u)*0.1f; glVertex3fv(glm::value_ptr( pos )); glVertex3fv(glm::value_ptr( pos + incn )); glVertex3fv(glm::value_ptr( pos )); glVertex3fv(glm::value_ptr( pos + incb )); }; glEnd(); }
/** * Draw the OBJ model. */ void RenderOBJModel (struct obj_model_t *mdl) { int i, j; //glDisable(GL_LIGHTING); //printf("%d\n", mdl->num_faces); for (i = 0; i < mdl->num_faces; ++i) { glBegin (mdl->faces[i].type); for (j = 0; j < mdl->faces[i].num_elems; ++j) { if (mdl->has_texCoords) { //printf("test2 %d\n", i); //printf("test3 %d\n", mdl->texCoords[mdl->faces[i].uvw_indices[j]].uvw); glTexCoord3fv (mdl->texCoords[mdl->faces[i].uvw_indices[j]].uvw); //glTexCoord3fv (mdl->texCoords[mdl->faces[219].uvw_indices[3]].uvw); } if (mdl->has_normals){ //glNormal3fv (mdl->normals[mdl->faces[219].norm_indices[3]].ijk); glNormal3fv (mdl->normals[mdl->faces[i].norm_indices[j]].ijk); } glVertex4fv (mdl->vertices [mdl->faces[i].vert_indices[j]].xyzw); } glEnd(); } /*if (hasname) { glDisable(GL_LIGHTING); }*/ }
void glArrayElement(GLint i) { if (i < 0) { ERROR(GL_INVALID_VALUE); } GLfloat *v; pointer_state_t *p; p = &state.pointers.color; if (state.enable.color_array && p->pointer) { v = gl_pointer_index(p, i); GLuint scale = gl_max_value(p->type); // color[3] defaults to 1.0f if (p->size < 4) v[3] = 1.0f; // scale color coordinates to a 0 - 1.0 range for (int i = 0; i < p->size; i++) { v[i] /= scale; } glColor4fv(v); } p = &state.pointers.normal; if (state.enable.normal_array && p->pointer) { v = gl_pointer_index(p, i); glNormal3fv(v); } for (int i = 0; i < MAX_TEX; i++) { p = &state.pointers.tex_coord[i]; if (state.enable.tex_coord_array[i] && p->pointer) { v = gl_pointer_index(p, i); glMultiTexCoord2fv(GL_TEXTURE0 + i, v); } } p = &state.pointers.vertex; if (state.enable.vertex_array && p->pointer) { v = gl_pointer_index(p, i); if (p->size == 4) { glVertex4fv(v); } else { glVertex3fv(v); } } }
/** * Draw the OBJ model. */ void RenderOBJModel (struct obj_model_t *mdl) { int i, j; for (i = 0; i < mdl->num_faces; ++i) { glBegin (mdl->faces[i].type); for (j = 0; j < mdl->faces[i].num_elems; ++j) { if (mdl->has_texCoords) glTexCoord3fv (mdl->texCoords[mdl->faces[i].uvw_indices[j]].uvw); if (mdl->has_normals) glNormal3fv (mdl->normals[mdl->faces[i].norm_indices[j]].ijk); glVertex4fv (mdl->vertices [mdl->faces[i].vert_indices[j]].xyzw); } glEnd(); } }
/** * Draw the OBJ model. */ void LoadOBJ::RenderOBJModel () { int i, j; for (i = 0; i < mdl.num_faces; ++i) { glBegin (mdl.faces[i].type); //glBegin (GL_LINE_STRIP); for (j = 0; j < mdl.faces[i].num_elems; ++j) { if (mdl.has_texCoords) glTexCoord3fv (mdl.texCoords[mdl.faces[i].uvw_indices[j]].uvw); if (mdl.has_normals) glNormal3fv (mdl.normals[mdl.faces[i].norm_indices[j]].ijk); glVertex4fv (mdl.vertices [mdl.faces[i].vert_indices[j]].xyzw); } glEnd(); } }
static void im_render () { GLint i; glBegin (GL_POINTS); for (i = 0; i < sizeof (attribs) / sizeof (*attribs); i++) { struct ATTRIB_DATA *att = &attribs[i]; switch (att->dispatch) { case C: glColor4fv (att->data); break; case S: glSecondaryColor3fvEXT (att->data); break; case N: glNormal3fv (att->data); break; case V: glVertex4fv (att->data); break; case T: assert (att->index >= 0 && att->index < 8); glMultiTexCoord4fvARB (GL_TEXTURE0_ARB + att->index, att->data); break; case F: glFogCoordfvEXT (att->data); break; case A: assert (att->index > 0 && att->index < 16); glVertexAttrib4fvARB (att->index, att->data); break; default: assert (0); } } glEnd (); }