当前位置: 首页>>代码示例>>Java>>正文


Java GLContext类代码示例

本文整理汇总了Java中javax.media.opengl.GLContext的典型用法代码示例。如果您正苦于以下问题:Java GLContext类的具体用法?Java GLContext怎么用?Java GLContext使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


GLContext类属于javax.media.opengl包,在下文中一共展示了GLContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: dispose

import javax.media.opengl.GLContext; //导入依赖的package包/类
public void dispose() {
	if (vertices != null) {
		vertices.clear();
	}
	vertices = null;
	
	if (points != null)
		points.clear();
	points = null;

	subImage = null;

	if (texture != null) {
		GLContext context = ww.getSceneController().getDrawContext().getGLContext();

		int i = context.makeCurrent();
		if (i == GLContext.CONTEXT_CURRENT) {
			((Disposable) texture).dispose();
			context.release();
		} else
			System.err.println("Could not make GLContext current");
	}
	texture = null;
}
 
开发者ID:iedadata,项目名称:geomapapp,代码行数:25,代码来源:FenceDiagram.java

示例2: renderPlanetPaths

import javax.media.opengl.GLContext; //导入依赖的package包/类
public void renderPlanetPaths( GLCanvas canvas, Simulation sim, Planet planet )
{
	if( planet == null )
		return;
	
	GL gl = GLContext.getCurrent().getGL();
	
	gl.glEnable( GL.GL_BLEND );
	gl.glBegin( GL.GL_LINES );	
	gl.glColor4f( 0.3f, 0.3f, 0.7f, 1 );
	for( int id: planet.getReachablePlanets() )
	{
		Planet p = sim.getPlanet( id );
		tmp.set(p.getPosition()).sub(planet.getPosition()).nor();
		gl.glVertex2f( planet.getPosition().x + tmp.x * planet.getRadius(), planet.getPosition().y + tmp.y * planet.getRadius() );
		gl.glVertex2f( p.getPosition().x + tmp.x * -p.getRadius(), p.getPosition().y + tmp.y * -p.getRadius() );
	}
	gl.glEnd();
	gl.glDisable( GL.GL_BLEND );	
	
	planet.renderMesh( canvas, 0.9f, 0.7f, 0.7f, 1, circle );
	
}
 
开发者ID:weimingtom,项目名称:quantum-game,代码行数:24,代码来源:Renderer.java

示例3: renderPlanetPathsLight

import javax.media.opengl.GLContext; //导入依赖的package包/类
public void renderPlanetPathsLight( GLCanvas canvas, Simulation sim, Planet planet )
{
	if( planet == null )
		return;
	
	GL gl = GLContext.getCurrent().getGL();
	
	gl.glEnable( GL.GL_BLEND );
	gl.glLineWidth( 1 );
	gl.glBegin( GL.GL_LINES );		
	gl.glColor4f( 0.1f, 0.1f, 0.1f, 1 );
	for( int id: planet.getReachablePlanets() )
	{
		Planet p = sim.getPlanet( id );
		tmp.set(p.getPosition()).sub(planet.getPosition()).nor();
		gl.glVertex2f( planet.getPosition().x + tmp.x * planet.getRadius(), planet.getPosition().y + tmp.y * planet.getRadius() );
		gl.glVertex2f( p.getPosition().x + tmp.x * -p.getRadius(), p.getPosition().y + tmp.y * -p.getRadius() );
	}		
	gl.glEnd();
	gl.glLineWidth( 1.5f );
	gl.glDisable( GL.GL_BLEND );				
	
}
 
开发者ID:weimingtom,项目名称:quantum-game,代码行数:24,代码来源:Renderer.java

示例4: renderFullScreenQuad

