ITKeyword,专注技术干货聚合推荐

注册 | 登录

java - opengl / JOGL - best way to draw textures

itPublisher 分享于

2021腾讯云限时秒杀,爆款1核2G云服务器298元/3年!(领取2860元代金券),
地址https://cloud.tencent.com/act/cps/redirect?redirect=1062

2021阿里云最低价产品入口+领取代金券(老用户3折起),
入口地址https://www.aliyun.com/minisite/goods

推荐:你好,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
1

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.

推荐:JAVA的OPENGL,JOGL入门例子----碰撞移动的正方体

开发环境:XP + eclipse + JOGL 第一步:到https://jogl.dev.java.net/  下载 jogl-1.1.2-pre-20080523-windows-i586.zip 解压缩到随意文件夹里,如:C:/Program


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

 | 

推荐:JAVA的OPENGL:JOGL入门例子(六)---NetBeans可视化与JOGL结合

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


相关阅读排行


相关内容推荐

最新文章

×

×

请激活账号

为了能正常使用评论、编辑功能及以后陆续为用户提供的其他产品,请激活账号。

您的注册邮箱: 修改

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

如果您没有收到激活邮件,请注意检查垃圾箱。