ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

primitiveStream.cc
Go to the documentation of this file.
00001 /*
00002 ** License Applicability. Except to the extent portions of this file are
00003 ** made subject to an alternative license as permitted in the SGI Free
00004 ** Software License B, Version 1.1 (the "License"), the contents of this
00005 ** file are subject only to the provisions of the License. You may not use
00006 ** this file except in compliance with the License. You may obtain a copy
00007 ** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
00008 ** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
00009 ** 
00010 ** http://oss.sgi.com/projects/FreeB
00011 ** 
00012 ** Note that, as provided in the License, the Software is distributed on an
00013 ** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
00014 ** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
00015 ** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
00016 ** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
00017 ** 
00018 ** Original Code. The Original Code is: OpenGL Sample Implementation,
00019 ** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
00020 ** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
00021 ** Copyright in any portions created by third parties is as indicated
00022 ** elsewhere herein. All Rights Reserved.
00023 ** 
00024 ** Additional Notice Provisions: The application programming interfaces
00025 ** established by SGI in conjunction with the Original Code are The
00026 ** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
00027 ** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
00028 ** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
00029 ** Window System(R) (Version 1.3), released October 19, 1998. This software
00030 ** was created using the OpenGL(R) version 1.2.1 Sample Implementation
00031 ** published by SGI, but has not been independently verified as being
00032 ** compliant with the OpenGL(R) version 1.2.1 Specification.
00033 **
00034 ** $Date: 2006-03-12 00:07:02 +0000 (Sun, 12 Mar 2006) $ $Revision: 1.1 $
00035 */
00036 /*
00037 ** $Header: /cygdrive/c/RCVS/CVS/ReactOS/reactos/lib/glu32/libnurbs/nurbtess/primitiveStream.cc,v 1.1 2004/02/02 16:39:13 navaraf Exp $
00038 */
00039 
00040 #include "gluos.h"
00041 #include <stdlib.h>
00042 #include <stdio.h>
00043 #include <assert.h>
00044 #include <GL/gl.h> 
00045 
00046 #include "primitiveStream.h"
00047 
00048 Int primStream::num_triangles()
00049 {
00050   Int i;
00051   Int ret=0;
00052   for(i=0; i<index_lengths; i++)
00053     {
00054       ret += lengths[i]-2;
00055     }
00056   return ret;
00057 }
00058 
00059       
00060 
00061 /*the begining of inserting a new primitive. 
00062  *reset counter to be 0.
00063  */
00064 void primStream::begin()
00065 {
00066   counter = 0;
00067 }
00068 
00069 void primStream::insert(Real u, Real v)
00070 {
00071   /*if the space cannot hold u and v,
00072    *we have to expand the array
00073    */
00074   if(index_vertices+1 >= size_vertices) {
00075     Real* temp = (Real*) malloc (sizeof(Real) * (2*size_vertices + 2));
00076     assert(temp);
00077     
00078     /*copy*/
00079     for(Int i=0; i<index_vertices; i++)
00080       temp[i] = vertices[i];
00081     
00082     free(vertices);
00083     vertices = temp;
00084     size_vertices = 2*size_vertices + 2;
00085   }
00086 
00087   vertices[index_vertices++] = u;
00088   vertices[index_vertices++] = v;
00089   counter++;
00090 }
00091 
00092 /*the end of a primitive.
00093  *increase index_lengths 
00094  */
00095 void primStream::end(Int type)
00096 {
00097   Int i;
00098   /*if there is no vertex in this primitive, 
00099    *nothing needs to be done
00100    */
00101   if(counter == 0) return ;
00102 
00103   if(index_lengths >= size_lengths){
00104     Int* temp = (Int*) malloc(sizeof(Int) * (2*size_lengths + 2));
00105     assert(temp);
00106     Int* tempTypes = (Int*) malloc(sizeof(Int) * (2*size_lengths + 2));
00107     assert(tempTypes);
00108     
00109     /*copy*/
00110     for(i=0; i<index_lengths; i++){
00111       temp[i] = lengths[i];
00112       tempTypes[i] = types[i];
00113     }
00114     
00115     free(lengths);
00116     free(types);
00117     lengths = temp;
00118     types = tempTypes;
00119     size_lengths = 2*size_lengths + 2;
00120   }
00121   lengths[index_lengths] = counter;
00122   types[index_lengths] = type;
00123   index_lengths++;
00124 }
00125 
00126 void primStream::print()
00127 {
00128   Int i,j,k;
00129   printf("index_lengths=%i,size_lengths=%i\n", index_lengths, size_lengths);
00130   printf("index_vertices=%i,size_vertices=%i\n", index_vertices, size_vertices);
00131   k=0;
00132   for(i=0; i<index_lengths; i++)
00133     {
00134       if(types[i] == PRIMITIVE_STREAM_FAN)
00135     printf("primitive-FAN:\n");
00136       else 
00137     printf("primitive-STRIP:\n");
00138       for(j=0; j<lengths[i]; j++)
00139     {
00140       printf("(%f,%f) ", vertices[k], vertices[k+1]);
00141       k += 2;     
00142     }
00143       printf("\n");
00144     }
00145 }
00146 
00147 primStream::primStream(Int sizeLengths, Int sizeVertices)
00148 {
00149   lengths = (Int*)malloc (sizeof(Int) * sizeLengths);
00150   assert(lengths);
00151   types = (Int*)malloc (sizeof(Int) * sizeLengths);
00152   assert(types);
00153   
00154   vertices = (Real*) malloc(sizeof(Real) * sizeVertices);
00155   assert(vertices);
00156   
00157   index_lengths = 0;
00158   index_vertices = 0;
00159   size_lengths = sizeLengths;
00160   size_vertices = sizeVertices; 
00161 }
00162 
00163 primStream::~primStream()
00164 {
00165   free(lengths);
00166   free(types);
00167   free(vertices);
00168 }
00169 
00170 void primStream::draw()
00171 {
00172   Int i,j,k;
00173   k=0;
00174   for(i=0; i<index_lengths; i++)
00175     {
00176       switch(types[i]){
00177       case PRIMITIVE_STREAM_FAN:
00178     glBegin(GL_TRIANGLE_FAN);
00179     break;
00180       case PRIMITIVE_STREAM_STRIP:
00181     glBegin(GL_TRIANGLE_STRIP);
00182     break;
00183       }
00184       
00185       for(j=0; j<lengths[i]; j++){
00186     glVertex2fv(vertices+k);
00187     k += 2;
00188       }
00189       glEnd();
00190     }
00191 }
00192 

Generated on Sun May 27 2012 04:23:49 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.