Results 1 to 3 of 3
Thread: Slow drawing to bufferedImage
- 04-27-2012, 03:39 PM #1
Member
- Join Date
- Apr 2012
- Posts
- 2
- Rep Power
- 0
Slow drawing to bufferedImage
Hello,
I am making a game in java, but I ran into a speed problem. First I thought it was slow
because of graphics2d limitations, now I am using jogl, but the problem still persists.
One thing I noticed that drawImage is taking too long when drawing to bufferedImage (this
takes about ~200ms, only background, ~90 gif images).
Video card is intel hd, but it shouldn't be a problem because I get solid 100+ fps in q3?
Main code where drawing takes place:
Java Code:private Graphics2D g2 = null; private GLCanvas glcanvas = null; private WritableRaster raster = null; private ComponentColorModel colorModel = null; private BufferedImage bi = null; public Game() { raster = Raster.createInterleavedRaster (DataBuffer.TYPE_BYTE, C.SCREEN_WIDTH, C.SCREEN_HEIGHT, 4, null); colorModel= new ComponentColorModel (ColorSpace.getInstance(ColorSpace.CS_sRGB), new int[] {8,8,8,8}, true, false, ComponentColorModel.TRANSLUCENT, DataBuffer.TYPE_BYTE); bi = new BufferedImage (colorModel, raster, false, null); g2 = (Graphics2D) bi.createGraphics(); } public void render() { glcanvas.repaint(); } @Override public void display(GLAutoDrawable gLDrawable) { g2.setColor(Color.BLACK); g2.clearRect(0, 0, C.SCREEN_WIDTH, C.SCREEN_HEIGHT); drawBackground(g2); GL2 gl = gLDrawable.getGL().getGL2(); gl.glMatrixMode(GL2.GL_PROJECTION); gl.glLoadIdentity(); gl.glOrtho(0, C.SCREEN_WIDTH, C.SCREEN_HEIGHT, 0, 0, 1); gl.glMatrixMode(GL2.GL_MODELVIEW); gl.glDisable(GL2.GL_DEPTH_TEST); gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); gl.glClear(GL2.GL_COLOR_BUFFER_BIT); gl.glBlendFunc (GL2.GL_SRC_ALPHA, GL2.GL_ONE_MINUS_SRC_ALPHA); gl.glEnable (GL2.GL_BLEND); g2.drawImage(bi, null, null); DataBufferByte dukeBuf = (DataBufferByte) raster.getDataBuffer(); byte[] dukeRGBA = dukeBuf.getData(); ByteBuffer bb = ByteBuffer.wrap(dukeRGBA); bb.position(0); bb.mark(); gl.glBindTexture(GL2.GL_TEXTURE_2D, 13); gl.glPixelStorei(GL2.GL_UNPACK_ALIGNMENT, 1); gl.glTexParameteri(GL2.GL_TEXTURE_2D, GL2.GL_TEXTURE_WRAP_S, GL2.GL_CLAMP); gl.glTexParameteri(GL2.GL_TEXTURE_2D, GL2.GL_TEXTURE_WRAP_T, GL2.GL_CLAMP); gl.glTexParameteri(GL2.GL_TEXTURE_2D, GL2.GL_TEXTURE_MAG_FILTER, GL2.GL_LINEAR); gl.glTexParameteri(GL2.GL_TEXTURE_2D, GL2.GL_TEXTURE_MIN_FILTER, GL2.GL_LINEAR); gl.glTexEnvf(GL2.GL_TEXTURE_ENV, GL2.GL_TEXTURE_ENV_MODE, GL2.GL_REPLACE); gl.glTexImage2D (GL2.GL_TEXTURE_2D, 0, GL2.GL_RGBA, bi.getWidth(), bi.getHeight(), 0, GL2.GL_RGBA, GL2.GL_UNSIGNED_BYTE, bb); gl.glEnable(GL2.GL_TEXTURE_2D); gl.glBindTexture (GL2.GL_TEXTURE_2D, 13); gl.glBegin (GL2.GL_POLYGON); gl.glTexCoord2d (0, 0); gl.glVertex2d (0, 0); gl.glTexCoord2d(1,0); gl.glVertex2d (bi.getWidth(), 0); gl.glTexCoord2d(1,1); gl.glVertex2d (bi.getWidth(), bi.getHeight()); gl.glTexCoord2d(0,1); gl.glVertex2d (0, bi.getHeight()); gl.glEnd (); gl.glFlush(); } @Override public void init(GLAutoDrawable gLDrawable) { System.out.println("init() called"); GL2 gl = gLDrawable.getGL().getGL2(); gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); gl.glShadeModel(GL2.GL_FLAT); } @Override public void reshape(GLAutoDrawable gLDrawable, int x, int y, int width, int height) { } @Override public void dispose(GLAutoDrawable arg0) { } public void drawBackground(Graphics2D g2) { BufferedImage texture = Images.getImage(1); int tWidth = texture.getWidth(); int tHeight = texture.getHeight(); for (int i = -100; i < C.SCREEN_HEIGHT+tWidth; i+= tHeight/2) { for (int j = -240; j < C.SCREEN_WIDTH + tWidth; j+= tWidth) { g2.drawImage(texture, null, j + i%tHeight*2 - Data.getPlayer().getX()%tWidth, i - Data.getPlayer().getY()%tHeight); } } }
- 04-27-2012, 04:00 PM #2
Re: Slow drawing to bufferedImage
Moved from AWT/Swing.
Painting with partial transparency is known to be slow. No idea how much JOGL can speed that up. How big is this image anyways?Java Code:ComponentColorModel.TRANSLUCENT,
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 04-27-2012, 04:27 PM #3
Member
- Join Date
- Apr 2012
- Posts
- 2
- Rep Power
- 0
Similar Threads
-
Drawing to large BufferedImage, Direct3D pipeline slower then software pipeline?
By neptune296 in forum Java 2DReplies: 0Last Post: 03-23-2012, 10:13 PM -
Problem Drawing Grid with BufferedImage.
By Shikatsu in forum Java 2DReplies: 10Last Post: 11-26-2011, 12:01 AM -
Drawing BufferedImage or Graphics2D to window
By danfoster3141 in forum Java 2DReplies: 6Last Post: 06-16-2011, 02:33 PM -
Slow applet
By robs in forum Java AppletsReplies: 20Last Post: 02-28-2011, 03:15 PM -
creating a BufferedImage from a drawing
By chappa in forum Java 2DReplies: 2Last Post: 01-10-2010, 06:04 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks