`
daojin
  • 浏览: 677245 次
  • 性别: Icon_minigender_1
  • 来自: 西安
社区版块
存档分类
最新评论

自己动手实现OpenGL之glViewPort(一)

阅读更多

直接上代码。

	public static   void glViewport(
            int x,
            int y,
            int width,
            int height
     ) 
	{
		int surfaceHeight = mInfo.height;
		float far = mViewPortZFar;
		float near = mViewPortZNear;
		float sx = width/2.0f;
		float ox = sx + x;
		float sy = height/2.0f;
		float oy = sy + surfaceHeight - height - y;   
		float A = (far - near)/2.0f;
		float B = (far + near)/2.0f;
		// compute viewport matrix
		float[][] f = new float[4][4];
	    f[0][0] = sx;  f[0][1] = 0;   f[0][2] = 0;  f[0][3] = ox;
		f[1][0] = 0;   f[1][1] =-sy;  f[1][2] = 0;  f[1][3] = oy;
		f[2][0] = 0;   f[2][1] = 0;   f[2][2] = A;  f[2][3] = B;
		f[3][0] = 0;   f[3][1] = 0;   f[3][2] = 0;  f[3][3] = 1;
		mCurrentViewPortMatrix = new M4();
		mCurrentViewPortMatrix.m = f;
	}

 

 

  

 public static void glDepthRangef(
        float zNear,
        float zFar
    ){
     mViewPortZNear = zNear;
     mViewPortZFar = zFar;
    }

 
   

分享到:
评论

相关推荐

    OpenGl实验报告.doc

    实验目的与要求 1、学习和掌握OpenGL的使用 2、掌握矩阵堆栈的实现方法 3、根据自己的创意实现实验内容,进一步掌握和理解OpenGL的使用 2. 实验内容 1、请编写地球围绕太阳自动旋转的方式 2、请再加上一个月亮, 并...

    glViewport()与glOrtho()函数的理解.doc

    glViewport()与glOrtho()函数的理解glViewport()与glOrtho()函数的理解glViewport()与glOrtho()函数的理解glViewport()与glOrtho()函数的理解

    用opengl绘制一个旋转正方体.cpp

    glViewport(0, 0, w, h); glMatrixMode(GL_PROJECTION); //将当前矩阵指定为投影模式 glLoadIdentity(); //设置三维投影区 if (w ) { glOrtho(-nRange, nRange, -nRange * aspect, nRange * aspect, -...

    opengl 期末复习资料

    6、 在一个坐标系W中,光源的位置为 (0, 0, 200, 1.0),设模型为一个以(1.0, 0.0, 0.0), (0.0, 1.0, 0.0), (0.0, 0.0, 1.0)为三个点的三角形,另一个模型是以(0, 0, 10)为中心,长度为2的一个正方体,如何实现该...

    opengl画旋转多边形

    //样本程序: 旋转的六边形 #include "stdafx.h" #include #include #define PI 3.14159 //设置圆周率 ... glViewport(0,0,w,h); //设置视区大小 glMatrixMode(GL_MODELVIEW); //模型矩阵模式 }

    gertt点阵图读取器(opengl)

    glViewport(0,0,width,height); // Reset The Current Viewport glMatrixMode(GL_PROJECTION); // Select The Projection Matrix glLoadIdentity(); // Reset The Projection Matrix // ...

    OpenGL视口变换

    Void glViewport(Glint x,Glint y,GLsizei width,Glsizei height); 在窗口中定义一个像素矩形,最终的图形将映射到个矩形中。(x,y)参数指定了视口的左下角,width和height表示这个视口矩形的宽度和高度。

    opengl画图程序附带源代码

    glViewport(0,0,width,height); // Reset The Current Viewport glMatrixMode(GL_PROJECTION); // Select The Projection Matrix glLoadIdentity(); // Reset The Projection Matrix // Calculate The Aspect ...

    opengl的太阳系模型

    // 初始化OpenGL void InitGL(void) { glClearColor(0.0f, 0.0f, 0.0f, 0.5f); //设置黑色背景 glClearDepth(2.0f); // 设置深度缓存 glEnable(GL_DEPTH_TEST); //启动深度测试 glDepthFunc(GL_LEQUAL); //深度...

    opengl加载3DS文件

    在加载过程中可以将窗口分割代码部分去除掉,不然会让模型显示在右上角,可以将主函数中glviewport部分删除即可实现单模型加载

    opengl橡皮筋

    glViewport(0, 0, (GLsizei)w, (GLsizei)h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); if (w ) glOrtho(-3.5, 3.5, -3.5*(GLfloat)h / (GLfloat)w, 3.5*(GLfloat)h / (GLfloat)w, -3.5, 3.5); else ...

    glViewport - 人为干预视口改变和场景

    游戏开发中,人机互动机制是必不可少的。输入装置要么操作杆、要么是键盘。视口改变是无论在3D还是2D都要出现的功能,比如,google地图就是一个显然的变视口问题,视口如同一个放大镜在地图上方...本篇就模拟实现之。

    图形学平移缩小旋转

    图形学中实现图形的选择,平移,缩小。主要绘制了三角形,四方形和五角星。

    openGL程序

    glViewport(0,0,w,h); float fAspect=(GLfloat)w/(GLfloat)h; glMatrixMade(GL_PROJECTION); glLoadIdentity(); glutPostRedisplay(); } void TimerFunc(int value) { glutPostRedisplay(); ...

    计算机图形学作业实验报告.doc

    二、实验内容步骤和实现:首先进行初始化工作,进行显示模式(单缓冲区)和窗口等 设定,主要实现根据两个函数,一个是指定场景绘制函数,glutDisplayFunc(Paint), paint函数中设置了两个三角形,一个填充,一个不...

    支持Python3.3,PyQt4的PyOpenGL

    支持Python3.3,PyQt4的PyOpenGL。如果你是使用PyQt4中的OpenGL例子,如果运行出现错误,请将glViewport()函数改成GL.glViewport(0, 0, side, side)形式。

    OopenGL习题讲解

    【例3-2】使用glut库函数绘制一个真实感的球。 # include /* 初始化材料属性、光源属性、光照模型,打开深度缓冲区等 */ void init(void) { GLfloat light_position [ ] = { 1.0, 1.0, 1.0, 0.0 }; glClearColor ( ...

    CodeFullToolkit:基于OpenTK的可视化工具包

    当前,它包含一个名为GLViewport3D的Windows窗体控件,OpenTK GLControl的扩展以及试图创建更好的WPF Viewport3D替代方案的尝试。 GLViewport3D能够快速渲染具有数百万个顶点的三角形网格并对其进行处理。 可以从...

    MTK GPU函数库,请下载附件反编译

    1.项目需求 ...我需要从这4个库函数中反编译出“glViewport”函数的详细代码逻辑。 3.参考 source/目录下是部分已反编译出的代码,可以参考 4.其他的txt文件是4个库函数的2进制代码,用于参考一下。

    计算机图形学制作时钟源代码

    用MFC VC++实现的时钟源代码 // MFCFrame1View.cpp : implementation of the CMFCFrame1View class // #include "stdafx.h" #include "MFCFrame1.h" #include "MFCFrame1Doc.h" #include "MFCFrame1View.h" #...

Global site tag (gtag.js) - Google Analytics