示例#1
0
/***********************************************************
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();
}
示例#2
0
static void
draw_face(int x, int y, int dim, int face)
{
	glViewport(0, 0, piglit_width, piglit_height);
	piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE);

	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, piglit_winsys_fbo);

	glEnable(GL_TEXTURE_CUBE_MAP);
	glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
	glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
	glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);

	glBegin(GL_QUADS);

	glTexCoord3fv(cube_face_texcoords[face][0]);
	glVertex2f(x, y);

	glTexCoord3fv(cube_face_texcoords[face][1]);
	glVertex2f(x + dim, y);

	glTexCoord3fv(cube_face_texcoords[face][2]);
	glVertex2f(x + dim, y + dim);

	glTexCoord3fv(cube_face_texcoords[face][3]);
	glVertex2f(x, y + dim);

	glEnd();

	glDisable(GL_TEXTURE_CUBE_MAP);
}
示例#3
0
文件: brick.c 项目: phoboz/volkit
static void render_plane(
    VRState *state,
    Brick *b,
    Coord cpt[8],
    float cp[4]
    )
{
    int j, n;
    GLfloat p[8][3];

    /* Get vertices for plane */
    n = get_plane_cube_intersect(cp[0], cp[1], cp[2], cp[3], p, cpt);

    if (n > 2)
    {
        /* Draw plane */
        glBegin(GL_POLYGON);
        for (j = 0; j < n; j++)
        {
            glTexCoord3fv(p[j]);
            glVertex3fv(p[j]);
        }
        glEnd();
    }
}
示例#4
0
static void WINE_GLAPI wine_glMultiTexCoord3fvARB(GLenum target, const GLfloat *v) {
    if(target != GL_TEXTURE0) {
        ERR("Texture unit > 0 used, but GL_ARB_multitexture is not supported\n");
        return;
    }
    glTexCoord3fv(v);
}
示例#5
0
static void draw_skybox( void )
{
   if ( use_vertex_arrays ) {
      glTexCoordPointer( 3, GL_FLOAT, 0, tex_coords );
      glVertexPointer(   3, GL_FLOAT, 0, vtx_coords );

      glEnableClientState( GL_TEXTURE_COORD_ARRAY );
      glEnableClientState( GL_VERTEX_ARRAY );

      glDrawArrays( GL_QUADS, 0, 24 );

      glDisableClientState( GL_TEXTURE_COORD_ARRAY );
      glDisableClientState( GL_VERTEX_ARRAY );
   }
   else {
      unsigned   i;

      glBegin(GL_QUADS);
      for ( i = 0 ; i < 24 ; i++ ) {
	 glTexCoord3fv( & tex_coords[ i * 3 ] );
	 glVertex3fv  ( & vtx_coords[ i * 3 ] );
      }
      glEnd();
   }
}
示例#6
0
void GeomRenderer::sendTexCoord(GLuint texCoordIndex)
{
    assert(texCoordData.size >= 1 && texCoordData.size <= 4);

    switch(texCoordData.type)
    {
        case GL_SHORT:
            if (texCoordData.size == 1) glTexCoord1sv((const GLshort*)((const char*)texCoordData.pointer + texCoordIndex*texCoordData.stride));
            if (texCoordData.size == 2) glTexCoord2sv((const GLshort*)((const char*)texCoordData.pointer + texCoordIndex*texCoordData.stride));
            if (texCoordData.size == 3) glTexCoord3sv((const GLshort*)((const char*)texCoordData.pointer + texCoordIndex*texCoordData.stride));
            if (texCoordData.size == 4) glTexCoord4sv((const GLshort*)((const char*)texCoordData.pointer + texCoordIndex*texCoordData.stride));
            break;

        case GL_INT:
            if (texCoordData.size == 1) glTexCoord1iv((const GLint*)((const char*)texCoordData.pointer + texCoordIndex*texCoordData.stride));
            if (texCoordData.size == 2) glTexCoord2iv((const GLint*)((const char*)texCoordData.pointer + texCoordIndex*texCoordData.stride));
            if (texCoordData.size == 3) glTexCoord3iv((const GLint*)((const char*)texCoordData.pointer + texCoordIndex*texCoordData.stride));
            if (texCoordData.size == 4) glTexCoord4iv((const GLint*)((const char*)texCoordData.pointer + texCoordIndex*texCoordData.stride));
            break;

        case GL_FLOAT:
            if (texCoordData.size == 1) glTexCoord1fv((const GLfloat*)((const char*)texCoordData.pointer + texCoordIndex*texCoordData.stride));
            if (texCoordData.size == 2) glTexCoord2fv((const GLfloat*)((const char*)texCoordData.pointer + texCoordIndex*texCoordData.stride));
            if (texCoordData.size == 3) glTexCoord3fv((const GLfloat*)((const char*)texCoordData.pointer + texCoordIndex*texCoordData.stride));
            if (texCoordData.size == 4) glTexCoord4fv((const GLfloat*)((const char*)texCoordData.pointer + texCoordIndex*texCoordData.stride));
            break;

        case GL_DOUBLE:
            if (texCoordData.size == 1) glTexCoord1dv((const GLdouble*)((const char*)texCoordData.pointer + texCoordIndex*texCoordData.stride));
            if (texCoordData.size == 2) glTexCoord2dv((const GLdouble*)((const char*)texCoordData.pointer + texCoordIndex*texCoordData.stride));
            if (texCoordData.size == 3) glTexCoord3dv((const GLdouble*)((const char*)texCoordData.pointer + texCoordIndex*texCoordData.stride));
            if (texCoordData.size == 4) glTexCoord4dv((const GLdouble*)((const char*)texCoordData.pointer + texCoordIndex*texCoordData.stride));
            break;
    }
}
示例#7
0
void drawMesh()
{
    int i, j;

    if (g_mesh){

        glBegin(GL_TRIANGLES);

        for (i =0; i < g_mesh->numFaces; ++i){
            HTriangle face = &g_mesh->triangles[i];
            for (j = 0; j < 3; ++j){

                if (face->vn[j] >= 0){
                    glNormal3fv(&g_mesh->normals[face->vn[j]].x);
                }

                if (face->vt[j] >= 0){
                    glTexCoord3fv(&g_mesh->texcoords[face->vt[j]].x);
                }

                glVertex3fv(&g_mesh->vertices[g_mesh->triangles[i].v[j]].x);
            }
        }

        glEnd();
    }
}
示例#8
0
文件: brick.c 项目: phoboz/volkit
static void render_slices(
    Brick *b,
    VRState *state,
    Coord cpt[8],
    int direction
    )
{
    int i, j, n;
    float d;
    float min_z, max_z;
    int slice_count;
    GLfloat p[8][3];

    /* Get slice distance from state */
    float delta = state->view->delta;
    float dz = delta * (float) direction;

    min_z =  HUGE;
    max_z = -HUGE;

    /* Find minimum and maximum z-coordinates */
    for (i = 0; i < 8; i++)
    {
        if (min_z > cpt[i][2])
        {
            min_z = cpt[i][2];
        }
        if (max_z < cpt[i][2])
        {
            max_z = cpt[i][2];
        }
    }

    min_z = floor(min_z / delta) * delta;
    max_z = floor(max_z / delta) * delta;

    /* For each slice */
    slice_count = 0;
    for (d = min_z; (direction == 1) ? (d <= max_z) : (d >= max_z); d += dz)
    {
        /* Get intersection polygon */
        n = get_plane_cube_intersect(0.0, 0.0, 1.0, -d, p, cpt);
        if (n > 2)
        {
            slice_count++;

            /* Draw slice */
            glBegin(GL_POLYGON);
            for (j = 0; j < n; j++)
            {
                glTexCoord3fv(p[j]);
                glVertex3fv(p[j]);
            }
            glEnd();
        }
    }
}
示例#9
0
void yglTexTris(long ntri, float *verts, float *texverts)
{
  long i, nd;

  if(alpha_pass) return;
  /* Draw an array of 3Dtextured triangles. */
  glBindTexture(glCurrWin3d->myGL_TEXTURE_3D, texName3d);
  glBegin(GL_TRIANGLES);
  for(i= 0; i < ntri; i++) {
    nd= 9*i;  /* 3 coords per vertex, 3 vertices per tri */
    glTexCoord3fv(texverts+nd);
    glVertex3fv(verts+nd);
    glTexCoord3fv(texverts+nd+3);
    glVertex3fv(verts+nd+3);
    glTexCoord3fv(texverts+nd+6);
    glVertex3fv(verts+nd+6);
  }
  glEnd();
}
示例#10
0
inline void vRenderer::renderSlice(int edges,float tc[6][3], float pc[6][3],int   order[6])
{
    glBegin(GL_POLYGON);  {//draw slice and texture map it
	for(int j=0; j< edges; ++j)
	{
	    glTexCoord3fv(tc[order[j]]);
	    glVertex3fv(pc[order[j]]);
	}
    } glEnd();
}
示例#11
0
/**
 * 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);
    }*/
  

}
/**
 * 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();
    }
}
示例#13
0
文件: obj.c 项目: echo0101/Island
/**
 * 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();
    }
}
示例#14
0
void CMesh::draw() const
{
	bool isTransparent;
	// bind the texture
	if (hasTexture()) {
		glBindTexture (GL_TEXTURE_2D, m_pTexture->getID());
		isTransparent = m_pTexture->isTransparent();
	}
	else isTransparent = false;

	bool isDepthTestEnabled = glIsEnabled(GL_DEPTH_TEST);
	if (isTransparent)
		glDisable(GL_DEPTH_TEST);
	glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, m_material.Ka);
	glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, m_material.Kd);
	glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, m_material.Ks);
	glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, m_material.Ns);
	// draw each face...
	for (vector<SPolygonFace>::const_iterator itFace = m_faceVector.begin(); itFace != m_faceVector.end(); ++itFace)
	{
		glColor3f(1, 1, 0);
		glBegin(GL_POLYGON);
		//	TODO: passer ˆà for_each
		for (unsigned i = 0; i < (*itFace).v.size(); ++i) {
			glNormal3fv(m_normVector[(*itFace).vn[i]].getVertex3fv());
			if (hasTexture() && hasTextureCoords())
				glTexCoord3fv(m_texVector[(*itFace).vt[i]].getVertex3fv());
			glVertex3fv(m_vertVector[(*itFace).v[i]].getVertex3fv());
		}
		glEnd();	//	GL_POLYGON
	}
	//	restore depth test
	if (isDepthTestEnabled)
		glEnable(GL_DEPTH_TEST);
	else
		glDisable(GL_DEPTH_TEST);
}
示例#15
0
文件: g_render.c 项目: aosm/X11
void __glXDisp_TexCoord3fv(GLbyte *pc)
{
	glTexCoord3fv( 
		(GLfloat  *)(pc + 0)
	);
}
示例#16
0
文件: cubemap.c 项目: RAOF/piglit
static GLboolean
draw_at_size(int size, int x_offset, int y_offset, GLboolean mipmapped)
{
	GLfloat row_y = PAD + y_offset;
	int dim, face;
	int color = 0, level = 0;
	GLuint texname;
	GLboolean pass = GL_TRUE;

	/* Create the texture. */
	glGenTextures(1, &texname);
	glBindTexture(GL_TEXTURE_CUBE_MAP_ARB, texname);

	/* For each face drawing, we want to only see that face's contents at
	 * that mipmap level.
	 */
	if (mipmapped) {
		glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB,
				GL_TEXTURE_MIN_FILTER,
				GL_NEAREST_MIPMAP_NEAREST);
	} else {
		glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB,
				GL_TEXTURE_MIN_FILTER,
				GL_NEAREST);
	}
	glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB,
			GL_TEXTURE_MAG_FILTER, GL_NEAREST);
	glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB,
			GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
	glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB,
			GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

	/* Fill in faces on each level */
	for (dim = size; dim > 0; dim /= 2) {
		for (face = 0; face < 6; face++) {
			set_face_image(level, cube_face_targets[face],
				       dim, color);
			color = (color + 1) % ARRAY_SIZE(colors);
		}
		if (!mipmapped)
			break;

		level++;
	}

	glEnable(GL_TEXTURE_CUBE_MAP_ARB);

	color = 0;
	level = 0;
	for (dim = size; dim > 0; dim /= 2) {
		GLfloat row_x = PAD + x_offset;

		for (face = 0; face < 6; face++) {
			GLfloat base_x = row_x + face * (max_size + PAD);
			GLfloat base_y = row_y;

			glBegin(GL_QUADS);

			glTexCoord3fv(cube_face_texcoords[face][0]);
			glVertex2f(base_x, base_y);

			glTexCoord3fv(cube_face_texcoords[face][1]);
			glVertex2f(base_x + dim, base_y);

			glTexCoord3fv(cube_face_texcoords[face][2]);
			glVertex2f(base_x + dim, base_y + dim);

			glTexCoord3fv(cube_face_texcoords[face][3]);
			glVertex2f(base_x, base_y + dim);

			glEnd();

			if (dim > 2) {
				pass = test_results(base_x, base_y,
						    dim, level, face,
						    mipmapped,
						    color) && pass;
			}

			color = (color + 1) % ARRAY_SIZE(colors);
		}

		if (!mipmapped)
			break;

		row_y += dim + PAD;
		level++;
	}

	glDeleteTextures(1, &texname);

	return pass;
}
示例#17
0
void PolygonForeground::draw(DrawEnv *pEnv)
{
    if(getActive() == false)
        return;

    if(getMFPositions()->size() == 0) // nothing to render
        return;

    if(pEnv->getPixelWidth()  == 0 ||
       pEnv->getPixelHeight() == 0   ) // nothing to render to
        return;
        
    bool bUseTC = true;

    if(getMFPositions()->size() != getMFTexCoords()->size())
    {
#if 0
        FWARNING(("PolygonForeground::draw: positions and texcoords have "
                  "different sizes (%d vs. %d)!\n", 
                  getMFPositions()->size(), getMFTexCoords()->size()));
        return;
#endif

        bUseTC = false;
    }
       
    glPushAttrib(GL_ALL_ATTRIB_BITS);

    Real32 aspectX = 1.0f, aspectY = 1.0f;
    
    if(getAspectHeight() && getAspectWidth())
    {
        aspectX = 
            (Real32(pEnv->getPixelHeight()) / getAspectHeight()) /
            (Real32(pEnv->getPixelWidth())  / getAspectWidth());
    }
 
    glMatrixMode(GL_MODELVIEW);
    glPushMatrix();
    glLoadIdentity();

    glMatrixMode(GL_PROJECTION);
    glPushMatrix();
    glLoadIdentity();
    
	Real32 sFac = getScale() > 0 ? getScale() : 1.0f;
	
	UInt32 width  = pEnv->getPixelWidth(),
		   height = pEnv->getPixelHeight();
    
    if(pEnv->getTileFullSize()[0] != 0 && getTile() == false)
    {
        width  = pEnv->getTileFullSize()[0];
        height = pEnv->getTileFullSize()[1];

        Real32 t = 0;
#if 0
        Real32 left   = pEnv->getTileRegion()[0]; //cdP->getLeft(),
        Real32 right  = pEnv->getTileRegion()[1]; //cdP->getRight(),
        Real32 top    = pEnv->getTileRegion()[3]; //cdP->getTop(),
        Real32 bottom = pEnv->getTileRegion()[2]; //cdP->getBottom();
#endif
        
        if (getAspectHeight() && getAspectWidth() &&
            height != 0 && width != 0)
        {
            aspectX = 
                (Real32(height/getAspectHeight())) /
                (Real32(width / getAspectWidth()));

            t  = Real32(width) * (1 - aspectX) * 0.5f;
            t *= Real32(pEnv->getPixelWidth()) / width;
        }
		
        Matrix sm = pEnv->calcTileDecorationMatrix();
        
        glLoadMatrixf(sm.getValues());
        glOrtho(0, pEnv->getPixelWidth(), 0, pEnv->getPixelHeight(), 0, 1);

        glTranslatef(t, 0, 0);
        glScalef(aspectX, aspectY, 1);

        float t1 = (1 - sFac) * 0.5f * Real32(pEnv->getPixelWidth());
        float t2 = (1 - sFac) * 0.5f * Real32(pEnv->getPixelHeight());
        glTranslatef(t1, t2, 0);
        glScalef(sFac,sFac,1);
    }
    else
    {
        glScalef(sFac,sFac,1);
        
        glScalef(aspectX, aspectY, 1);
        
        glOrtho(0, pEnv->getPixelWidth(), 0, pEnv->getPixelHeight(), 0, 1);
    }

    getMaterial()->getState()->activate(pEnv);
   
    const Vec3f *tc  = NULL;

    if(bUseTC == true)
    {
        tc = &((*getMFTexCoords())[0]);
    }

    const Pnt2f *pos = &((*getMFPositions())[0]);
    
    glBegin(GL_POLYGON);
    
    for(UInt16 i = 0; i < getMFPositions()->size(); i++)
    {
        if(bUseTC == true)
        {
            glTexCoord3fv( tc[i].getValues() );
        }

        glVertex2f( mapCoordinate(pos[i][0], Real32(pEnv->getPixelWidth()),
                                             getNormalizedX()),
                    mapCoordinate(pos[i][1], Real32(pEnv->getPixelHeight()),
                                             getNormalizedY()) );
    }

    glEnd();
    
    getMaterial()->getState()->deactivate(pEnv);

    glScalef(1, 1, 1);
    
    glPopMatrix();

    glMatrixMode(GL_MODELVIEW);
    glPopMatrix();

    glPopAttrib();
}
void SkyBackground::drawFace(      DrawEnv             * pEnv,
                                   TextureBaseChunk    * tex,
                                   StateChunk          *&oldtex,
                             const Pnt3f                &p1,
                             const Pnt3f                &p2,
                             const Pnt3f                &p3,
                             const Pnt3f                &p4,
                             const Vec3f               * texCoord)
{
#if !defined(OSG_OGL_COREONLY) || defined(OSG_CHECK_COREONLY)
    if(tex != NULL)
    {
        if(oldtex != NULL)
        {
            tex->changeFrom(pEnv, oldtex);
        }
        else
        {
            tex->activate(pEnv);
        }

        if(tex->isTransparent())
        {
            glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
            glEnable(GL_BLEND);
        }

        // ENRICO: this part holds the informations about
        // custom texture coordinates
        // Mess with the best, die like the rest
        glBegin(GL_QUADS);
        {
#if 0 // strange crash with par drawers.
            glTexCoord3fv(static_cast<const GLfloat *>(
                              texCoord[0].getValues()));
            glVertex3fv  (static_cast<const GLfloat *>(p1.getValues()));

            glTexCoord3fv(static_cast<const GLfloat *>(
                              texCoord[1].getValues()));
            glVertex3fv  (static_cast<const GLfloat *>(p2.getValues()));

            glTexCoord3fv(static_cast<const GLfloat *>(
                              texCoord[2].getValues()));
            glVertex3fv  (static_cast<const GLfloat *>(p3.getValues()));

            glTexCoord3fv(static_cast<const GLfloat *>(
                              texCoord[3].getValues()));
            glVertex3fv  (static_cast<const GLfloat *>(p4.getValues()));
#else
            glTexCoord3fv(static_cast<const GLfloat *>(
                              texCoord[0].getValues()));
            glVertex3f  (p1[0], p1[1], p1[2]);

            glTexCoord3fv(static_cast<const GLfloat *>(
                              texCoord[1].getValues()));
            glVertex3f   (p2[0], p2[1], p2[2]);

            glTexCoord3fv(static_cast<const GLfloat *>(
                              texCoord[2].getValues()));
            glVertex3f   (p3[0], p3[1], p3[2]);

            glTexCoord3fv(texCoord[3].getValues());
            glVertex3f   (p4[0], p4[1], p4[2]);
#endif
        }
        glEnd();

        if(tex->isTransparent())
        {
            glDisable(GL_BLEND);
        }

        oldtex = tex;
    }
#endif
}
示例#19
0
void 
CLineAnimatorInOpenGL::_TraversePoint(int iPointIndex, int iTraceIndex, float fX, float fY, float fZ, float fT)
{
	static list<int>::iterator liiParticleIterator;
	static VECTOR3 v3PrevPoint;
	static VECTOR3 v3PrevTangent;
	// ADD-BY-LEETEN 07/07/2010-BEGIN
	static VECTOR4 v4PrevColor;
	VECTOR4 v4Color = cColorScheme.V4GetColor();
	// ADD-BY-LEETEN 07/07/2010-END
	VECTOR3 v3Point(fX, fY, fZ);

	if( 0 == iPointIndex )
	{
		for(liiParticleIterator  = liParticles.begin();		
			liiParticleIterator != liParticles.end() && *liiParticleIterator < 0;
			liiParticleIterator++)
			;
	}

	VECTOR3 v3Tangent = v3Point - v3PrevPoint;
	v3Tangent.Normalize();

	if( liiParticleIterator != liParticles.end() && iPointIndex == *liiParticleIterator )
	{
		#if	0	// MOD-BY-LEETEN 07/05/2010-FROM:
			if( iPointIndex > 0 )
			{
				if( 1 == iPointIndex )
					glTexCoord3fv(&v3Tangent[0]);
				else
					glTexCoord3fv(&v3PrevTangent[0]);
				glVertex3fv(&v3PrevPoint[0]);

				glTexCoord3fv(&v3Tangent[0]);
				glVertex3fv(&v3Point[0]);
			}
		#else	// MOD-BY-LEETEN 07/05/2010-TO:
		if( 1 == iPointIndex )
			pv4TexCoords.push_back(VECTOR4(v3Tangent[0], v3Tangent[1], v3Tangent[2], 1.0));
		else
			pv4TexCoords.push_back(VECTOR4(v3PrevTangent[0], v3PrevTangent[1], v3PrevTangent[2], 1.0));
		pv4Coords.push_back(VECTOR4(v3PrevPoint[0], v3PrevPoint[1], v3PrevPoint[2], 1.0));
		// ADD-BY-LEETEN 07/07/2010-BEGIN
		pv4Colors.push_back(v4PrevColor);
		// ADD-BY-LEETEN 07/07/2010-END

		pv4TexCoords.push_back(VECTOR4(v3Tangent[0], v3Tangent[1], v3Tangent[2], 1.0));
		pv4Coords.push_back(VECTOR4(v3Point[0], v3Point[1], v3Point[2], 1.0));
		// ADD-BY-LEETEN 07/07/2010-BEGIN
		pv4Colors.push_back(v4Color);
		// ADD-BY-LEETEN 07/07/2010-END
		#endif	// MOD-BY-LEETEN 07/05/2010-END
		liiParticleIterator++;
		iNrOfRenderedParticles++;
	}

	// ADD-BY-LEETEN 07/07/2010-BEGIN
	cColorScheme._MoveToNextPoint();

	v4PrevColor = v4Color;
	// ADD-BY-LEETEN 07/07/2010-END
	v3PrevPoint = v3Point;
	v3PrevTangent = v3Tangent;
}
示例#20
0
void
RenderOBJModelt (struct obj_model_t *mdl, struct mtl_file *mtlfile)
{
  int i, j, k;

  GLfloat ambient[4];
  GLfloat diffuse[4];
  GLfloat specular[4];
  GLfloat shininess[1];

  //if (hasname) {
	  glEnable(GL_LIGHTING);
  //}
  //printf("%d\n", mdl->num_faces);
  for (i = 0; i < mdl->num_faces; ++i)
  {
	  if(isalpha(mdl->faces[i].mat[0])) {

	  ///printf("====== material name %s =====\n", mdl->faces[i].mat);
	  
	//if(mdl->faces[i].matindex+1 == i) {
		for(k=0; k<mtlfile->materials;k++) {
			if(!strcmp(mtlfile->mtl[k].name, mdl->faces[i].mat)){
				//printf("====== material name %s =====\n", mtlfile->mtl[k].name);
				ambient[0] = mtlfile->mtl[k].ka[0];
				ambient[1] = mtlfile->mtl[k].ka[1];
				ambient[2] = mtlfile->mtl[k].ka[2];
				ambient[3] = mtlfile->mtl[k].ni;

				diffuse[0] = mtlfile->mtl[k].kd[0];
				diffuse[1] = mtlfile->mtl[k].kd[1];
				diffuse[2] = mtlfile->mtl[k].kd[2];
				diffuse[3] = mtlfile->mtl[k].ni;

				specular[0] = mtlfile->mtl[k].ks[0];
				specular[1] = mtlfile->mtl[k].ks[1];
				specular[2] = mtlfile->mtl[k].ks[2];
				specular[3] = mtlfile->mtl[k].ni;

				shininess[0] = mtlfile->mtl[k].d;
				glMaterialfv(GL_FRONT, GL_AMBIENT, ambient);
				glMaterialfv(GL_FRONT, GL_DIFFUSE, diffuse);
				glMaterialfv(GL_FRONT, GL_SPECULAR, specular);
				glMaterialfv(GL_FRONT, GL_SHININESS, shininess);

			}
		}
	  }
		

	//}
        
    glBegin (mdl->faces[i].type);
	for (j = 0; j < mdl->faces[i].num_elems; ++j)
	{
		/*printf("test4 %d\n", mdl->texCoords[mdl->faces[i].uvw_indices[j]].uvw);
		if (i==100) {
			printf("test4 %d\n", mdl->texCoords[mdl->faces[i].uvw_indices[j]].uvw);

		}*/
		/*printf("i=%d j=%d %d/", i, j, mdl->faces[i].vert_indices[j]);
		printf("%d/", mdl->faces[i].uvw_indices[j]);
		printf("%d\n", mdl->faces[i].norm_indices[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();
    }
	//glDisable(GL_COLOR_MATERIAL);

	//if (hasname) {
	  glDisable(GL_LIGHTING);
    //}
  /*printf ("mtl results 222222222222: read\n");
  printf ("   * %s name\n", mtlfile->mtl[0].name);
  printf ("   * %f ns\n", mtlfile->mtl[0].ns);
  printf ("   * %f %f %f ka\n", mtlfile->mtl[0].ka[0], mtlfile->mtl[0].ka[1], mtlfile->mtl[0].ka[2]);
  printf ("   * %f %f %f kd\n", mtlfile->mtl[0].kd[0], mtlfile->mtl[0].kd[1], mtlfile->mtl[0].kd[2]);
  printf ("   * %f %f %f ks\n", mtlfile->mtl[0].ks[0], mtlfile->mtl[0].ks[1], mtlfile->mtl[0].ks[2]);
  printf ("   * %f ni\n", mtlfile->mtl[0].ni);*/
}
示例#21
0
M(void, glTexCoord3fv, jobject v) {
	glTexCoord3fv(BUFF(GLfloat, v));
}
示例#22
0
void drawParticles(std::list<Particle> &drawList, GLuint texture)
{

    static float overTime = 0.0;
    int particlesToEmit = particles_per_Second * t + overTime;
    overTime += particles_per_Second * t - particlesToEmit;


    glBindTexture(GL_TEXTURE_2D, texture);
    glTexEnvi(GL_POINT_SPRITE, GL_COORD_REPLACE, GL_TRUE);


    for(std::list<Particle>::iterator it = drawList.begin(); it != drawList.end(); ++it)
    {
        //update and draw particles if alive
        if(it->isAlive)
        {

            it->t += t;
            if(it->t > it->lifeTime)
                it->isAlive = false;


            glPointSize(10.0 * (it->lifeTime - it->t) / it->lifeTime + 0.1);

            glColor4f(1 - (it->lifeTime - it->t) / it->lifeTime,
                      1-(it->lifeTime - it->t) / it->lifeTime
                      ,1.0f, 1.0);
            glBegin(GL_POINTS);

            glVertex3f( it->position[0] + it->t * it->velocity[0],
                        it->position[1] + it->t * it->velocity[1] - 0.5 * 9.81 * it->t * it->t,
                        it->position[2] + it->t * it->velocity[2]);

            glEnd();

        }
        //revive particle if necessary
        else if(particlesToEmit > 0)
        {
            --particlesToEmit;
            it->isAlive = true;
            it->t = 0;
            it->lifeTime = myRand(1.5,2.5);

            it->position[0] = myRand(-0.5,0.5);
            it->position[1] = 0;
            it->position[2] = myRand(-0.5,0.5);

            it->velocity[0] = myRand(-2, 2);
            it->velocity[1] = myRand(5.0,10.0);
            it->velocity[2] = myRand(-2, 2);

            cgGLEnableTextureParameter(cg_parameter_vertex_velocity);
            glVertex2f(0.0f, 0.0f);
            glTexCoord3fv(it->velocity);
            cgGLDisableTextureParameter(cg_parameter_vertex_velocity);

        }
    }
    //create new particles if necessary
    for(int i = 0; i < particlesToEmit; ++i)
    {
        Particle neu;

        neu.isAlive = true;
        neu.t = 0;
        neu.lifeTime = myRand(1.5,2.5);

        neu.position[0] = myRand(-0.5,0.5);
        neu.position[1] = 0;
        neu.position[2] = myRand(-0.5, 0.5);

        neu.velocity[0] = myRand(-2, 2);
        neu.velocity[1] = myRand(5.0,10.0);
        neu.velocity[2] = myRand(-2, 2);

        cgGLEnableTextureParameter(cg_parameter_vertex_velocity);
        glVertex2f(0.0f, 0.0f);
        glTexCoord3fv(neu->velocity);
        cgGLDisableTextureParameter(cg_parameter_vertex_velocity);

        water_list.push_back(neu);
    }

}
示例#23
0
inline void glTexCoord3v( const GLfloat * v )	{ glTexCoord3fv( v ); }
示例#24
0
static void
RandomPrimitive(void)
{
   int i;
   int len = MinVertexCount + RandomInt(MaxVertexCount - MinVertexCount);

   Vprim = RandomInt(10);

   glBegin(Vprim);
   Vbuffer[Vcount].type = BEGIN;
   Vbuffer[Vcount].v[0] = Vprim;
   Vcount++;

   for (i = 0; i < len; i++) {
      Vbuffer[Vcount].v[0] = RandomFloat(-3, 3);
      Vbuffer[Vcount].v[1] = RandomFloat(-3, 3);
      Vbuffer[Vcount].v[2] = RandomFloat(-3, 3);
      Vbuffer[Vcount].v[3] = RandomFloat(-3, 3);
      int k = RandomInt(9);
      switch (k) {
      case 0:
         glVertex2fv(Vbuffer[Vcount].v);
         Vbuffer[Vcount].type = VERTEX2;
         break;
      case 1:
         glVertex3fv(Vbuffer[Vcount].v);
         Vbuffer[Vcount].type = VERTEX3;
         break;
      case 2:
         glVertex4fv(Vbuffer[Vcount].v);
         Vbuffer[Vcount].type = VERTEX4;
         break;
      case 3:
         glColor3fv(Vbuffer[Vcount].v);
         Vbuffer[Vcount].type = COLOR3;
         break;
      case 4:
         glColor4fv(Vbuffer[Vcount].v);
         Vbuffer[Vcount].type = COLOR4;
         break;
      case 5:
         glTexCoord2fv(Vbuffer[Vcount].v);
         Vbuffer[Vcount].type = TEX2;
         break;
      case 6:
         glTexCoord3fv(Vbuffer[Vcount].v);
         Vbuffer[Vcount].type = TEX3;
         break;
      case 7:
         glTexCoord4fv(Vbuffer[Vcount].v);
         Vbuffer[Vcount].type = TEX4;
         break;
      case 8:
         glSecondaryColor3fv(Vbuffer[Vcount].v);
         Vbuffer[Vcount].type = SECCOLOR3;
         break;
      case 9:
         glNormal3fv(Vbuffer[Vcount].v);
         Vbuffer[Vcount].type = NORMAL3;
         break;
      default:
         abort();
      }
      Vcount++;

      if (Vcount >= BufferSize - 2) {
         /* reset */
         Vcount = 0;
      }
   }

   Vbuffer[Vcount++].type = END;

   glEnd();
}
示例#25
0
文件: api_eval.c 项目: aosm/X11
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 MultiplanarSliceRenderer::renderSlice(SliceAlignment sliceAlign, int sliceNo, tgt::TextureUnit& texUnit) {

    tgtAssert(inport_.hasData(), "No volume");
    const VolumeBase* volume =  inport_.getData();
    tgt::ivec3 volDim = volume->getDimensions();
    tgt::vec3 textureSize = volume->getCubeSize();

    tgt::vec3 dim = static_cast<tgt::vec3>(volDim - tgt::ivec3(1));
    tgt::vec3 llb = volume->getLLF();

    tgt::ivec3 permutation(0, 1, 2);
    switch (sliceAlign) {
        default:
        case SLICE_XY:
            break;
        case SLICE_XZ:
            permutation = tgt::ivec3(0, 2, 1);
            break;
        case SLICE_YZ:
            permutation = tgt::ivec3(2, 1, 0);
            break;
    }
    float s = tgt::clamp(sliceNo / (dim[permutation.z]-1), 0.f, 1.f);

    tgt::vec3 ll = permuteComponents(tgt::vec3(0.f, 0.f, s), permutation);
    tgt::vec3 lr = permuteComponents(tgt::vec3(1.f, 0.f, s), permutation);
    tgt::vec3 ur = permuteComponents(tgt::vec3(1.f, 1.f, s), permutation);
    tgt::vec3 ul = permuteComponents(tgt::vec3(0.f, 1.f, s), permutation);

    if (texMode_.isSelected("2d-texture")) {
        tgt::vec3 texLowerLeft = ll;//(textureMatrix_*ll).xyz();
        tgt::vec3 texUpperRight = ur;//(textureMatrix_*ur).xyz();

        tgt::Texture* sliceTexture = generateAlignedSliceTexture(inport_.getData(), texLowerLeft, texUpperRight);
        if (sliceTexture) {
            bindSliceTexture(sliceShader_, inport_.getData(), sliceTexture, &texUnit);
            LGL_ERROR;

            sliceShader_->setUniform("textureMatrix_", tgt::mat4::identity);
            glBegin(GL_QUADS);

            glTexCoord2f(0.f, 0.f);
            glVertex3fv( ((ll * textureSize) + llb).elem );

            if (sliceAlign == SLICE_YZ)
                glTexCoord2f(0.f, 1.f);
            else
                glTexCoord2f(1.f, 0.f);
            glVertex3fv( ((lr * textureSize) + llb).elem );

            glTexCoord2f(1.f, 1.f);
            glVertex3fv( ((ur * textureSize) + llb).elem );

            if (sliceAlign == SLICE_YZ)
                glTexCoord2f(1.f, 0.f);
            else
                glTexCoord2f(0.f, 1.f);
            glVertex3fv( ((ul * textureSize) + llb).elem );

            glEnd();
            delete sliceTexture;

            LGL_ERROR;
        }
    }
    else if (texMode_.isSelected("3d-texture")) {

        glBegin(GL_QUADS);
            glTexCoord3fv(ll.elem);
            glVertex3fv( ((ll * textureSize) + llb).elem );

            glTexCoord3fv(lr.elem);
            glVertex3fv( ((lr * textureSize) + llb).elem );

            glTexCoord3fv(ur.elem);
            glVertex3fv( ((ur * textureSize) + llb).elem );

            glTexCoord3fv(ul.elem);
            glVertex3fv( ((ul * textureSize) + llb).elem );
        glEnd();
    }
}
示例#27
0
文件: api_eval.c 项目: aosm/X11
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 );
   }
}
示例#28
0
static GLboolean
draw_at_size(int size, int x_offset, int y_offset, GLboolean mipmapped)
{
	GLfloat row_y = PAD + y_offset;
	int dim, face;
	int color = 0, level = 0, maxlevel, baselevel = 3;
	GLuint texname;
	GLboolean pass = GL_TRUE;
	GLint loc;
	
	glUseProgram(program_cube);
	loc = glGetUniformLocation(program_cube, "tex");
	glUniform1i(loc, 0); /* texture unit p */

	/* Create the texture. */
	glGenTextures(1, &texname);
	glBindTexture(GL_TEXTURE_CUBE_MAP_ARB, texname);

	/* For each face drawing, we want to only see that face's contents at
	 * that mipmap level.
	 */
	if (mipmapped) {
		glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB,
				GL_TEXTURE_MIN_FILTER,
				GL_NEAREST_MIPMAP_NEAREST);
	} else {
		glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB,
				GL_TEXTURE_MIN_FILTER,
				GL_NEAREST);
	}
	glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB,
			GL_TEXTURE_MAG_FILTER, GL_NEAREST);
	glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB,
			GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
	glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB,
			GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

	/* Fill in faces on each level */
	for (dim = size; dim > 0; dim /= 2) {
		if (test_state != STATE_PLAIN_SHADER)
			color = (level) % ARRAY_SIZE(colors);
		for (face = 0; face < 6; face++) {
			set_face_image(level, cube_face_targets[face],
				       dim, color);
			if (test_state == STATE_PLAIN_SHADER)
				color = (color + 1) % ARRAY_SIZE(colors);
		}
		if (!mipmapped)
			break;

		level++;
	}
	maxlevel = level;
	if (maxlevel >= ARRAY_SIZE(colors))
		maxlevel = ARRAY_SIZE(colors) - 1;

	glEnable(GL_TEXTURE_CUBE_MAP_ARB);

	color = 0;
	level = 0;
	if (test_state == STATE_LOD_BIAS_SHADER)
		level = baselevel;
	for (dim = size; dim > 0; dim /= 2) {
		GLfloat row_x = PAD + x_offset;

		if (test_state == STATE_LOD_SHADER)
			level = baselevel;

		for (face = 0; face < 6; face++) {
			GLfloat base_x = row_x + face * (max_size + PAD);
			GLfloat base_y = row_y;
			
			if (test_state != STATE_PLAIN_SHADER) {
				color = level;
				if (color >= ARRAY_SIZE(colors))
					color = ARRAY_SIZE(colors) - 1;
			}
			glBegin(GL_QUADS);

			glTexCoord3fv(cube_face_texcoords[face][0]);
			glVertex2f(base_x, base_y);

			glTexCoord3fv(cube_face_texcoords[face][1]);
			glVertex2f(base_x + dim, base_y);

			glTexCoord3fv(cube_face_texcoords[face][2]);
			glVertex2f(base_x + dim, base_y + dim);

			glTexCoord3fv(cube_face_texcoords[face][3]);
			glVertex2f(base_x, base_y + dim);

			glEnd();

			if (dim > 2) {
				pass = test_results(base_x, base_y,
						    dim, level, face,
						    mipmapped,
						    color, maxlevel) && pass;
			}

			if (test_state == STATE_PLAIN_SHADER)
				color = (color + 1) % ARRAY_SIZE(colors);
		}

		if (!mipmapped)
			break;

		row_y += dim + PAD;
		level++;
		if (test_state != STATE_PLAIN_SHADER)
			if (level > maxlevel)
				level = maxlevel;
	}

	glUseProgram(0);
	glDeleteTextures(1, &texname);

	return pass;
}
void PolygonBackground::clear(DrawEnv *pEnv)
{
#if !defined(OSG_OGL_COREONLY) || defined(OSG_CHECK_COREONLY)
    if(pEnv->getPixelWidth()  == 0 ||
       pEnv->getPixelHeight() == 0 )
    {
        FWARNING(("Port has zero size: nothing to render to!\n"));
        return;
    }

    if(getMFPositions()->size() == 0 ||
       getMFPositions()->size() != getMFTexCoords()->size())
    {
        FWARNING(("PolygonBackground::clear: positions and texcoords have "
                  "different/ invalid sizes (%d vs. %d)!\n",
                  getMFPositions()->size(), getMFTexCoords()->size()));
        return;
    }

    Int32 bit = getClearStencilBit();      // 0x0

    if(bit >= 0)
    {
        glClearStencil(bit);

        glClear(GL_COLOR_BUFFER_BIT |
                GL_DEPTH_BUFFER_BIT |
                GL_STENCIL_BUFFER_BIT);
    }
    else
    {
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    }

    glPushAttrib(GL_ALL_ATTRIB_BITS);

    glDisable(GL_DEPTH_TEST);
    glDepthFunc(GL_ALWAYS);

    if(getCleanup())
        glDepthMask(GL_FALSE);

    Real32 aspectX = 1.0f, aspectY = 1.0f;

    if(getAspectHeight() != 0 && getAspectWidth() != 0)
    {
        aspectX = (Real32(pEnv->getPixelHeight()) / getAspectHeight()) /
                  (Real32(pEnv->getPixelWidth ()) / getAspectWidth ());
    }

    Real32 sFac        = getScale() > 0 ? getScale() : 1.0f;
    UInt32 fullWidth;
    UInt32 fullHeight;

    if(!getTile())
    {
        beginOrthoRender(pEnv, getNormalizedX(), getNormalizedY(),
                               fullWidth,        fullHeight       );

        Real32 t = 0;

        if(getAspectHeight() != 0 && getAspectWidth() != 0 &&
           fullHeight        != 0 && fullHeight       != 0   )
        {
            aspectX = (Real32(fullHeight) / getAspectHeight()) /
                      (Real32(fullWidth ) / getAspectWidth ());

            t  = Real32(fullWidth) * (1.0f - aspectX) * 0.5f;
            t *= Real32(pEnv->getPixelWidth()) / fullWidth;
        }

        glTranslatef(t,       0.0f,    0.0f);
        glScalef    (aspectX, aspectY, 1.0f);

        Real32 tW = (1.0f - sFac) * 0.5f * Real32(pEnv->getPixelWidth ());
        Real32 tH = (1.0f - sFac) * 0.5f * Real32(pEnv->getPixelHeight());

        glTranslatef(tW,   tH,   0.0f);
        glScalef    (sFac, sFac, 1.0f);
    }
    else
    {
        glScalef(sFac,    sFac,    1.0f);
        glScalef(aspectX, aspectY, 1.0f);

        beginOrthoRender(pEnv, getNormalizedX(), getNormalizedY(),
                               fullWidth,        fullHeight       );
    }


    getMaterial()->getState()->activate(pEnv);

    const Vec3f *tc  = &getMFTexCoords()->front();
    const Pnt2f *pos = &getMFPositions()->front();

    glBegin(GL_POLYGON);

    for (UInt16 i=0; i < getMFPositions()->size(); i++)
    {
        glTexCoord3fv( tc[i].getValues());
        glVertex2fv  (pos[i].getValues());
    }

    glEnd();

    getMaterial()->getState()->deactivate(pEnv);

    glScalef(1, 1, 1);

    if(getCleanup())
    {
        if(bit >= 0)
        {
            glClear(GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
        }
        else
        {
            glClear(GL_DEPTH_BUFFER_BIT);
        }
    }

    endOrthoRender(pEnv);

    glPopAttrib();
#endif
}