Beispiel #1
0
/**********************************************************************
 * FlatShadeStripCB:
 **********************************************************************/
void 
FlatShadeStripCB::faceCB(CBvert* v, CBface* f) 
{
   // normal
   glNormal3dv(f->norm().data());

   if (v->has_color()) {
      GL_COL(v->color(), alpha*v->alpha());
   }

   // texture coords
   if (_do_texcoords) {
      if (_use_auto) { //force automatic 
         //use spherical text coord gen
         glTexCoord2dv(_auto_UV->uv_from_vert(v,f).data());
      } else {
         // the patch has a texture... try to find
         // appropriate texture coordinates...

         // use patch's TexCoordGen if possible,
         // otherwise use the texture coordinates stored
         // on the face (if any):
         TexCoordGen* tg = f->patch()->tex_coord_gen();
         if (tg)
            glTexCoord2dv(tg->uv_from_vert(v,f).data());
         else if (UVdata::lookup(f))
            glTexCoord2dv(UVdata::get_uv(v,f).data());
      }
   }
  
   // vertex coords
   glVertex3dv(v->loc().data());
}
Beispiel #2
0
void Triangle::render() const
{
    bool materials_nonnull = true;
    for ( int i = 0; i < 3; ++i )
        materials_nonnull = materials_nonnull && vertices[i].material;

    // this doesn't interpolate materials. Ah well.
    if ( materials_nonnull )
        vertices[0].material->set_gl_state();

    glBegin(GL_TRIANGLES);

    glNormal3dv( &vertices[0].normal.x );
    glTexCoord2dv( &vertices[0].tex_coord.x );
    glVertex3dv( &vertices[0].position.x );

    glNormal3dv( &vertices[1].normal.x );
    glTexCoord2dv( &vertices[1].tex_coord.x );
    glVertex3dv( &vertices[1].position.x);

    glNormal3dv( &vertices[2].normal.x );
    glTexCoord2dv( &vertices[2].tex_coord.x );
    glVertex3dv( &vertices[2].position.x);

    glEnd();

    if ( materials_nonnull )
        vertices[0].material->reset_gl_state();
}
void display(void)
{
    double polygon[][3] = {
      0, 0, 0,
      10, 0, 0,
      10, 6, 0,
      5, 10, 0,
      0, 6, 0
    };

    double text[][2] = {
      0, 0,
      1.0, 0,
      1.0, .6,
      .5, 1.0,
      0, .6
    };

    glMatrixMode(GL_TEXTURE);
    glLoadIdentity();
    glRotated(45, 0, 0, 1);
    glScaled(1.75,1.75,1.75);
    glMatrixMode(GL_MODELVIEW);

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glBegin(GL_POLYGON);
      glTexCoord2dv(text[0]); glVertex3dv(polygon[0]);
      glTexCoord2dv(text[1]); glVertex3dv(polygon[1]);
      glTexCoord2dv(text[2]); glVertex3dv(polygon[2]);
      glTexCoord2dv(text[3]); glVertex3dv(polygon[3]);
      glTexCoord2dv(text[4]); glVertex3dv(polygon[4]);
    glEnd();
    glutSwapBuffers();
}
Beispiel #4
0
void Mesh::render(const vec3b& color, bool texturing, bool selected) const {
  bool use_texture = texturing && !tex_coord.empty();

  glEnable(GL_NORMALIZE);
  glEnable(GL_LIGHTING);

  if (use_texture) {
    glEnable(GL_TEXTURE_2D);
    glBindTexture(GL_TEXTURE_2D, texture_id);
  }

  auto& mesh = *this;

  auto triangles = mesh.triangles;
  triangles << top_cover.triangles;
  triangles << bottom_cover.triangles;
  glBegin(GL_TRIANGLES);
  for (auto& tri : triangles) {
    if (selected) glColor3ub(255, 0, 0);
    else if (use_texture) glColor3ub(255, 255, 255);
    else glColor3ubv(color.coords);

    glNormal3dv(tri.normal.coords);
    if (use_texture) glTexCoord2dv(tex(tri[0]).coords);
    glVertex3iv(mesh[tri[0]].coords);

    glNormal3dv(tri.normal.coords);
    if (use_texture) glTexCoord2dv(tex(tri[1]).coords);
    glVertex3iv(mesh[tri[1]].coords);

    glNormal3dv(tri.normal.coords);
    if (use_texture) glTexCoord2dv(tex(tri[2]).coords);
    glVertex3iv(mesh[tri[2]].coords);
  }
  glEnd();

  if (use_texture) {
    glDisable(GL_TEXTURE_2D);
  }

  glDisable(GL_LIGHTING);
  glDisable(GL_NORMALIZE);

#ifndef NDEBUG
  if (selected && use_texture) {
    glLineWidth(5);
    glColor3d(1, 0, 0);
    glBegin(GL_LINE_STRIP);
    for(auto &e: anchor_points) glVertex2iv(e[0].coords);
    glEnd();
    glBegin(GL_LINE_STRIP);
    for (auto &e: anchor_points) glVertex2iv(e[1].coords);
    glEnd();
    glLineWidth(1);
  }
#endif
  glColor3d(1, 1, 1);
}
// Construct the two display lists
void RenderablePicoSurface::createDisplayLists()
{
	// Generate the lists for lighting mode
    _dlProgramNoVCol = compileProgramList(false);
    _dlProgramVcol = compileProgramList(true);

	// Generate the list for flat-shaded (unlit) mode
	_dlRegular = glGenLists(1);
	assert(_dlRegular != 0); // check if we run out of display lists
	glNewList(_dlRegular, GL_COMPILE);

	glBegin(GL_TRIANGLES);
	for (Indices::const_iterator i = _indices.begin();
		 i != _indices.end();
		 ++i)
	{
		// Get the vertex for this index
		ArbitraryMeshVertex& v = _vertices[*i];

		// Submit attributes
		glNormal3dv(v.normal);
		glTexCoord2dv(v.texcoord);
		glVertex3dv(v.vertex);
	}
	glEnd();

	glEndList();
}
Beispiel #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;
    }
}
Beispiel #7
0
static void draw(const Svg* svg)
{
    GLenum nextPrimType, primType = GL_LINE_STRIP;
    const SvgLine* lIt;
    uint i;

    DENG_ASSERT_IN_MAIN_THREAD();
    DENG_ASSERT_GL_CONTEXT_ACTIVE();

    lIt = svg->lines;
    for(i = 0; i < svg->lineCount; ++i, lIt++)
    {
        if(lIt->numPoints != 2)
        {
            nextPrimType = SvgLine_IsLoop(lIt)? GL_LINE_LOOP : GL_LINE_STRIP;

            // Do we need to end the current primitive?
            if(primType == GL_LINES)
            {
                glEnd(); // 2-vertex set ends.
            }

            // A new n-vertex primitive begins.
            glBegin(nextPrimType);
        }
        else
        {
            // Do we need to start a new 2-vertex primitive set?
            if(primType != GL_LINES)
            {
                primType = GL_LINES;
                glBegin(GL_LINES);
            }
        }

        // Write the vertex data.
        if(lIt->head)
        {
            const SvgLinePoint* pIt = lIt->head;
            do
            {
                /// @todo Use TexGen?
                glTexCoord2dv((const GLdouble*)pIt->coords.xy);
                glVertex2dv((const GLdouble*)pIt->coords.xy);
            } while(NULL != (pIt = pIt->next) && pIt != lIt->head);
        }

        if(lIt->numPoints != 2)
        {
            glEnd(); // N-vertex primitive ends.
        }
    }

    if(primType == GL_LINES)
    {
        // Close any remaining open 2-vertex set.
        glEnd();
    }
}
/** Contains the vertex, normal and texture calls  that draw the primitive.
*/
void C3dLine::draw () const
{
	C3dPoint::draw();
	
	glNormal3dv(m_VN1.dv());
	glTexCoord2dv(m_VTex1.dv()); 
	m_V1.vertex();
}
Beispiel #9
0
void Triangle::render() const
{
    bool materials_nonnull = true;
    for ( int i = 0; i < 3; ++i )
        materials_nonnull = materials_nonnull && vertices[i].material;

    // this doesn't interpolate materials. Ah well.
    if ( materials_nonnull )
        vertices[0].material->set_gl_state();

    glBegin(GL_TRIANGLES);
//    glBegin(GL_LINE_LOOP);

    glNormal3dv( &vertices[0].normal.x );
    glTexCoord2dv( &vertices[0].tex_coord.x );
    glVertex3dv( &vertices[0].position.x );

    glNormal3dv( &vertices[1].normal.x );
    glTexCoord2dv( &vertices[1].tex_coord.x );
    glVertex3dv( &vertices[1].position.x);

    glNormal3dv( &vertices[2].normal.x );
    glTexCoord2dv( &vertices[2].tex_coord.x );
    glVertex3dv( &vertices[2].position.x);

    glEnd();

	// 545
/*    glBegin(GL_LINES);
    	const Vertex * v;
    	Vector3 p, n;
		for(int i=0; i<3; i++) {
			v = &vertices[i];
			p = v->position;
			n = v->normal;
			glVertex3f(p.x, p.y, p.z);
			glVertex3f(p.x+n.x, p.y+n.y, p.z+n.z);
		}
    glEnd(); */


    if ( materials_nonnull )
        vertices[0].material->reset_gl_state();
}
Beispiel #10
0
/* Render us using the current color and texture state */
void CkQuadView::render(void) {
#ifdef CMK_LIVEVIZ3D_CLIENT
	c_tex->bind();
	glBegin (nCorners==4?GL_QUADS:GL_TRIANGLE_STRIP);
	for (int i=0;i<nCorners;i++) {
		glTexCoord2dv(texCoord[i]); glVertex3dv(corners[i]); 
	}
	glEnd();
#endif
}
Beispiel #11
0
// Construct the display lists
void MD5Surface::createDisplayLists()
{
    // Release old display lists first
    releaseDisplayLists();

	// Create the list for lighting mode
	_lightingList = glGenLists(1);
	assert(_lightingList != 0);
	glNewList(_lightingList, GL_COMPILE);

	glBegin(GL_TRIANGLES);
	for (Indices::const_iterator i = _indices.begin();
		 i != _indices.end();
		 ++i)
	{
		// Get the vertex for this index
		ArbitraryMeshVertex& v = _vertices[*i];

		// Submit the vertex attributes and coordinate
		if (GLEW_ARB_vertex_program) {
			// Submit the vertex attributes and coordinate
			glVertexAttrib2dvARB(ATTR_TEXCOORD, v.texcoord);
			glVertexAttrib3dvARB(ATTR_TANGENT, v.tangent);
			glVertexAttrib3dvARB(ATTR_BITANGENT, v.bitangent);
			glVertexAttrib3dvARB(ATTR_NORMAL, v.normal);
		}
		glVertex3dv(v.vertex);
	}
	glEnd();

	glEndList();

	// Generate the list for flat-shaded (unlit) mode
	_normalList = glGenLists(1);
	assert(_normalList != 0);
	glNewList(_normalList, GL_COMPILE);

	glBegin(GL_TRIANGLES);
	for (Indices::const_iterator i = _indices.begin();
		 i != _indices.end();
		 ++i)
	{
		// Get the vertex for this index
		ArbitraryMeshVertex& v = _vertices[*i];

		// Submit attributes
		glNormal3dv(v.normal);
		glTexCoord2dv(v.texcoord);
		glVertex3dv(v.vertex);
	}
	glEnd();

	glEndList();
}
void draw_tex_font_char( tex_font_metrics_t *tfm, char c )
{
    tfm_char_data_t *cd;

    cd = find_char_data( tfm, c );

    glBegin( GL_QUADS );
    {
	glTexCoord2dv( (scalar_t*) &cd->tex_ll );
	glVertex2dv(   (scalar_t*) &cd->ll     );
	glTexCoord2dv( (scalar_t*) &cd->tex_lr );
	glVertex2dv(   (scalar_t*) &cd->lr     );
	glTexCoord2dv( (scalar_t*) &cd->tex_ur );
	glVertex2dv(   (scalar_t*) &cd->ur     );
	glTexCoord2dv( (scalar_t*) &cd->tex_ul );
	glVertex2dv(   (scalar_t*) &cd->ul     );
    }
    glEnd();

    glTranslatef( cd->kern_width, 0., 0. );
}
Beispiel #13
0
void __glXDisp_TexCoord2dv(GLbyte *pc)
{

#ifdef __GLX_ALIGN64
	if ((unsigned long)(pc) & 7) {
	    __GLX_MEM_COPY(pc-4, pc, 16);
	    pc -= 4;
	}
#endif
	glTexCoord2dv( 
		(GLdouble *)(pc + 0)
	);
}
Beispiel #14
0
/*
** 箱の描画
*/
void box(double x, double y, double z)
{
  /* 頂点の座標値 */
  const GLdouble vertex[][4][3] = {
    {{ -x, -y, -z }, {  x, -y, -z }, {  x, -y,  z }, { -x, -y,  z }},
    {{ -x, -y, -z }, { -x,  y, -z }, {  x,  y, -z }, {  x, -y, -z }},
    {{  x, -y, -z }, {  x,  y, -z }, {  x,  y,  z }, {  x, -y,  z }},
    {{  x, -y,  z }, {  x,  y,  z }, { -x,  y,  z }, { -x, -y,  z }},
    {{ -x, -y,  z }, { -x,  y,  z }, { -x,  y, -z }, { -x, -y, -z }},
    {{ -x,  y,  z }, {  x,  y,  z }, {  x,  y, -z }, { -x,  y, -z }},
  };
  
  /* 頂点のテクスチャ座標 */
  static const GLdouble texcoord[][4][2] = {
    {{ 0.0, 0.0 }, { 0.0, 1.0 }, { 1.0, 1.0 }, { 1.0, 0.0 }},
    {{ 0.0, 0.0 }, { 0.0, 1.0 }, { 1.0, 1.0 }, { 1.0, 0.0 }},
    {{ 0.0, 0.0 }, { 0.0, 1.0 }, { 1.0, 1.0 }, { 1.0, 0.0 }},
    {{ 0.0, 0.0 }, { 0.0, 1.0 }, { 1.0, 1.0 }, { 1.0, 0.0 }},
    {{ 0.0, 0.0 }, { 0.0, 1.0 }, { 1.0, 1.0 }, { 1.0, 0.0 }},
    {{ 0.0, 0.0 }, { 0.0, 1.0 }, { 1.0, 1.0 }, { 1.0, 0.0 }},
  };
  
  /* 面の法線ベクトル */
  static const GLdouble normal[][3] = {
    {  0.0, -1.0,  0.0 },
    {  0.0,  0.0, -1.0 },
    {  1.0,  0.0,  0.0 },
    {  0.0,  0.0,  1.0 },
    { -1.0,  0.0,  0.0 },
    {  0.0,  1.0,  0.0 },
  };

  int i, j;
  
  /* 四角形6枚で箱を描く */
  glBegin(GL_QUADS);
  for (j = 0; j < 6; ++j) {
    glNormal3dv(normal[j]);
    for (i = 0; i < 4; ++i) {
      /* テクスチャ座標の指定 */
      glTexCoord2dv(texcoord[j][i]);
      /* 対応する頂点座標の指定 */
      glVertex3dv(vertex[j][i]);
    }
  }
  glEnd();
}
   //******** TRI STRIPS ********
   virtual void faceCB(CBvert* v, CBface* f) {
  
      assert(v && f);
      
	  glNormal3dv(f->norm().data());

	  if (v->has_color()) 
	  {
			GL_COL(v->color(), alpha*v->alpha());
	  }
	   

	 //pass texture coordinates to opengl
	  glTexCoord2dv(att_function->get_attrib(v,f).data());

	  send_d(v,f);
	 
   
      glVertex3dv(v->loc().data());     // vertex coordinates
   }
Beispiel #16
0
	void	model::render()
	{
	  // default material setup
	  glBindTexture(GL_TEXTURE_2D, 0);

	  glPushMatrix();
	  setModelview();
	  glBegin(GL_TRIANGLES);
	  std::list<materialAssoc>::const_iterator materialIdx = _renderMap.begin();
	  idx3d k = 0;
	  for (std::list<mesh>::const_iterator i = _mesh.begin(); i != _mesh.end();)
	    {
	      if (materialIdx != _renderMap.end())
		{
		  if (k == (*materialIdx).startIndex)
		    {
		      (*materialIdx).material->setup();
		      materialIdx++;
		    }
		}
	      
	      //glBegin(GL_LINE_STRIP);
	      for (unsigned char j = 0; j < 3 && i != _mesh.end(); j++)
		{
		  //glColor3dv(color[j]);
		  glVertex3dv(&i->vertex.x);
		  //glNormal3dv(&i->normal.x);
		  glTexCoord2dv(&i->texture.x);
		  i++;
		}
	      //glEnd();
	      k++;
	    }
	  glEnd();
	  glPopMatrix();
	}
inline void glTexCoord2v( const GLdouble * v )	{ glTexCoord2dv( v ); }
void DrawParabolicMapWithSphere()
{
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  glOrtho(-width, width, -height, height, -100000, 100000);
  gluLookAt(0, 0, 1, 0, 0, 0, 0, -1, 0);
  glViewport(0, 0, width * 2, height * 2);
  glScissor(0, 0, width * 2, height * 2);
  glClearColor(1,1,1, 1);
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

  double showMapPoints[LOD+1][LOD+1][2];
  double showMapTexCoords[LOD+1][LOD+1][2];

  for (int i = 0; i <= LOD; i++)
  {
    float x = i * 1.0 / LOD;
    for (int j = 0; j <= LOD; j++)
    {
      float y = j * 1.0 / LOD;
      showMapPoints[i][j][0] = x * width;
      showMapPoints[i][j][1] = y * height;


      float parabolic_x, parabolic_y, parabolic_z;


      // float parabolic_x = ((mapped.x / (2 * (1 + mapped.z))) + 0.5) / 2;
      // float parabolic_y = (-mapped.y / (2 * (1 + mapped.z))) + 0.5;
      // float parabolic_z = (1 - parabolic_x * parabolic_x + parabolic_y * parabolic_y) / 2;
      if (i < LOD / 2) {
        parabolic_x = (2 * x - 0.5) * 2;
        parabolic_y = -(2 * y - 1);
        parabolic_z = (1 - (parabolic_x * parabolic_x + parabolic_y * parabolic_y)) / 2;
      } else {
        parabolic_x = (2 * (x - 0.5) - 0.5) * 2;
        parabolic_y = -(2 * y - 1);
        parabolic_z = -(1 - (parabolic_x * parabolic_x + parabolic_y * parabolic_y)) / 2;
      }
      // printf("para : %f, %f, %f\n",parabolic_x, parabolic_y, parabolic_z);

      Vector3d mapped = Vector3d(parabolic_x, parabolic_y, parabolic_z);
      mapped.normalize();

      double sum = sqrt(mapped.x*mapped.x + mapped.y*mapped.y + pow(mapped.z+1,2));
      showMapTexCoords[i][j][0] = (mapped.x/sum + 1) / 2;
      showMapTexCoords[i][j][1] = (-mapped.y/sum + 1) / 2;

      // showMapTexCoords[i][j][0] = x;
      // showMapTexCoords[i][j][1] = y;
    }
  }

  glEnable(GL_TEXTURE_2D);
  for (int i = 0; i < LOD; i++)
  {
    glBegin(GL_QUAD_STRIP);
    for (int j = 0; j < LOD; j++)
    {
      glTexCoord2dv(showMapTexCoords[i][j]);
      glVertex2dv(showMapPoints[i][j]);
      glTexCoord2dv(showMapTexCoords[i + 1][j]);
      glVertex2dv(showMapPoints[i + 1][j]);
    }
    glEnd();
  }
  glDisable(GL_TEXTURE_2D);
  return;
}
Beispiel #19
0
void APIENTRY
glu_vertex(GLdouble *xyz)  /* I - XYZ location + ST texture coordinate */
    {
    glTexCoord2dv(xyz + 3);
    glVertex3dv(xyz);
    }
