void init_scene(int width, int height)
{
    printGLString("Version", GL_VERSION);
    printGLString("Vendor", GL_VENDOR);
    printGLString("Renderer", GL_RENDERER);
    printGLString("Extensions", GL_EXTENSIONS);

    glDisable(GL_DITHER);
    glEnable(GL_CULL_FACE);

    float ratio = width / height;
    glViewport(0, 0, width, height);

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glFrustumf(-ratio, ratio, -1, 1, 1, 10);

    glMatrixMode(GL_MODELVIEW);

    glLoadIdentity();
    gluLookAt(
            0, 0, 3,  // eye
            0, 0, 0,  // center
            0, 1, 0); // up

    glEnable(GL_TEXTURE_2D);
    glEnableClientState(GL_VERTEX_ARRAY);
    glEnableClientState(GL_TEXTURE_COORD_ARRAY);
}
示例#2
0
static void reshape(int width, int height)
{
    // Height / width ration 
    GLfloat ratio;

    // Protect against a divide by zero 
    if (width == 0)
        width = 1;

    ratio = (GLfloat)height / (GLfloat)width;

    // Setup our viewport. 
    glViewport(0, 0, (GLsizei)width, (GLsizei)height);

    // change to the projection matrix and set our viewing volume. 
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();

    // Set our perspective 
	glFrustumf(-1.0, 1.0, -ratio, ratio, 0.1, 100.0);

    // Make sure we're chaning the model view and not the projection 
    glMatrixMode(GL_MODELVIEW);

    // Reset The View 
    glLoadIdentity();
}
示例#3
0
GL_API void GL_APIENTRY glFrustumx (GLfixed left, GLfixed right,
		GLfixed bottom, GLfixed top, GLfixed zNear, GLfixed zFar)
{
	glFrustumf(floatFromFixed(left), floatFromFixed(right),
		   floatFromFixed(bottom), floatFromFixed(top),
		   floatFromFixed(zNear), floatFromFixed(zFar));
}
示例#4
0
JNIEXPORT void JNICALL Java_com_bullet_demo_DemoLib_init(JNIEnv * env, jobject obj,  jint width, jint height)
{
	glShadeModel( GL_SMOOTH );
	glClearColor( 0.0f, 0.0f, 0.0f, 0.5f );
	glEnable( GL_DEPTH_TEST );
	glDepthFunc( GL_LEQUAL );
	glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST );

	LOGI("OpenGL Init finished");

	glViewport( 0, 0, ( GLint )width, ( GLint )height );
	glMatrixMode( GL_PROJECTION );
	glLoadIdentity( );

	float w = width;
	float h = height;
	glFrustumf(-1.0f, 1.0f, -1*h/w, h/w, 5.0f, 1000.0f);
	glMatrixMode( GL_MODELVIEW );
	glLoadIdentity( );

	LOGI("View Port and frustrum set.");

	init_physics();
	LOGI("Physics initialized");

}
示例#5
0
static void
use_pbuffer(void)
{
   static int initialized;

   eglMakeCurrent(dpy, surf_pbuf, surf_pbuf, ctx_pbuf);
   if (!initialized) {
      EGLint width, height;
      GLfloat ar;

      initialized = 1;

      eglQuerySurface(dpy, surf_pbuf, EGL_WIDTH, &width);
      eglQuerySurface(dpy, surf_pbuf, EGL_WIDTH, &height);
      ar = (GLfloat) width / (GLfloat) height;

      glViewport(0, 0, (GLint) width, (GLint) height);

      glMatrixMode(GL_PROJECTION);
      glLoadIdentity();
      glFrustumf(-ar, ar, -1, 1, 1.0, 10.0);

      glMatrixMode(GL_MODELVIEW);
      glLoadIdentity();

      /* y-inverted */
      glScalef(1.0, -1.0, 1.0);

      glTranslatef(0.0, 0.0, -5.0);

      glClearColor(0.2, 0.2, 0.2, 0.0);

      glGenTextures(1, &tex_pbuf);
   }
}
示例#6
0
// glu based camera functionality
void CCCameraBase::GluPerspective(float fovy, float aspect)
{	
    frustumMax.y = zNear * tanf( fovy * CC_PI / 360.0f );
	frustumMin.y = -frustumMax.y;
	frustumMin.x = frustumMin.y * aspect;
	frustumMax.x = frustumMax.y * aspect;
	
	const float zNearScale = 1.0f / zNear;
	frustumSize.width = ( frustumMax.x + -frustumMin.x ) * zNearScale;
	frustumSize.height = ( frustumMax.y + -frustumMin.y ) * zNearScale;
	
    if( gEngine->renderer->openGL2() )
    {
        CCMatrixLoadIdentity( projectionMatrix );
        CCMatrixFrustum( projectionMatrix, frustumMin.x, frustumMax.x, frustumMin.y, frustumMax.y, zNear, zFar );
    }
    else
    {
#ifdef IOS
        
        glMatrixMode( GL_PROJECTION );
        glLoadIdentity();
        glFrustumf( frustumMin.x, frustumMax.x, frustumMin.y, frustumMax.y, zNear, zFar );
        glGetFloatv( GL_PROJECTION_MATRIX, projectionMatrix.data() );
        
#endif
    }
}
示例#7
0
void CSpinZoom::Do( float fTime, float fTimeStart )
{
	m_fTime = fTime - fTimeStart - .1;

	glMatrixMode( GL_PROJECTION );
	glLoadIdentity();
	glFrustumf( -.6f, .6f, -.45f, .45f, 1, l_fZMax );

	glMatrixMode( GL_MODELVIEW );
	glLoadIdentity();

	glEnable( GL_TEXTURE_2D );
	glEnable( GL_BLEND );
	glBlendFunc( GL_SRC_ALPHA, GL_ONE );
	glDisable( GL_CULL_FACE );
	glDisable( GL_DEPTH_TEST );
	glDepthMask( 0 );

	glBindTexture( GL_TEXTURE_2D, m_iTex1 );

	for ( int i = 0; i != m_iSpins; i++ )
	{
		m_pSpins[i].Render( m_fTime );
	}
}
示例#8
0
void fs_gl_perspective(void)
{
    if (g_projection == 3) {
        return;
    }
#ifdef TRACE
    printf("gluPerspective 45.0, 16.0 / 9.0 0.1 100.0\n");
#endif
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    // FIXME: ASPECT
    double fov_y = 45.0;
    double aspect_ratio = 16.0 / 9.0;
    double front = 0.1;
    double back = 100.0;

    const double DEG2RAD = 3.14159265 / 180;
    double tangent = tan(fov_y / 2 * DEG2RAD); // tangent of half fovY
    double height = front * tangent;           // half height of near plane
    double width = height * aspect_ratio;      // half width of near plane
    // params: left, right, bottom, top, front, back
#ifdef USE_GLES
    glFrustumf(-width, width, -height, height, front, back);
#else
    glFrustum(-width, width, -height, height, front, back);
    //gluPerspective(fov_y, aspect_ratio, front, back);
#endif
    glMatrixMode(GL_MODELVIEW);
    CHECK_GL_ERROR();
    //glLoadIdentity();
    g_projection = 3;
}
示例#9
0
/***********************************************************
 * Name: init_model_proj
 *
 * Arguments:
 *       CUBE_STATE_T *state - holds OGLES model info
 *
 * Description: Sets the OpenGL|ES model to default values
 *
 * Returns: void
 *
 ***********************************************************/