import javax.media.opengl.GLContext; //导入依赖的package包/类
public void renderFullScreenQuad( )
{
	GL gl = GLContext.getCurrent().getGL();		
	gl.glMatrixMode(GL.GL_PROJECTION);
	gl.glPushMatrix();
	gl.glLoadIdentity();
	gl.glMatrixMode(GL.GL_MODELVIEW);
	gl.glPushMatrix();
	gl.glLoadIdentity();
	bindTexture(0);
	gl.glBegin(GL.GL_QUADS );
		gl.glTexCoord2f( 0, 0 );
		gl.glVertex2f( -1f, -1f );
		gl.glTexCoord2f( 1, 0 );
		gl.glVertex2f( 1f, -1f );
		gl.glTexCoord2f( 1, 1 );
		gl.glVertex2f( 1f, 1f );
		gl.glTexCoord2f( 0, 1 );
		gl.glVertex2f( -1f, 1f );
	gl.glEnd();
	unbindTexture();
	gl.glMatrixMode(GL.GL_PROJECTION);
	gl.glPopMatrix();		
	gl.glMatrixMode(GL.GL_MODELVIEW);
	gl.glPopMatrix();
}
 
开发者ID:weimingtom,项目名称:quantum-game,代码行数:27,代码来源:FrameBufferObject.java

示例5: renderFullScreenQuadNearest

import javax.media.opengl.GLContext; //导入依赖的package包/类
public void renderFullScreenQuadNearest( )
{
	GL gl = GLContext.getCurrent().getGL();		
	gl.glMatrixMode(GL.GL_PROJECTION);
	gl.glPushMatrix();
	gl.glLoadIdentity();
	gl.glMatrixMode(GL.GL_MODELVIEW);
	gl.glPushMatrix();
	gl.glLoadIdentity();
	texture.bind(0, GL.GL_NEAREST, GL.GL_NEAREST, GL.GL_CLAMP_TO_EDGE, GL.GL_CLAMP_TO_EDGE );
	gl.glBegin(GL.GL_QUADS );
		gl.glTexCoord2f( 0, 0 );
		gl.glVertex2f( -1f, -1f );
		gl.glTexCoord2f( 1, 0 );
		gl.glVertex2f( 1f, -1f );
		gl.glTexCoord2f( 1, 1 );
		gl.glVertex2f( 1f, 1f );
		gl.glTexCoord2f( 0, 1 );
		gl.glVertex2f( -1f, 1f );
	gl.glEnd();
	unbindTexture();
	gl.glMatrixMode(GL.GL_PROJECTION);
	gl.glPopMatrix();		
	gl.glMatrixMode(GL.GL_MODELVIEW);
	gl.glPopMatrix();
}
 
开发者ID:weimingtom,项目名称:quantum-game,代码行数:27,代码来源:FrameBufferObject.java

示例6: getInfoLog

import javax.media.opengl.GLContext; //导入依赖的package包/类
public String getInfoLog( int object )
{
	String text = "";
	GL gl = GLContext.getCurrent().getGL();
			
	int len[] = new int[1];
	gl.glGetObjectParameterivARB( object, GL.GL_INFO_LOG_LENGTH, len, 0 );
	
	if( len[0] > 0 )
	{			
		byte[] bytes = new byte[len[0]];
		gl.glGetInfoLogARB( object, len[0], len, 0, bytes, 0 );
		text = new String( bytes );
	}
	
	return text;
}
 
开发者ID:weimingtom,项目名称:quantum-game,代码行数:18,代码来源:Shader.java

示例7: dispose

import javax.media.opengl.GLContext; //导入依赖的package包/类
public void dispose( )
{
	GL gl = GLContext.getCurrent().getGL();
	if( vertex_shader != -1 )
	{
		gl.glDetachObjectARB( program, vertex_shader );
		gl.glDeleteObjectARB( vertex_shader );
	}
	if( fragment_shader != -1 )
	{
		gl.glDetachObjectARB( program, fragment_shader );
		gl.glDeleteObjectARB( fragment_shader );
	}
	
	gl.glDeleteObjectARB( program );
}
 
开发者ID:weimingtom,项目名称:quantum-game,代码行数:17,代码来源:Shader.java

示例8: update

import javax.media.opengl.GLContext; //导入依赖的package包/类
public void update( int width, int height )
{		
	this.width = width;
	this.height = height;
	
	proj.setToOrtho2D(0, 0, (width * scale), (float)(height * scale), near, far );
	model.idt();
	model.setToTranslation( new Vector( (float)(-pos.getX() + (width / 2) * scale), (float)(-pos.getY() + (height / 2) * scale), (float)(-pos.getZ()) ) );
	combined.set( proj );
	combined.mul( model );
				
	GL gl = GLContext.getCurrent().getGL();
	gl.glMatrixMode( GL.GL_PROJECTION );
	gl.glLoadIdentity();
	gl.glMatrixMode( GL.GL_MODELVIEW );
	gl.glLoadMatrixf(combined.toFloatBuffer());		
}
 