Beispiel #20
0
void texture2(const Point &p)
{
    glTexCoord2dv(p.v);
}
Beispiel #21
0
template< > inline void glTexCoord2v< Vector3r >	( const Vector3r v )		{	glTexCoord2dv((double*)&v);	};
Beispiel #22
0
/////////////////////////////////////////////////////////
// Render
//
void GEMglTexCoord2dv :: render(GemState *state) {
	glTexCoord2dv (v);
}
PsychError SCREENDontCopyWindow(void) 
{
	PsychRectType			sourceRect, targetRect, targetRectInverted;
	PsychWindowRecordType	*sourceWin, *targetWin;
	GLdouble				sourceVertex[2], targetVertex[2]; 
	double  t1,t2;
	double					sourceRectWidth, sourceRectHeight;
        
    
    
	//all sub functions should have these two lines
	PsychPushHelp(useString, synopsisString, seeAlsoString);
	if(PsychIsGiveHelp()){PsychGiveHelp();return(PsychError_none);};

	//cap the number of inputs
	PsychErrorExit(PsychCapNumInputArgs(5));   //The maximum number of inputs
	PsychErrorExit(PsychCapNumOutputArgs(0));  //The maximum number of outputs
        
	//get parameters for the source window:
	PsychAllocInWindowRecordArg(1, TRUE, &sourceWin);
	PsychCopyRect(sourceRect, sourceWin->rect);
	PsychCopyInRectArg(3, FALSE, sourceRect);

	//get paramters for the target window:
	PsychAllocInWindowRecordArg(2, TRUE, &targetWin);
	PsychCopyRect(targetRect, targetWin->rect);
	PsychCopyInRectArg(4, FALSE, targetRect);

	//Check that the windows agree in depth.  They don't have to agree in format because we convert to the correct format for the target when we 
	//create the texture.
	if(sourceWin->depth != targetWin->depth)
		PsychErrorExitMsg(PsychError_user, "Source and target windows must have the same bit depth");
            
	//We need to unbind the source window texture from any previous target contexts if it is bound.  There can be only one binding at a time.
	//We could augment the Psychtoolbox to support shared contexts and multiple bindings.
	PsychRetargetWindowToWindow(sourceWin, targetWin);
		
		
	//each of these next three commands makes changes only when neccessary, they can be called generously 
	//when there is a possibility that any are necessary.
	  
	//PsychGetPrecisionTimerSeconds(&t1);
	PsychAllocateTexture(sourceWin);
	PsychBindTexture(sourceWin);
	PsychUpdateTexture(sourceWin);
	//PsychGetPrecisionTimerSeconds(&t2);
	//mexPrintf("texture checking copywindow took %f seconds\n", t2-t1);

	//PsychGetPrecisionTimerSeconds(&t1);
	PsychGetPrecisionTimerSeconds(&t1);
	PsychSetGLContext(targetWin);
	
	glBindTexture(GL_TEXTURE_RECTANGLE_EXT, sourceWin->glTexture);
	sourceRectWidth= PsychGetWidthFromRect(sourceWin->rect);
	sourceRectHeight= PsychGetHeightFromRect(sourceWin->rect);
	glTexSubImage2D(GL_TEXTURE_RECTANGLE_EXT, 0, 0, 0, (GLsizei)sourceRectWidth, (GLsizei)sourceRectHeight, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, sourceWin->textureMemory);
	
	PsychInvertRectY(targetRectInverted, targetRect, targetWin->rect);
	//PsychGetPrecisionTimerSeconds(&t1);
	targetVertex[0]=0;
	targetVertex[1]=0;
    glBegin(GL_QUADS);
		glTexCoord2dv(PsychExtractQuadVertexFromRect(sourceRect, 0, sourceVertex));
		glVertex2dv(targetVertex);
		
		glTexCoord2dv(PsychExtractQuadVertexFromRect(sourceRect, 1, sourceVertex));
		glVertex2dv(targetVertex);

		glTexCoord2dv(PsychExtractQuadVertexFromRect(sourceRect, 2, sourceVertex));
		glVertex2dv(targetVertex);

		glTexCoord2dv(PsychExtractQuadVertexFromRect(sourceRect, 3, sourceVertex));
		glVertex2dv(targetVertex);
    glEnd();
    glFinish();
	//PsychGetPrecisionTimerSeconds(&t2);
	//mexPrintf("copywindow took %f seconds\n", t2-t1);



	return(PsychError_none);
}
void DrawParabolicMapWithCube()
{
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  glOrtho(-width, width, -height, height, -100000, 100000);
  gluLookAt(0, 0, 1, 0, 0, 0, 0, -1, 0);
  glViewport(0, 0, width * 2, height * 2);
  glScissor(0, 0, width * 2, height * 2);
  glClearColor(1,1,1, 1);
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

  double showMapPoints[LOD+1][LOD+1][2];
  double showMapTexCoords[LOD+1][LOD+1][2];

  for (int i = 0; i <= LOD; i++)
  {
    float x = i * 1.0 / LOD;
    for (int j = 0; j <= LOD; j++)
    {
      float y = j * 1.0 / LOD;
      showMapPoints[i][j][0] = x * width;
      showMapPoints[i][j][1] = y * height;


      float parabolic_x, parabolic_y, parabolic_z;


      // float parabolic_x = ((mapped.x / (2 * (1 + mapped.z))) + 0.5) / 2;
      // float parabolic_y = (-mapped.y / (2 * (1 + mapped.z))) + 0.5;
      // float parabolic_z = (1 - parabolic_x * parabolic_x + parabolic_y * parabolic_y) / 2;
      if (i < LOD / 2) {
        parabolic_x = (2 * x - 0.5) * 2;
        parabolic_y = -(2 * y - 1);
        parabolic_z = (1 - (parabolic_x * parabolic_x + parabolic_y * parabolic_y)) / 2;
      } else {
        parabolic_x = (2 * (x - 0.5) - 0.5) * 2;
        parabolic_y = -(2 * y - 1);
        parabolic_z = -(1 - (parabolic_x * parabolic_x + parabolic_y * parabolic_y)) / 2;
      }
      // printf("para : %f, %f, %f\n",parabolic_x, parabolic_y, parabolic_z);

      Vector3d mapped = Vector3d(parabolic_x, parabolic_y, parabolic_z);
      mapped.normalize();

      float padding_y = 1/3.0;
      float padding_x = 1/4.0;
      if (mapped.x >= std::abs(mapped.y) && mapped.x >= std::abs(mapped.z)) { // right
        showMapTexCoords[i][j][0] = (-mapped.z / mapped.x + 1) / 2 / 4 + padding_x * 2;
        showMapTexCoords[i][j][1] = (-mapped.y / mapped.x + 1) / 2 / 3 + padding_y;
      } else if (mapped.y >= std::abs(mapped.x) && mapped.y >= std::abs(mapped.z)) { // top
        showMapTexCoords[i][j][0] = (mapped.x / mapped.y + 1) / 2 / 4 + padding_x;
        showMapTexCoords[i][j][1] = (mapped.z / mapped.y + 1) / 2 / 3;
      } else if (mapped.z >= std::abs(mapped.x) && mapped.z >= std::abs(mapped.y)) { // front
        showMapTexCoords[i][j][0] = (mapped.x / mapped.z + 1) / 2 / 4 + padding_x;
        showMapTexCoords[i][j][1] = (-mapped.y / mapped.z + 1) / 2 / 3 + padding_y;
      } else if (mapped.x <= -std::abs(mapped.y) && mapped.x <= -std::abs(mapped.z)) { // left
        showMapTexCoords[i][j][0] = (-mapped.z / mapped.x + 1) / 2 / 4;
        showMapTexCoords[i][j][1] = (mapped.y / mapped.x + 1) / 2 / 3 + padding_y;
      } else if (mapped.y <= -std::abs(mapped.x) && mapped.y <= -std::abs(mapped.z)) { // bottom
        showMapTexCoords[i][j][0] = (-mapped.x / mapped.y + 1) / 2 / 4 + padding_x;
        showMapTexCoords[i][j][1] = (mapped.z / mapped.y + 1) / 2 / 3 + padding_y * 2;
      } else if (mapped.z <= -std::abs(mapped.x) && mapped.z <= -std::abs(mapped.y)) { // back
        showMapTexCoords[i][j][0] = (mapped.x / mapped.z + 1) / 2 / 4 + padding_x * 3;
        showMapTexCoords[i][j][1] = (mapped.y / mapped.z + 1) / 2 / 3 + padding_y;
      }

      // showMapTexCoords[i][j][0] = x;
      // showMapTexCoords[i][j][1] = y;
    }
  }

  glEnable(GL_TEXTURE_2D);
  for (int i = 0; i < LOD; i++)
  {
    glBegin(GL_QUAD_STRIP);
    for (int j = 0; j < LOD; j++)
    {
      glTexCoord2dv(showMapTexCoords[i][j]);
      glVertex2dv(showMapPoints[i][j]);
      glTexCoord2dv(showMapTexCoords[i + 1][j]);
      glVertex2dv(showMapPoints[i + 1][j]);
    }
    glEnd();
  }
  glDisable(GL_TEXTURE_2D);
  return;
}
inline void glTexCoord(Vector2d const &v)
{
  glTexCoord2dv(v.c);
}
Beispiel #26
0
M(void, glTexCoord2dv, jobject v) {
	glTexCoord2dv(BUFF(GLdouble, v));
}
/**
  Draw the polyhedron.
 */