static void init_model_projGLES1(void)
{
   // near clipping plane
   const float nearp = 1.0f;
   // far clipping plane
   const float farp = 50.0f;
   float hht;
   float hwd;


   glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST );

   glViewport(0, 0, (GLsizei)state->screen_width, (GLsizei)state->screen_height);

   glMatrixMode(GL_PROJECTION);
   glLoadIdentity();

   hht = nearp * (float)tan(45.0 / 2.0 / 180.0 * M_PI);
   hwd = hht * (float)state->screen_width / (float)state->screen_height;
   // set up the viewing frustum
   glFrustumf(-hwd, hwd, -hht, hht, nearp, farp);

   glMatrixMode(GL_MODELVIEW);

}
示例#10
0
文件: testegl.c 项目: 01org/gst-omx
/***********************************************************
 * Name: init_model_proj
 *
 * Arguments:
 *       APP_STATE_T *state - holds OGLES model info
 *
 * Description: Sets the OpenGL|ES model to default values
 *
 * Returns: void
 *
 ***********************************************************/
static void
init_model_proj (APP_STATE_T * state)
{
  float nearp = 1.0f;
  float farp = 500.0f;
  float hht;
  float hwd;

  glHint (GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);

  glViewport (0, 0, (GLsizei) state->screen_width,
      (GLsizei) state->screen_height);

  glMatrixMode (GL_PROJECTION);
  glLoadIdentity ();

  hht = nearp * (float) tan (45.0 / 2.0 / 180.0 * M_PI);
  hwd = hht * (float) state->screen_width / (float) state->screen_height;

  glFrustumf (-hwd, hwd, -hht, hht, nearp, farp);

  glEnableClientState (GL_VERTEX_ARRAY);
  glVertexPointer (3, GL_BYTE, 0, quadx);

  reset_model (state);
}
示例#11
0
void TileRender::updateFrustum()
{
	float left = mCurrentFrustumCoords.x1 + mCurrentArea.x1 / (float)mImageWidth * mCurrentFrustumCoords.getWidth();
	float right = left + mCurrentArea.getWidth() / (float)mImageWidth * mCurrentFrustumCoords.getWidth();
	float top = mCurrentFrustumCoords.y1 + mCurrentArea.y1 / (float)mImageHeight * mCurrentFrustumCoords.getHeight();
	float bottom = top + mCurrentArea.getHeight() / (float)mImageHeight * mCurrentFrustumCoords.getHeight();

	int matrixMode;
	glGetIntegerv( GL_MATRIX_MODE, &matrixMode );
	glMatrixMode( GL_PROJECTION );
	glLoadIdentity();

	if( mCurrentFrustumPersp ) {
#if defined( CINDER_GLES )
		glFrustumf( left, right, bottom, top, mCurrentFrustumNear, mCurrentFrustumFar );
#else
		glFrustum( left, right, bottom, top, mCurrentFrustumNear, mCurrentFrustumFar );
#endif
	}
	else
#if defined( CINDER_GLES )
		glOrthof( left, right, bottom, top, mCurrentFrustumNear, mCurrentFrustumFar );
#else
		glOrtho( left, right, bottom, top, mCurrentFrustumNear, mCurrentFrustumFar );
#endif
	
	glMatrixMode( matrixMode );
}
void SetPerspective(GLfloat fovDegree, GLfloat aspect, GLfloat zNear,  GLfloat zFar)
{
	// tan(double(degree) * 3.1415962 / 180.0 / 2.0);
	static const float HALF_TAN_TABLE[91] =
	{
		0.00000f, 0.00873f, 0.01746f, 0.02619f, 0.03492f, 0.04366f, 0.05241f, 0.06116f, 0.06993f,
		0.07870f, 0.08749f, 0.09629f, 0.10510f, 0.11394f, 0.12278f, 0.13165f, 0.14054f, 0.14945f,
		0.15838f, 0.16734f, 0.17633f, 0.18534f, 0.19438f, 0.20345f, 0.21256f, 0.22169f, 0.23087f,
		0.24008f, 0.24933f, 0.25862f, 0.26795f, 0.27732f, 0.28675f, 0.29621f, 0.30573f, 0.31530f,
		0.32492f, 0.33460f, 0.34433f, 0.35412f, 0.36397f, 0.37389f, 0.38386f, 0.39391f, 0.40403f,
		0.41421f, 0.42448f, 0.43481f, 0.44523f, 0.45573f, 0.46631f, 0.47698f, 0.48773f, 0.49858f,
		0.50953f, 0.52057f, 0.53171f, 0.54296f, 0.55431f, 0.56577f, 0.57735f, 0.58905f, 0.60086f,
		0.61280f, 0.62487f, 0.63707f, 0.64941f, 0.66189f, 0.67451f, 0.68728f, 0.70021f, 0.71329f,
		0.72654f, 0.73996f, 0.75356f, 0.76733f, 0.78129f, 0.79544f, 0.80979f, 0.82434f, 0.83910f,
		0.85408f, 0.86929f, 0.88473f, 0.90041f, 0.91633f, 0.93252f, 0.94897f, 0.96569f, 0.98270f,
		1.00000f
	};

	int degree = int(fovDegree + 0.5f);

	degree = (degree >=  0) ? degree :  0;
	degree = (degree <= 90) ? degree : 90;

	GLfloat fxdYMax  = GLfloat(zNear * HALF_TAN_TABLE[degree]);
	GLfloat fxdYMin  = -fxdYMax;

	GLfloat fxdXMax  = GLfloat(GLfloat(fxdYMax) * aspect);
	GLfloat fxdXMin  = -fxdXMax;

	glFrustumf(fxdXMin, fxdXMax, fxdYMin, fxdYMax, GLfloat(zNear), GLfloat(zFar));
}
示例#13
0
void gluPerspective(double fovy, double aspect, double zNear, double zFar) {
    GLfloat xmin, xmax, ymin, ymax;
    ymax = zNear * tan(fovy * M_PI / 360.0);
    ymin = -ymax;
    xmin = ymin * aspect;
    xmax = ymax * aspect;
    glFrustumf(xmin, xmax, ymin, ymax, zNear, zFar);
}
示例#14
0
文件: cube.c 项目: bbw2008good/ftk
void reshape (UGWindow uwin, int w, int h)
{
   glViewport (0, 0, (GLsizei) w, (GLsizei) h); 
   glMatrixMode (GL_PROJECTION);
   glLoadIdentity ();
   glFrustumf(-1.0, 1.0, -1.0, 1.0, 1.5, 20.0);
   glMatrixMode (GL_MODELVIEW);
}
示例#15
0
inline void gluPerspective( float fovy, float aspect, float zNear, float zFar )
{
	GLfloat ymax = zNear * tan( fovy * M_PI / 360.0 );
	GLfloat ymin = -ymax;
	GLfloat xmin = ymin * aspect;
	GLfloat xmax = ymax * aspect;
	glFrustumf( xmin, xmax, ymin, ymax, zNear, zFar );
}
示例#16
0
void init_scene()
{
   static GLfloat lightpos[4]={50.0f, 50.0f, -320.f, 1.0f};
   GLubyte* tex;

   /* Clear error */
   glGetError();

   /* draw a perspective scene */
   glMatrixMode(GL_PROJECTION);
   glFrustumf(-100.f, 100.f, -100.f, 100.f, 320.f, 640.f);
   glMatrixMode(GL_MODELVIEW);

   /* turn on features */
   glEnable(GL_DEPTH_TEST);
   glEnable(GL_LIGHTING);
   glEnable(GL_LIGHT0);

   /* place light 0 in the right place */
   glLightfv(GL_LIGHT0, GL_POSITION, lightpos);

   /* enable filtering */
   glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
   glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

   tex=make_texture(256, 256);
   glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 256, 256, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, tex);
   free(tex);

   disk_fill=gluNewQuadric();
   gluQuadricDrawStyle(disk_fill, GLU_FILL);
   gluQuadricNormals(disk_fill, GLU_SMOOTH);

   disk_fill_flat=gluNewQuadric();
   gluQuadricDrawStyle(disk_fill_flat, GLU_FILL);
   gluQuadricNormals(disk_fill_flat, GLU_FLAT);

   disk_fill_texture=gluNewQuadric();
   gluQuadricDrawStyle(disk_fill_texture, GLU_FILL);
   gluQuadricNormals(disk_fill_texture, GLU_SMOOTH);
   gluQuadricTexture(disk_fill_texture, GLU_TRUE);

   disk_point=gluNewQuadric();
   gluQuadricDrawStyle(disk_point, GLU_POINT);
   gluQuadricNormals(disk_point, GLU_SMOOTH);

   disk_line=gluNewQuadric();
   gluQuadricDrawStyle(disk_line, GLU_LINE);
   gluQuadricNormals(disk_line, GLU_SMOOTH);

   disk_silh=gluNewQuadric();
   gluQuadricDrawStyle(disk_silh, GLU_SILHOUETTE);

   if (glGetError())
   {
      printf("Oops! I screwed up my OpenGL ES calls somewhere\n");
   }
}
示例#17
0
// -----------------------------------------------------------------------------
// CSimpleCubePbuffer::SetScreenSize
// Reacts to the dynamic screen size change during execution of this program.
// -----------------------------------------------------------------------------
//
void CSimpleCubePbuffer::SetScreenSize( TUint aWidth, TUint aHeight )
    {
    iScreenWidth  = aWidth;
    iScreenHeight = aHeight;

    // Reinitialize OpenGL ES
    // Set the screen background color.
    glClearColor( 0.f, 0.f, 0.f, 1.f );

    // Enable back face culling.
    glEnable( GL_CULL_FACE  );

    // Initialize viewport and projection.
    glViewport( 0, 0, iScreenWidth, iScreenHeight );
    glMatrixMode( GL_PROJECTION );
    glFrustumf( -1.f, 1.f, -1.f, 1.f, 3.f, 1000.f );
    glMatrixMode( GL_MODELVIEW );

    // Enable vertex arrays.
    glEnableClientState( GL_VERTEX_ARRAY );

    // Set array pointers.
    glVertexPointer( 3, GL_BYTE, 0, vertices );

    // Enable color arrays.
    glEnableClientState( GL_COLOR_ARRAY );

    // Set color pointers.
    glColorPointer( 4, GL_UNSIGNED_BYTE, 0, colors );

    // Set the initial shading mode
    glShadeModel( GL_FLAT );

    // Do not use perspective correction
    glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST );

    // Recalculate the view frustrum
    glMatrixMode( GL_PROJECTION );
    glLoadIdentity();
    GLfloat aspectRatio = (GLfloat)(iScreenWidth) / (GLfloat)(iScreenHeight);
    glFrustumf( FRUSTUM_LEFT * aspectRatio, FRUSTUM_RIGHT * aspectRatio,
                FRUSTUM_BOTTOM, FRUSTUM_TOP,
                FRUSTUM_NEAR, FRUSTUM_FAR );
    glMatrixMode( GL_MODELVIEW );
    }
