注册 | 登录

java - opengl / JOGL - best way to draw textures

itPublisher 分享于



推荐:你好,JOGL - Java与OpenGl的绑定

    在这篇文章里,摘录了《学习Java对于OpenGl的绑定》。作者吉恩戴维斯解释了如何开始用Java对于OpenGl的绑定开发图形增强的程序 这些年来,为了创建一个图形

I thought about the best way to draw a picture in OpenGL / JOGL. I currently program a Game and it is my goal to save the information about a picture in a text file instead of saving the picture. My idea was to program a method that saves every pixel information (RGB) at the position of X and Y. Then I draw every pixel and it is finished.

What you think about that idea?

java opengl textures draw jogl
  this question
asked Jul 13 '14 at 10:42 user3151285 8 4      What do you want to achieve here? Directly writing pixels into the framebuffer is the opposite of what opengl is for, and it will result in a really low performance if you actually emulate this functionality with GL. –  derhass Jul 13 '14 at 12:36


1 Answers

You should simply use TextureIO to make a texture from your picture and use this texture with 4 vertices that have some texture coordinates while drawing. glReadPixels() is very slow, reading each pixel of a picture would take a lot of time, saving its content as a text file would require a lot of memory (saving it as a compressed image in a loss-less format like PNG might be worth a try), drawing each pixel one by one would be a lot slower than drawing a texture. derhass is right. You could vectorize your picture (make a SVG from it) but you would have to rasterize it after or you would have to implement some rendering of vectorized contents and it would be probably slower than using a texture. I'm not sure you really need an offscreen buffer.

I had a similar problem when I began working on my first person shooter. I wasn't using JOGL at the very beginning, I reused the source code of someone else, it relied on software rendering in an image, it was very slow. Then, I used JOGL to draw each pixel one by one instead of using Java2D, it was about 4 times faster on my machine but still very slow for me. At the end, I had to redesign the whole rendering to use OpenGL for what it is for as derhass would say, I used triangles, quads and textures. The performance became acceptable and this is what you should do, use OpenGL to draw primitives and clarify what you're trying to achieve so that we can help you a bit better.


开发环境:XP + eclipse + JOGL 第一步:到  下载 解压缩到随意文件夹里,如:C:/Program

  this answer
answered Jul 14 '14 at 10:44 gouessej 2,279 1 18 31



有人会问:以前都用eclipse作为JOGL的开发工具,为什么忽然要用NetBeans呢? 看看下面图片:  很明显,,你们看到的不是JFrame运行以后的效果,而是类似于VC++6.








您的注册邮箱: 修改

重新发送激活邮件 进入我的邮箱