开发者ID:weimingtom,项目名称:quantum-game,代码行数:18,代码来源:OrthoCamera.java

示例9: dispose

import javax.media.opengl.GLContext; //导入依赖的package包/类
/**
 * diposes the texture, does not unbind it
 */
public void dispose( )
{
	IntBuffer buffer = IntBuffer.allocate(1);
	buffer.put( textureID );
	buffer.flip();
	try
	{
		GLContext.getCurrent().getGL().glDeleteTextures( 1, buffer );
		Log.println( "[Texture] disposed texture " + this.getWidth() + "x" + this.getHeight()  );
		texture_count--;
	}
	catch( Exception ex )
	{
		Log.println( "[Texture] couldn't dispose texture: " + Log.getStackTrace( ex ) );
	}    	
}
 
开发者ID:weimingtom,项目名称:quantum-game,代码行数:20,代码来源:Texture.java

示例10: loadTexture

import javax.media.opengl.GLContext; //导入依赖的package包/类
/**
 * Load a texture into OpenGL from a image reference on
 * disk.
 *
 * @param resourceName The location of the resource to load
 * @param target The GL target to load the texture against
 * @param dstPixelFormat The pixel format of the screen
 * @param minFilter The minimising filter
 * @param magFilter The magnification filter
 * @return The loaded texture
 * @throws IOException Indicates a failure to access the resource
 */
private static Texture loadTexture(BufferedImage bufferedImage, int dstPixelFormat ) 
{ 
		GL gl = GLContext.getCurrent().getGL();
     int srcPixelFormat = 0;	        
     int textureID = createTextureID(); 
     Texture texture = new Texture(textureID); 	        
     gl.glBindTexture( GL.GL_TEXTURE_2D, textureID); 
	 
     texture.width = bufferedImage.getWidth();
     texture.height = bufferedImage.getHeight();
     
     if (bufferedImage.getColorModel().hasAlpha()) 
         srcPixelFormat = GL.GL_RGBA;
     else 
         srcPixelFormat = GL.GL_RGB;
     
	
     ByteBuffer textureBuffer = convertImageData(bufferedImage,texture); 	        
     new GLU().gluBuild2DMipmaps( GL.GL_TEXTURE_2D, dstPixelFormat, get2Fold( bufferedImage.getWidth()), get2Fold( bufferedImage.getHeight()), srcPixelFormat, GL.GL_UNSIGNED_BYTE, textureBuffer);
     Log.println( "[Texture] created texture " + bufferedImage.getWidth() + "x" + bufferedImage.getHeight() );
     texture_count ++;
     return texture; 
}
 
开发者ID:weimingtom,项目名称:quantum-game,代码行数:36,代码来源:Texture.java

示例11: renderOutlinedQuad

import javax.media.opengl.GLContext; //导入依赖的package包/类
public static void renderOutlinedQuad( float x, float y, float width, float height )
{
	GL gl = GLContext.getCurrent().getGL();
	gl.glPolygonMode( GL.GL_FRONT_AND_BACK, GL.GL_LINE );
	gl.glBegin( GL.GL_LINES );
	gl.glVertex2f( x, y );
	gl.glVertex2f( x + width, y );
	gl.glVertex2f( x + width, y );
	gl.glVertex2f( x + width, y - height);
	
	gl.glVertex2f( x + width, y - height);
	gl.glVertex2f( x, y - height);
	
	gl.glVertex2f( x, y - height);
	gl.glVertex2f( x, y );
	
	gl.glEnd();
	gl.glPolygonMode( GL.GL_FRONT_AND_BACK, GL.GL_FILL );
}
 
开发者ID:weimingtom,项目名称:quantum-game,代码行数:20,代码来源:Widget.java

示例12: setup

