本文整理匯總了Java中javax.media.opengl.GL2.glViewport方法的典型用法代碼示例。如果您正苦於以下問題:Java GL2.glViewport方法的具體用法?Java GL2.glViewport怎麽用?Java GL2.glViewport使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.media.opengl.GL2
的用法示例。
在下文中一共展示了GL2.glViewport方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: reshape
import javax.media.opengl.GL2; //導入方法依賴的package包/類
public void reshape(GLAutoDrawable drawable, int x, int y, int width,
int height) {
GL2 gl = drawable.getGL().getGL2();
this.drawable = drawable;
this.width = width;
this.height = height;
gl.glMatrixMode(GL2.GL_PROJECTION);
gl.glLoadIdentity();
gl.glOrtho(0, width, height, 0, -1, 1);
gl.glViewport(0, 0, width, height);
gl.glGetDoublev(GL2.GL_MODELVIEW_MATRIX, modelview);
gl.glGetDoublev(GL2.GL_PROJECTION_MATRIX, projection);
gl.glGetIntegerv(GL2.GL_VIEWPORT, viewport);
}
示例2: setView
import javax.media.opengl.GL2; //導入方法依賴的package包/類
public void setView(GL2 gl, GLU glu, GlobalState gs) {
// Select part of window.
gl.glViewport(0, 0, gs.w, gs.h);
// Set projection matrix.
gl.glMatrixMode(GL_PROJECTION);
//Load the identity matrix.
gl.glLoadIdentity();
glu.gluPerspective(fovAngle, (float) gs.w / gs.h, planeNear, planeFar);
// Set camera.
gl.glMatrixMode(GL_MODELVIEW);
//Load the identity matrix.
gl.glLoadIdentity();
glu.gluLookAt(eye.x(), eye.y(), eye.z(),
center.x(), center.y(), center.z(),
up.x(), up.y(), up.z());
}
示例3: applyCamera
import javax.media.opengl.GL2; //導入方法依賴的package包/類
/**
* Apply the camera settings.
*
* @param gl GL API.
*/
public void applyCamera(GL2 gl) {
// Setup projection.
gl.glMatrixMode(GL2.GL_PROJECTION);
gl.glLoadIdentity();
glu.gluPerspective(45f, // fov,
width / (float) height, // ratio
0.f, 10.f); // near, far clipping
eye[0] = (float) Math.sin(theta) * 2.f;
eye[1] = .5f;
eye[2] = (float) Math.cos(theta) * 2.f;
glu.gluLookAt(eye[0], eye[1], eye[2], // eye
.0f, .0f, 0.f, // center
0.f, 1.f, 0.f); // up
gl.glMatrixMode(GL2.GL_MODELVIEW);
gl.glLoadIdentity();
gl.glViewport(0, 0, width, height);
}
示例4: reshape
import javax.media.opengl.GL2; //導入方法依賴的package包/類
@Override
public void reshape(GLAutoDrawable arg0, int arg1, int arg2, int arg3, int arg4) {
GL2 gl2 = arg0.getGL().getGL2();
gl2.glMatrixMode(GL2.GL_PROJECTION);
gl2.glLoadIdentity();
// coordinate system origin at lower left with width and height same as the window
GLU glu = new GLU();
glu.gluOrtho2D(0.0f, getWidth(), 0.0f, getHeight());
gl2.glMatrixMode(GL2.GL_MODELVIEW);
gl2.glLoadIdentity();
gl2.glViewport(0, 0, getWidth(), getHeight());
controller.updateExtents(arg3 / 2, arg4 / 2);
}
示例5: updateView
import javax.media.opengl.GL2; //導入方法依賴的package包/類
private void updateView( GL2 gl2 )
{
gl2 .glMatrixMode( GL2.GL_PROJECTION );
gl2 .glLoadIdentity();
// coordinate system origin at lower left with width and height same as the window
if ( this .fov == 0 )
gl2 .glOrtho( - this .halfEdge, this .halfEdge, - this .halfEdge, this .halfEdge, this .near, this .far );
else
this .glu .gluPerspective( this .fov, this .width / this .height, this .near, this .far );
glu .gluLookAt( 0, 0, (this .far - this .near) / 2f, 0, 0, 0, 0, 1, 0 );
gl2 .glMatrixMode( GL2.GL_MODELVIEW );
gl2 .glLoadIdentity();
gl2 .glViewport( 0, 0, this .width, this .height );
}
示例6: init
import javax.media.opengl.GL2; //導入方法依賴的package包/類
@Override
public void init( final GLAutoDrawable drawable )
{
final GL2 gl = drawable.getGL().getGL2();
gl.setSwapInterval( 1 );
gl.glEnable( GL.GL_DEPTH_TEST );
gl.glDepthFunc( GL.GL_LEQUAL );
gl.glShadeModel( GLLightingFunc.GL_SMOOTH );
gl.glHint( GL2ES1.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST );
// gl.glEnable( GL.GL_BLEND );
// gl.glBlendFunc( GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA );
gl.glEnable( GL2GL3.GL_POLYGON_SMOOTH );
final float w = this.window.getDrawableSurface().getWidth();
final float h = this.window.getDrawableSurface().getHeight();
// Set the projection matrix (only done once - just here)
gl.glMatrixMode( GLMatrixFunc.GL_PROJECTION );
gl.glLoadIdentity();
this.glu.gluPerspective( 50, (w / h), 0.01, 10 );
// Set the initial model matrix
gl.glMatrixMode( GLMatrixFunc.GL_MODELVIEW );
gl.glLoadIdentity();
gl.glViewport( 0, 0, (int) w, (int) h ); /* viewport size in pixels */
}
示例7: reshape
import javax.media.opengl.GL2; //導入方法依賴的package包/類
public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height)
{
GL2 gl = drawable.getGL().getGL2();
gl.glViewport(0, 0, width, height);
gl.glMatrixMode(GL2.GL_PROJECTION);
gl.glLoadIdentity();
glu.gluOrtho2D(0.0f,1.0f,0.0f,1.0f);
}
示例8: display
import javax.media.opengl.GL2; //導入方法依賴的package包/類
public void display(GLAutoDrawable drawable) {
GL2 gl = drawable.getGL().getGL2();
this.drawable = drawable;
// Apply transformations
double transx = -origin.getX(), transy = -origin.getY();
gl.glMatrixMode(GL2.GL_PROJECTION);
gl.glLoadIdentity();
gl.glOrtho(0, width, height, 0, -1, 1);
gl.glViewport(0, 0, width, height);
gl.glTranslated(transx + zoomPos.getX(), transy + zoomPos.getY(), 0);
gl.glScaled(scaleFactor, scaleFactor, 1);
gl.glTranslated(-zoomPos.getX(), -zoomPos.getY(), 0);
gl.glGetDoublev(GL2.GL_MODELVIEW_MATRIX, modelview);
gl.glGetDoublev(GL2.GL_PROJECTION_MATRIX, projection);
gl.glGetIntegerv(GL2.GL_VIEWPORT, viewport);
gl.glClear(GL2.GL_COLOR_BUFFER_BIT | GL2.GL_DEPTH_BUFFER_BIT);
// Draw edges, arrows and vertices
edgeRenderer.transform(transx, transy, scaleFactor);
edgeRenderer.render();
if (animateLabels) {
labelRenderer.scale(scaleFactor);
labelRenderer.drawLabels();
}
vertexRenderer.transform(transx, transy, scaleFactor);
vertexRenderer.render();
}
示例9: setProjection
import javax.media.opengl.GL2; //導入方法依賴的package包/類
private void setProjection(GL2 openGl) {
float halfOfHorizont = width / zoom;
float halfOfVertical = height / zoom;
openGl.glViewport(0, 0, width, height);
openGl.glMatrixMode(GL2.GL_PROJECTION);
openGl.glLoadIdentity();
openGl.glOrtho(-halfOfHorizont, halfOfHorizont, -halfOfVertical, halfOfVertical, -1000, +1000);
openGl.glMatrixMode(GL2.GL_MODELVIEW);
}
示例10: setupCamera
import javax.media.opengl.GL2; //導入方法依賴的package包/類
@Override
public void setupCamera(GL2 gl, GLU glu, float x, float y, float z,
int width, int height) {
if(state != null) {
// Change to projection matrix.
gl.glMatrixMode(GL2.GL_PROJECTION);
gl.glLoadIdentity();
gl.glViewport(0, 0, width, height);
FloatBoundingBox bbox = state.getOrthogonalBBox();
float glWidth = Math.abs(bbox.getUpperRight().getX()
- bbox.getUpperLeft().getX());
float glHeight = Math.abs(bbox.getUpperRight().getY()
- bbox.getLowerRight().getY());
FloatVector3D glCenter = state.getPosition();
gl.glOrthof(glCenter.getX() - glWidth / 2.0f, glCenter.getX() + glWidth
/ 2.0f, glCenter.getY() - glHeight / 2.0f, glCenter.getY()
+ glHeight / 2.0f, -10000, 10000);
gl.glTranslatef(glCenter.getX(), glCenter.getY(), 0);
gl.glRotatef(state.getRotation().getX(), 1, 0, 0);
gl.glRotatef(state.getRotation().getZ(), 0, 0, 1);
gl.glTranslatef(-glCenter.getX(), -glCenter.getY(), 0);
// Change back to model view matrix.
gl.glMatrixMode(GL2.GL_MODELVIEW);
gl.glLoadIdentity();
}
}
示例11: setupLighting
import javax.media.opengl.GL2; //導入方法依賴的package包/類
private void setupLighting(GLAutoDrawable drawable, GL2 gl) {
int paramsOffset = 0;
float pos[] = { 2.0f, -2.0f, 10.0f, 0.0f };
float ambient[] = {0.5f, 0.5f, 0.5f, 1.0f};
float diffuse[] = {0.9f, 0.9f, 0.9f, 1.0f};
float specular[] = {0.05f, 0.05f, 0.99f, 1.0f};
gl.glLightfv(GL2.GL_LIGHT0, GL2.GL_POSITION, pos, 0);
gl.glEnable(GL2.GL_LIGHTING);
gl.glEnable(GL2.GL_LIGHT0);
gl.glEnable(GL2.GL_DEPTH_TEST);
gl.glEnable(GL2.GL_AUTO_NORMAL);
gl.glEnable(GL2.GL_NORMALIZE);
gl.glLightfv(GL2.GL_LIGHT0, GL2.GL_AMBIENT, ambient, paramsOffset);
gl.glLightfv(GL2.GL_LIGHT0, GL2.GL_DIFFUSE, diffuse, paramsOffset);
gl.glLightfv(GL2.GL_LIGHT0, GL2.GL_SPECULAR, specular, paramsOffset);
gl.glLightfv(GL2.GL_LIGHT0, GL2.GL_POSITION, pos, paramsOffset);
gl.glLightModeli(GL2.GL_LIGHT_MODEL_LOCAL_VIEWER, GL2.GL_TRUE);
gl.glClearColor(1f, 1f, 1f, 1f);
gl.glClear(GL2.GL_COLOR_BUFFER_BIT | GL2.GL_DEPTH_BUFFER_BIT);
gl.glMatrixMode(GL2.GL_MODELVIEW);
gl.glLoadIdentity();
gl.glViewport(0, 0, drawable.getSurfaceWidth(), drawable.getSurfaceHeight());
gl.glMatrixMode(GL2.GL_PROJECTION);
gl.glLoadIdentity();
if (gl instanceof GLLightingFunc) {
((GLLightingFunc) gl).glMaterialfv(GL.GL_FRONT, GLLightingFunc.GL_AMBIENT_AND_DIFFUSE, blue, 0);
((GLLightingFunc) gl).glMaterialfv(GL.GL_FRONT, GLLightingFunc.GL_SPECULAR, white, 0);
float[] medHiShiny = new float[] {80.0f};
((GLLightingFunc) gl).glMaterialfv(GL.GL_FRONT, GLLightingFunc.GL_SHININESS, medHiShiny, 0);
((GLLightingFunc) gl).glShadeModel(GLLightingFunc.GL_FLAT);
}
}
示例12: render
import javax.media.opengl.GL2; //導入方法依賴的package包/類
@SuppressWarnings("static-access")
protected void render(GL2 gl2) {
if (use_draw_pixels_ || view_width_ == 0 || view_height_ == 0) {
return;
}
assert (initialized_context_ != null);
final float[] vertex_data = {
//tu, tv, x, y, z
0.0f, 1.0f, -1.0f, -1.0f, 0.0f, 1.0f, 1.0f, 1.0f, -1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0.0f, -1.0f, 1.0f, 0.0f };
FloatBuffer vertices = FloatBuffer.wrap(vertex_data);
gl2.glClear(gl2.GL_COLOR_BUFFER_BIT | gl2.GL_DEPTH_BUFFER_BIT);
gl2.glMatrixMode(gl2.GL_MODELVIEW);
gl2.glLoadIdentity();
// Match GL units to screen coordinates.
gl2.glViewport(0, 0, view_width_, view_height_);
gl2.glMatrixMode(gl2.GL_PROJECTION);
gl2.glLoadIdentity();
// Draw the background gradient.
gl2.glPushAttrib(gl2.GL_ALL_ATTRIB_BITS);
gl2.glBegin(gl2.GL_QUADS);
gl2.glColor4f(1.0f, 0.0f, 0.0f, 1.0f); // red
gl2.glVertex2f(-1.0f, -1.0f);
gl2.glVertex2f(1.0f, -1.0f);
gl2.glColor4f(0.0f, 0.0f, 1.0f, 1.0f); // blue
gl2.glVertex2f(1.0f, 1.0f);
gl2.glVertex2f(-1.0f, 1.0f);
gl2.glEnd();
gl2.glPopAttrib();
// Rotate the view based on the mouse spin.
if (spin_x_ != 0) {
gl2.glRotatef(-spin_x_, 1.0f, 0.0f, 0.0f);
}
if (spin_y_ != 0) {
gl2.glRotatef(-spin_y_, 0.0f, 1.0f, 0.0f);
}
if (transparent_) {
// Alpha blending style. Texture values have premultiplied alpha.
gl2.glBlendFunc(gl2.GL_ONE, gl2.GL_ONE_MINUS_SRC_ALPHA);
// Enable alpha blending.
gl2.glEnable(gl2.GL_BLEND);
}
// Enable 2D textures.
gl2.glEnable(gl2.GL_TEXTURE_2D);
// Draw the facets with the texture.
assert (texture_id_[0] != 0);
gl2.glBindTexture(gl2.GL_TEXTURE_2D, texture_id_[0]);
gl2.glInterleavedArrays(gl2.GL_T2F_V3F, 0, vertices);
gl2.glDrawArrays(gl2.GL_QUADS, 0, 4);
// Disable 2D textures.
gl2.glDisable(gl2.GL_TEXTURE_2D);
if (transparent_) {
// Disable alpha blending.
gl2.glDisable(gl2.GL_BLEND);
}
}
示例13: render
import javax.media.opengl.GL2; //導入方法依賴的package包/類
@SuppressWarnings("static-access")
protected void render(GL2 gl2) {
if (use_draw_pixels_ || view_width_ == 0 || view_height_ == 0)
return;
assert(initialized_context_ != null);
final float[] vertex_data = {
//tu, tv, x, y, z
0.0f, 1.0f, -1.0f, -1.0f, 0.0f,
1.0f, 1.0f, 1.0f, -1.0f, 0.0f,
1.0f, 0.0f, 1.0f, 1.0f, 0.0f,
0.0f, 0.0f, -1.0f, 1.0f, 0.0f
};
FloatBuffer vertices = FloatBuffer.wrap(vertex_data);
gl2.glClear(gl2.GL_COLOR_BUFFER_BIT | gl2.GL_DEPTH_BUFFER_BIT);
gl2.glMatrixMode(gl2.GL_MODELVIEW);
gl2.glLoadIdentity();
// Match GL units to screen coordinates.
gl2.glViewport(0, 0, view_width_, view_height_);
gl2.glMatrixMode(gl2.GL_PROJECTION);
gl2.glLoadIdentity();
gl2.glOrtho(0, 0, view_width_, view_height_, 0.1, 100.0);
// Draw the background gradient.
gl2.glPushAttrib(gl2.GL_ALL_ATTRIB_BITS);
gl2.glBegin(gl2.GL_QUADS);
gl2.glColor4f(1.0f, 0.0f, 0.0f, 1.0f); // red
gl2.glVertex2f(-1.0f, -1.0f);
gl2.glVertex2f(1.0f, -1.0f);
gl2.glColor4f(0.0f, 0.0f, 1.0f, 1.0f); // blue
gl2.glVertex2f(1.0f, 1.0f);
gl2.glVertex2f(-1.0f, 1.0f);
gl2.glEnd();
gl2.glPopAttrib();
// Rotate the view based on the mouse spin.
if (spin_x_ != 0)
gl2.glRotatef(-spin_x_, 1.0f, 0.0f, 0.0f);
if (spin_y_ != 0)
gl2.glRotatef(-spin_y_, 0.0f, 1.0f, 0.0f);
if (transparent_) {
// Alpha blending style. Texture values have premultiplied alpha.
gl2.glBlendFunc(gl2.GL_ONE, gl2.GL_ONE_MINUS_SRC_ALPHA);
// Enable alpha blending.
gl2.glEnable(gl2.GL_BLEND);
}
// Enable 2D textures.
gl2.glEnable(gl2.GL_TEXTURE_2D);
// Draw the facets with the texture.
assert(texture_id_[0] != 0);
gl2.glBindTexture(gl2.GL_TEXTURE_2D, texture_id_[0]);
gl2.glInterleavedArrays(gl2.GL_T2F_V3F, 0, vertices);
gl2.glDrawArrays(gl2.GL_QUADS, 0, 4);
// Disable 2D textures.
gl2.glDisable(gl2.GL_TEXTURE_2D);
if (transparent_) {
// Disable alpha blending.
gl2.glDisable(gl2.GL_BLEND);
}
}
示例14: doRoi
import javax.media.opengl.GL2; //導入方法依賴的package包/類
@Override protected void doRoi() {
transformer.transform(srcRoiPts, dstRoiPts, parameters, false);
double[] pts = dstRoiPts.get();
for (int i = 0; i < pts.length; i++) {
pts[i] /= (1<<pyramidLevel);
}
roi.x(0).y(0).width(maskCL[pyramidLevel].width).height(maskCL[pyramidLevel].height);
// Add +3 all around because cvWarpPerspective() needs it for interpolation,
// and there seems to be something funny with memory alignment and
// ROIs, so let's align our ROI to a 16 byte boundary just in case..
JavaCV.boundingRect(pts, roi, 3, 3, 16, 1);
//System.out.println(roi);
inputData.roiX = roi.x();
inputData.roiY = roi.y();
inputData.roiWidth = roi.width();
inputData.roiHeight = roi.height();
// GLContext glContext = context.getGLContext();
// glContext.makeCurrent();
GL2 gl = context.getGL2();
gl.glBindFramebuffer(GL2.GL_FRAMEBUFFER, maskfb[pyramidLevel]);
gl.glMatrixMode(GL2.GL_PROJECTION);
gl.glLoadIdentity();
context.getGLU().gluOrtho2D(0.0f, maskCL[pyramidLevel].width, 0.0f, maskCL[pyramidLevel].height);
gl.glMatrixMode(GL2.GL_MODELVIEW);
gl.glLoadIdentity();
gl.glViewport(0, 0, maskCL[pyramidLevel].width, maskCL[pyramidLevel].height);
gl.glClearColor(0, 0, 0, 0);
gl.glClear(GL2.GL_COLOR_BUFFER_BIT);
gl.glColor4f(1, 1, 1, 1);
gl.glBegin(GL2.GL_POLYGON);
// XXX: Remove "extra" pixels here...
gl.glVertex2d(pts[0], pts[1]);
gl.glVertex2d(pts[2]+1, pts[3]);
gl.glVertex2d(pts[4]+1, pts[5]+1);
gl.glVertex2d(pts[6], pts[7]+1);
gl.glEnd();
// gl.glFinish();
// glContext.release();
}