void PolyhedronGeom::drawGL()
{
  // No tesselation object allocated yet? Then do so once and for all...
  if (tess==0)
  {
    tess = gluNewTess();
    if (tess==0)
      return;
  }

  // Set flag to 0 (i.e. no variables are present so far)
  tess_data_flag = 0;
  PrimVarAccess<vec3d> normals(*this, std::string("N"), NORMAL, 1, std::string("Nfaces"));
  PrimVarAccess<double> texcoords(*this, std::string("st"), FLOAT, 2, std::string("stfaces"));
  PrimVarAccess<vec3d> colors(*this, std::string("Cs"), COLOR, 1, std::string("Csfaces"));
  vec3d* N;
  vec3d* Cs;
  GLfloat glcol[4] = {0,0,0,1};
  double* st;
  vec3d* vertsptr = verts.dataPtr();
  int i,j;
  int nfloats=3;

  // Check which variables has to be passed to the vertex callback
  // (this is the case when mode is > 2)
  if (normals.mode>2)
  {
    tess_data_flag |= 0x01;
    nfloats += 3;
  }
  if (texcoords.mode>2)
  {
    tess_data_flag |= 0x02;
    nfloats += 2;
  }
  if (colors.mode>2)
  {
    tess_data_flag |= 0x04;
    nfloats += 3;
  }

  dataMemManager.setDataSize(nfloats*sizeof(GLdouble));

  gluTessCallback(tess, GLU_TESS_BEGIN, (TessCallback)(&onTessBegin));
  gluTessCallback(tess, GLU_TESS_END, (TessCallback)(&onTessEnd));
  gluTessCallback(tess, GLU_TESS_VERTEX, (TessCallback)(&onTessVertex));
    
  gluTessProperty(tess, GLU_TESS_BOUNDARY_ONLY, GL_FALSE);
  gluTessProperty(tess, GLU_TESS_TOLERANCE, 0);
  gluTessProperty(tess, GLU_TESS_WINDING_RULE, GLU_TESS_WINDING_ODD);

  // Iterate over all polygons...
  for(i=0; i<getNumPolys(); i++)
  {
    dataMemManager.reset();

    // No normals? Then a face normal has to be calculated...
    if (normals.mode==0)
    {
      vec3d Ng;
      computeNormal(i, Ng);
      glNormal3d(Ng.x, Ng.y, Ng.z);      
    }

    // Process uniform variables...
    if (normals.onFace(N))
      glNormal3d(N->x, N->y, N->z);
    if (texcoords.onFace(st))
      glTexCoord2dv(st);
    if (colors.onFace(Cs))
    {
      glcol[0] = GLfloat(Cs->x);
      glcol[1] = GLfloat(Cs->y);
      glcol[2] = GLfloat(Cs->z);
      glMaterialfv(GL_FRONT, GL_DIFFUSE, glcol);
    }

    gluTessBeginPolygon(tess, 0);
    // Iterate over all loops of polygon i...
    for(j=0; j<getNumLoops(i); j++)
    {
      gluTessBeginContour(tess);
      LoopIterator it = loopBegin(i, j);
      LoopIterator itend = loopEnd(i, j);
      vec3d* v;
      for( ; it!=itend; it++)
      {
	int vidx = (*it);
	v = vertsptr + vidx;
	GLdouble* data = (GLdouble*)dataMemManager.newDataPtr();
	GLdouble* p = data+3;
	data[0] = v->x;
	data[1] = v->y;
	data[2] = v->z;
	if (normals.onVertex(vidx, N))
	{
	  p[0] = N->x;
	  p[1] = N->y;
	  p[2] = N->z;
	  p += 3;
	}
	if (texcoords.onVertex(vidx, st))
	{
	  p[0] = st[0];
	  p[1] = st[1];
	  p += 2;
	}
	if (colors.onVertex(vidx, Cs))
	{
	  p[0] = Cs->x;
	  p[1] = Cs->y;
	  p[2] = Cs->z;
	}
	gluTessVertex(tess, data, data);
      }
      gluTessEndContour(tess);
    }
    gluTessEndPolygon(tess);
  }

  /*  for(i=0; i<getNumPolys(); i++)
  {
    for(j=0; j<getNumLoops(i); j++)
    {
      LoopIterator it = loopBegin(i, j);
      LoopIterator itend = loopEnd(i, j);
      vec3d* v;
      glBegin(GL_LINE_LOOP);
      for( ; it!=itend; it++)
      {
	v = vertsptr + (*it);
	glVertex3d(v->x, v->y, v->z);
      }
      glEnd();
    }
    }*/
}
void DrawSurface()
{
  for (int i = 0; i <= LOD; i++)
    for (int j = 0; j <= LOD; j++)
    {
      // calculating reflecting vector
      Vector3d mapped;
      mapped.sub(center, eye);
      Vector3d n = Vector3d(surfaceNormals[i][j][0], surfaceNormals[i][j][1], surfaceNormals[i][j][2]);
      n.scale(-2 * n.dot(mapped));
      mapped.add(n);
      mapped.normalize();

      if (mapped.z >= 0) {
        float parabolic_x = ((mapped.x / (2 * (1 + mapped.z))) + 0.5) / 2;
        float parabolic_y = (-mapped.y / (2 * (1 + mapped.z))) + 0.5;
        texCoords[i][j][0] = parabolic_x;
        texCoords[i][j][1] = parabolic_y;
      } else {
        float parabolic_x = ((mapped.x / (2 * (1 - mapped.z))) + 0.5) / 2 + 0.5;
        float parabolic_y = (-mapped.y / (2 * (1 - mapped.z))) + 0.5;
        texCoords[i][j][0] = parabolic_x;
        texCoords[i][j][1] = parabolic_y;
      }

      // double sum = sqrt(mapped.x*mapped.x + mapped.y*mapped.y + pow(mapped.z+1,2));
      // texCoords[i][j][0] = (mapped.x/sum + 1) / 2;
      // texCoords[i][j][1] = (-mapped.y/sum + 1) / 2;
      // float padding_y = 1/3.0;
      // float padding_x = 1/4.0;
      // if (mapped.x >= std::abs(mapped.y) && mapped.x >= std::abs(mapped.z)) { // right
      //   texCoords[i][j][0] = (-mapped.z / mapped.x + 1) / 2 / 4 + padding_x * 2;
      //   texCoords[i][j][1] = (-mapped.y / mapped.x + 1) / 2 / 3 + padding_y;
      // } else if (mapped.y >= std::abs(mapped.x) && mapped.y >= std::abs(mapped.z)) { // top
      //   texCoords[i][j][0] = (mapped.x / mapped.y + 1) / 2 / 4 + padding_x;
      //   texCoords[i][j][1] = (mapped.z / mapped.y + 1) / 2 / 3;
      // } else if (mapped.z >= std::abs(mapped.x) && mapped.z >= std::abs(mapped.y)) { // front
      //   texCoords[i][j][0] = (mapped.x / mapped.z + 1) / 2 / 4 + padding_x;
      //   texCoords[i][j][1] = (-mapped.y / mapped.z + 1) / 2 / 3 + padding_y;
      // } else if (mapped.x <= -std::abs(mapped.y) && mapped.x <= -std::abs(mapped.z)) { // left
      //   texCoords[i][j][0] = (-mapped.z / mapped.x + 1) / 2 / 4;
      //   texCoords[i][j][1] = (mapped.y / mapped.x + 1) / 2 / 3 + padding_y;
      // } else if (mapped.y <= -std::abs(mapped.x) && mapped.y <= -std::abs(mapped.z)) { // bottom
      //   texCoords[i][j][0] = (-mapped.x / mapped.y + 1) / 2 / 4 + padding_x;
      //   texCoords[i][j][1] = (mapped.z / mapped.y + 1) / 2 / 3 + padding_y * 2;
      // } else if (mapped.z <= -std::abs(mapped.x) && mapped.z <= -std::abs(mapped.y)) { // back
      //   texCoords[i][j][0] = (mapped.x / mapped.z + 1) / 2 / 4 + padding_x * 3;
      //   texCoords[i][j][1] = (mapped.y / mapped.z + 1) / 2 / 3 + padding_y;
      // }
    }

  glEnable(GL_TEXTURE_2D);
  for (int i = 0; i < LOD; i++)
  {
    glBegin(GL_QUAD_STRIP);
    for (int j = 0; j <= LOD; j++)
    {
      glTexCoord2dv(texCoords[i][j]);
      glVertex3dv(surfacePoints[i][j]);
      glTexCoord2dv(texCoords[i+1][j]);
      glVertex3dv(surfacePoints[i+1][j]);
    }
    glEnd();
  }
  glDisable(GL_TEXTURE_2D);
}