示例#18
0
void gluPerspective(GLfloat fovy, GLfloat aspect, GLfloat zNear, GLfloat zFar) {
	GLfloat xmin, xmax, ymin, ymax;

	ymax = zNear * tan(fovy * M_PI / 360.0);
	ymin = -ymax;
	xmin = ymin * aspect;
	xmax = ymax * aspect;

	glFrustumf(xmin, xmax, ymin, ymax, zNear, zFar);
}
示例#19
0
static void reshape(int w,int h)
{
       glViewport (0, 0, (GLsizei) w, (GLsizei) h);
    glMatrixMode (GL_PROJECTION);
    glLoadIdentity();
    glFrustumf(-1.5f, 1.5f, -1.5f,1.5f, 1.0f, 10.0f);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
       glTranslatef(0.0, 0.0, -3.6f);
}
示例#20
0
void GLWidget::perspectiveProjection()
{
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
#ifdef QT_OPENGL_ES
    glFrustumf(-aspect, +aspect, -1.0, +1.0, 4.0, 15.0);
#else
    glFrustum(-aspect, +aspect, -1.0, +1.0, 4.0, 15.0);
#endif
    glMatrixMode(GL_MODELVIEW);
}
示例#21
0
static void reshape(int w, int h)
{
   glViewport(0, 0, (GLsizei) w, (GLsizei) h);
   glMatrixMode(GL_PROJECTION);
   glLoadIdentity();
   //ugluPerspectivef(60.0, (GLfloat) w/(GLfloat) h, 1.0, 30.0);
   glFrustumf(-1.5f, 1.5f, -1.5f,1.5f, 1.0f, 30.0f);
   glMatrixMode(GL_MODELVIEW);
   glLoadIdentity();
   glTranslatef(0.0, 0.0, -3.6f);
}
示例#22
0
// -----------------------------------------------------------------------------
// gluPerspective()
// Implementation of the GLU library function that allows the set up of a
// perspective projection matrix using field of view angles and aspect ratio.
// -----------------------------------------------------------------------------
void gluPerspective( GLfloat aFovY,  GLfloat aAspectRatio,
                     GLfloat aNearZ, GLfloat aFarZ )
    {
    GLfloat minX, maxX, minY, maxY;

    maxY = aNearZ * tan( aFovY * PI / 360.f );
    minY = -maxY;
    minX = minY * aAspectRatio;
    maxX = maxY * aAspectRatio;

    glFrustumf( minX, maxX, minY, maxY, aNearZ, aFarZ );
    }
示例#23
0
void renderMe(){
	if(z>1.0f){
	        z = 0.0f;
	    }
	    else{
	        z = z+.01;
	    }
	    if (f > 359.0f) {
	        f = 0.0f;
	    } else {
	        f = f + 1.0f;
	    }
	    GLubyte bytePixChar[4 * 3]={
	          255, 0, 0, //red
	          0, 255, 0, //green
	          0, 0, 255,  //blue
	          255, 255, 0  //yellow
	     };
	    int o;

	      GLfloat texC[8] = {
	        0.0, 0.0,
	        1.0, 0.0,
	        0.0, 1.0,
	        1.0, 1.0

	      };
	    glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
	    glGenTextures(1, &textureId);
	    glBindTexture(GL_TEXTURE_2D, textureId);
	    GLubyte *byteBuffer = (GLubyte *)malloc(pixelWidth * pixelHeight * 3);
	        int c;
	        for(c = 0; c < pixelWidth * pixelHeight * 3; c++)
	          byteBuffer[c] = pixels[c];
	    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, pixelWidth, pixelHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, byteBuffer);
	    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
	    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
	    glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
	    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	    glXRotate(0.0f);
		glYRotate(0.0f);
		glZRotate(0.0f);
		glFrustumf(0.1f, 10.0f);
		glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, gObj);
		glVertexAttribPointer(textCoordLoc, 2, GL_FLOAT, GL_FALSE, 0, texC);

		glUniform1i(sampler, 0 );
		glEnableVertexAttribArray(0);
		glEnableVertexAttribArray(textCoordLoc);
		glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
		render = 0;
}
示例#24
0
void SetPerspective( float fov, float aspect, float zNear, float zFar )
{
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();  
	glViewport(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
	//float aspect = (GLfloat)kWindowWidth/(GLfloat)kWindowHeight;
	float fH = float ( tan( fov / 360 * PI ) * zNear );
	float fW = float ( fH * aspect );
	glFrustumf( -fW, fW, -fH, fH, zNear, zFar );
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	return;
}
示例#25
0
void MYgluPerspective( float fovy, float aspect,
		     float zNear, float zFar )
{
   float xmin, xmax, ymin, ymax;

   ymax = zNear * tan( fovy * M_PI / 360.0f );
   ymin = -ymax;

   xmin = ymin * aspect;
   xmax = ymax * aspect;

   glFrustumf( xmin, xmax, ymin, ymax, zNear, zFar );
}
示例#26
0
void xgluPerspective( float fovy, float aspect, float near_clip, float far_clip )
{
    const double PI = 3.1415926;
    double TWOPI_OVER_360 = 2.0 * PI / 360.0;
    float half_height = near_clip * (float)tan( fovy * 0.5 * TWOPI_OVER_360 );
    float half_width = half_height * aspect;

#ifdef WIN32
    glFrustum( -half_width, half_width, -half_height, half_height, near_clip, far_clip );
#elif defined(CK_ANDROID)
    glFrustumf( -half_width, half_width, -half_height, half_height, near_clip, far_clip );
#endif
}
示例#27
0
文件: sgles1.c 项目: dschmenk/SEGL
void sglViewFrustrum(GLfloat fov, GLfloat near, GLfloat far, GLsizei width, GLsizei height)
{
    float hht;
    float hwd;
    glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
    glViewport(0, 0, width, height);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    hht = near * (float)tan(fov / 2.0 / 180.0 * M_PI);
    hwd = hht * (float)width / (float)height;
    glFrustumf(-hwd, hwd, -hht, hht, near, far);
    glMatrixMode(GL_MODELVIEW);
}
示例#28
0
void
gluPerspective(GLfloat fovy, GLfloat aspect, GLfloat zNear, GLfloat zFar)
{
	GLfloat xmin, xmax, ymin, ymax;

	const float m_pi = 3.14159;

   ymax = zNear * tan(fovy * m_pi / 360.0);
   ymin = -ymax;
   xmin = ymin * aspect;
   xmax = ymax * aspect;

   glFrustumf(xmin, xmax, ymin, ymax, zNear, zFar);
}
示例#29
0
int main()
{
    gfxInitDefault();
    hidInit(NULL);

    void* device = gfxCreateDevice(240, 400);
    gfxMakeCurrent(device);

    glViewport(0, 0, 240, 400);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();

    float near = 0.1f;
    float far = 100.0f;
    float fov = 90.0f;
    float aspect = 240.0f / 400.0f;
    float t = tan(fov * 3.14159 / 360.0) * near;
    float b = -t;
    float l = aspect * b;
    float r = aspect * t;
    glFrustumf(l, r, b, t, near, far);
    //3DS' framebuffers are sideways
    glRotatef(-90.0f, 0.0f, 0.0f, 1.0f);

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

    glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
    glEnable(GL_DEPTH_TEST);

    while (aptMainLoop())
    {
        hidScanInput();

        if (keysDown() & KEY_START)
            break;

        DrawGLScene();

        gfxFlush(gfxGetFramebuffer(GFX_TOP, GFX_LEFT, NULL, NULL));
        gfxFlushBuffers();
        gfxSwapBuffersGpu();
        gspWaitForVBlank();
    }

    // Exit services
    gfxExit();
    hidExit();
    return 0;
}
void setup(int ancho, int alto) {
	GLfloat size; 

	anchoPantalla = ancho;
	altoPantalla = alto;
	
	glMatrixMode(GL_PROJECTION); 
	glEnable(GL_DEPTH_TEST);
	size = kZNear * tanf(GRADOS_A_RADIANES(kFieldOfView) / 2.0); 
	glFrustumf(-size, size, -size / (1.0*ancho / alto), size / (1.0*ancho / alto), kZNear, kZFar); 
	glViewport(0, 0, ancho, alto); 
	glMatrixMode(GL_MODELVIEW); 
	glLoadIdentity(); 
	glClearColor(1.0f, 1.0f, 1.0f, 1.0f); 
}