import javax.media.opengl.GLContext; //导入依赖的package包/类
private static void setup( GLCanvas glcanvas, GLContext glcontext ) {
    Rectangle rectangle = glcanvas.getClientArea();

    glcanvas.setCurrent();
    glcontext.makeCurrent();

    GL2 gl = glcontext.getGL().getGL2();
    gl.glMatrixMode( GL2.GL_PROJECTION );
    gl.glLoadIdentity();

    // coordinate system origin at lower left with width and height same as the window
    GLU glu = new GLU();
    glu.gluOrtho2D( 0.0f, rectangle.width, 0.0f, rectangle.height );

    gl.glMatrixMode( GL2.GL_MODELVIEW );
    gl.glLoadIdentity();

    gl.glViewport( 0, 0, rectangle.width, rectangle.height );
    glcontext.release();
}
 
开发者ID:momega,项目名称:spacesimulator,代码行数:21,代码来源:Main.java

示例13: render

import javax.media.opengl.GLContext; //导入依赖的package包/类
private static void render( GLCanvas glcanvas, GLContext glcontext ) {
    Rectangle rectangle = glcanvas.getClientArea();

    glcanvas.setCurrent();
    glcontext.makeCurrent();

    GL2 gl = glcontext.getGL().getGL2();
    gl.glClear( GL.GL_COLOR_BUFFER_BIT );

    // draw a triangle filling the window
    gl.glLoadIdentity();
    gl.glBegin( GL.GL_TRIANGLES );
    gl.glColor3f( 1, 0, 0 );
    gl.glVertex2f( 0, 0 );
    gl.glColor3f( 0, 1, 0 );
    gl.glVertex2f( rectangle.width, 0 );
    gl.glColor3f( 0, 0, 1 );
    gl.glVertex2f( rectangle.width / 2, rectangle.height );
    gl.glEnd();

    glcanvas.swapBuffers();
    glcontext.release();
}
 
开发者ID:momega,项目名称:spacesimulator,代码行数:24,代码来源:Main.java

示例14: reshape

import javax.media.opengl.GLContext; //导入依赖的package包/类
@Override
public void reshape(GLAutoDrawable drawable, int x, int y, int w, int h) {
    // Get the Opengl context from the drawable, and make it current, so
    // we can see it and draw on it. I've never seen this fail, but there is
    // error checking anyway.
    contextOn(drawable);

    // Once we have the context current, we can extract the OpenGL instance
    // from it. We have defined a OpenGL 3.0 instance in the
    // NeonNewtWindow by adding the line
    // "glp = GLProfile.get(GLProfile.GL3);"
    // Therefore, we extract a GL3 instance, so we cannot make any
    // unfortunate mistakes (calls to methods that are undefined for this
    // version).
    final GL3 gl = GLContext.getCurrentGL().getGL3();

    // set the new canvas size and aspect ratio in the global variables.
    canvasWidth = GLContext.getCurrent().getGLDrawable().getWidth();
    canvasHeight = GLContext.getCurrent().getGLDrawable().getHeight();
    setAspect((float) canvasWidth / (float) canvasHeight);

    // Release the context.
    contextOff(drawable);
}
 
开发者ID:NLeSC,项目名称:Neon,代码行数:25,代码来源:HelloWorldGLEventListener.java

示例15: reshape

import javax.media.opengl.GLContext; //导入依赖的package包/类
@Override
public void reshape(GLAutoDrawable drawable, int x, int y, int w, int h) {
    // Get the Opengl context from the drawable, and make it current, so
    // we can see it and draw on it. I've never seen this fail, but there is
    // error checking anyway.
    contextOn(drawable);

    // Once we have the context current, we can extract the OpenGL instance
    // from it. We have defined a OpenGL 3.0 instance in the
    // NeonNewtWindow by adding the line
    // "glp = GLProfile.get(GLProfile.GL3)"
    // Therefore, we extract a GL3 instance, so we cannot make any
    // unfortunate mistakes (calls to methods that are undefined for this
    // version).
    final GL3 gl = GLContext.getCurrentGL().getGL3();

    // set the new canvas size and aspect ratio in the global variables.
    canvasWidth = GLContext.getCurrent().getGLDrawable().getWidth();
    canvasHeight = GLContext.getCurrent().getGLDrawable().getHeight();
    setAspect((float) canvasWidth / (float) canvasHeight);

    // Release the context.
    contextOff(drawable);
}
 
开发者ID:NLeSC,项目名称:Neon,代码行数:25,代码来源:RealisticEarthGLEventListener.java


注:本文中的javax.media.opengl.GLContext类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。