0

Let's imagine such array:

[0,0,0,1,1,0,0,0]
[0,0,1,0,0,1,0,0]
[0,1,0,0,0,0,1,0]
[0,1,0,0,0,0,1,0]
[0,0,1,0,0,1,0,0]
[0,0,0,1,1,0,0,0]

Since this array is of size 8x6, I'd like to divide the width of my window by 8, and height by 6, and then represent every '1' in the array as some color rectangle and every '0' as nothing (background color). Just like in this example (without split lines, of course):

picture

I was able to draw everything I wanted, only missing thing was to how to split my window accordingly and draw bigger boxes. Then, I found out that I'm using old OpenGL API.

I'm looking for the answer to these questions:

  1. Is this really so hard or am I missing some very important points here?
  2. What OpenGL 4 features should I know, to be able to do what I've explained?
  3. Are you aware of some docs/tutorials/books in C (I simply don't know/like C++), which covers such or similar examples for OGL4 (or at least OGL3)?
genpfault
  • 51,148
  • 11
  • 85
  • 139
kashpersky
  • 165
  • 2
  • 8
  • 1
    Why not upload as a texture? – Dietrich Epp Dec 19 '16 at 18:00
  • 1
    Question 1 is un-answerable, as nobody knows what you already have and haven't done. "hard" is also very subjective. Question 2 is easy to answer. though: none. OpenGL 3 is enough. OpenGL 4 will not change the picture, it will just add more possibilites. Question 3: no idea. – derhass Dec 19 '16 at 18:03
  • @DietrichEpp I'm constantly changing this array. – kashpersky Dec 19 '16 at 18:05
  • 3
    @kashpersky: and? since the data does influence the intended display output, it has to be transfered to the GPu at some point anyway, in one form or another – derhass Dec 19 '16 at 18:06
  • @derhass and it looks like I'm not right what is the texture in opengl world. – kashpersky Dec 19 '16 at 18:09
  • @derhass Ok, I glanced at this https://open.gl/textures and it is very promising. The last thing is how to split my window accordingly. Will I learn this while learning about textures or it is a different topic? If latter, can you point to the right topic? – kashpersky Dec 19 '16 at 18:19
  • Well, I don't know what you mean by "splitting the window". If you just map your texture to a full screen quad, you will get the texels as big, and you can use the fragment shader to properly color each block based on the contents of your texture. – derhass Dec 19 '16 at 18:47
  • Simply if you use that array as 2D texture then the only thing you need is propperly set the wrap parameters of textures my bet is you want `GL_NEAREST` ... btw OpenGL 1.0 is enough for this. Anyway if you want use that array as uniform (no texture) then you just need to round/trunc the resulting coordinates to the square size ... Hard to say more without any code you use for this.... We do not even know if you doing this on GPU or on CPU side ... in form of shader or rendering geometru etc .... – Spektre Dec 20 '16 at 08:44
  • @Spektre It would be easier for you if some moderator wouldn't have removed my sentence saying that I compiled first ever opengl program 4 days ago... I'm on "hello triangle" level. I'd like to not use OpenGL 1.0 since this is old. Sadly, I have almost completely no idea what you are derhass are talking about, so I'm simply continue in reading more tutorials until the point I will. – kashpersky Dec 20 '16 at 23:04
  • 1
    @kashpersky you can render this as set of colored quads generated from your array on CPU side as VBO/VAO ... or render single Quad covering whole screen and compute individual color of each pixel/fragment from your array on fragment shader (GPU) side or render the whole screen as single textured QUAD the choice is yours – Spektre Dec 21 '16 at 15:33
  • 1
    @kashpersky btw take a look at this [simple complete GL+GLSL+VAO/VBO C++ example](http://stackoverflow.com/a/31913542/2521214) in case you need further help with getting started. – Spektre Dec 21 '16 at 15:42

0 Answers0