0
\$\begingroup\$

I have an image (100×200 px) painted with Paint.NET and saved as a .png with 32-bit color depth. How can I render it using OpenGL 1.1 (with the LWJGL binding) or higher inside the display?

I tried creating a ByteBuffer, then loading the pixel color values inside that buffer, but I'm missing the OpenGL settings that need to be enabled. Some help?

\$\endgroup\$
  • \$\begingroup\$ As far as I know, you can't render a 100*200 image. Try 128*256 instead. \$\endgroup\$ – KaareZ Jul 15 '15 at 20:00
  • \$\begingroup\$ So you mean only base 2 resolutions? \$\endgroup\$ – user51054 Jul 15 '15 at 20:05
  • \$\begingroup\$ @BlackHamm3rJack They're called power-of-two textures. But they also must be squared, 128x256 is not squared. The common resolutions are 2x2, 4x4, 16x16, 32x32, 64x64, 128x128, 256x256, 512x512, 1024x1024, and 2048x2048. Not all graphics devices support larger resolutions, though. \$\endgroup\$ – LiquidFeline Jul 15 '15 at 20:21
  • \$\begingroup\$ Forgot to mention, some graphics devices support non-power-of-two textures. Some convert to power-of-two at run-time. It's just that some don't support them at all. \$\endgroup\$ – LiquidFeline Jul 15 '15 at 20:24
  • \$\begingroup\$ But why just power of two textures? What differs? \$\endgroup\$ – user51054 Jul 15 '15 at 20:27
1
\$\begingroup\$

First, this question is about asking for a tutorial, and as far as i know googling "opengl tutorial" is enough to get you started. Second, i don't recommend you to use such an old version of opengl, even if you want to support an extremely large range of computers, the 'modern opengl' (a.k.a. Opengl 3.0+) is widely supperted as well. And imho learning opengl 1 is useless for any intermediate complexity project, because it lacks of many essential features (see framebuffer objects).

That said, if you give up with gl1, non power of two textures will be fully supperted on every machine.

Here I want to give you a fair starting point to solve your actual problem (this is not for lwjgl, though, and I assume gl3+ with shaders):

In opengl you don't render textures, you render geometry, so you have to draw a quad with the proportions of your textures. To do this, feed a buffer with the data of this specific geometry and draw it. Now it's time of shaders, you will need a vertex and a fragment shader, where you actually sample a texture object created before to output your quad filled with your texture.

Now, you are aware that with only what i wrote, you can't do anything, because all the details that you need to write a working program are missing, so http://bfy.tw/qKL

\$\endgroup\$
  • \$\begingroup\$ I was using OpenGL 1.1 just because LWJGL tutorials used that, not because i need to support a wide range of systems. By the way... I'll start woth modern OpenGL so... \$\endgroup\$ – user51054 Jul 16 '15 at 10:49
  • \$\begingroup\$ That's your best option, and btw I started with lwjgl too, and in their docs there are some insights for gl3 :) \$\endgroup\$ – DI2edd Jul 16 '15 at 11:50
  • \$\begingroup\$ I wouldnt learn legacy GL ever, if you dont want to learn modern GL use a wrapper library. \$\endgroup\$ – Khlorghaal Jul 16 '15 at 13:12
  • \$\begingroup\$ "Rendering is the process of generating an image from a 2D or 3D model"-wiki Textures are part of that process, "rendering a texture" isnt an invalid thing to say. \$\endgroup\$ – Khlorghaal Jul 16 '15 at 13:15
  • \$\begingroup\$ Well, a texture isn't a model, so I wouldn't say "render a texture", but this is not the point of the question \$\endgroup\$ – DI2edd Jul 16 '15 at 13:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy