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):
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:
Is this really so hard or am I missing some very important points here?
What OpenGL 4 features should I know, to be able to do what I've explained?
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)?
Related
Ive been trying to make my own PNG reader in C and ive gotten to the point where it works normally but I want to try and expand its support. I noticed that while uncommon, interlaced png's do exist. Now, I want the goal of my reader simply to return an array of rgba values cooresponding to each pixel in top left to bottom right order. I would not be creating or displaying any pngs.
based on what i saw on the wikipedia for Adam7 Interlacing (the type pngs use) i would most have to add support for it by organizing the final array according to Adam7. However, when I reviewed the Interlacing and Progressive Display section of libpng (one of the sources i was using), it stated:
Note that, although I've described the method in terms of 8 × 8 tiles, pixels for any given pass are stored as complete rows, not as tiled groups. For example, the fifth pass consists of every other pixel in the entire third row of the image, followed by every other pixel in the seventh row, and so on.
This makes it seem as though the interlacing is meat for the program in which displays it to use, rather than the information itself being stored using the Adam7 Algorithm.
My question now is, If im not displaying the png, does interlacing matter? And if so, could someone provide an example of how to uninterlace the information? Because this aspect still confuses me.
I have a set of pages that look like this:
I have the content in grids with * Heights and Widths so the grid correctly scales when the entire window resizes. I would like the text to resize with the grid. Basically I would like the user to resize from this:
To this:
(preserving white space)
One way to do this would be to wrap the TextBlock in a ViewBox with margins on the right and bottom (for Grid.Row="3") to account for white space. But because I have several pages with different lengths and line counts I would have to set the margin specifically for each page otherwise the text sizes would differ on each page. Is there a better way to do this??
I don't think there is a better way to do this. There are different ways. But, I think it isn't just a matter of opinion that they would not be better.
Ways I can think of.
Render your text offscreen, rendertargetbitmap that so you've got a picture. Change your textblocks on screen to images and stretch them.
Or
Work out the size your text wants to be. Then do some calculation comes up with a different fontsize which is "better". This is a lot easier to write a description of than do.
In my opinion.
A viewbox is easier to implement. Way less error prone than calculations. Will give at least as good results as rendering to a picture.
I just want to add one more solution to the ones suggested by Andy, which is more of a scientific approach and takes a bit of practice to master.
Suppose you have to find a function F, which maps one or more variables to a desired single value. In your case that would be a function F, which takes aspect ratio of the window as input and outputs an appropriate font size.
How can you find such a function?
Well... you don't need to do any math yourself!
First, you need some data to begin with:
1. Resize the window randomly
2. Calculate aspect ration (X)
3. Pick an appropriate font size that looks good enough (Y)
4. Repeat the measurement 7 to 10 times (sorry data scientists)
5. Enter the data in Excel - one column for X and another one for Y
6. Insert a scatter chart
7. Choose the best trendline for your data, but avoid the polynomial one
8. Display the trendline equation and use the expression in your code
Now I should mention the pros and cons of this regression technique.
Pros:
1. It can solve a wide range of tricky problems:
"I use this 3rd party control, but when the text is too long it overlaps the title bar. How to trim it so it doesn't go beyond the top border?. Deadline is coming!"
2. Even if it doesn't solve the problem perfectly, the results are often acceptable
3. It takes minutes to try out unlike spending a day refreshing your math skills
Cons:
1. The biggest problem is that to keep it simple, you often lower the number of
variables by assuming some of them to be constant. In this post I've assumed that
the font family won't change for example, neither the font weight.
2. If any of the assumptions does not hold the final result could be even worse
This technique is fragile, but powerful. Use it as your last weapon and never leave magic expression like
fontSize = (int)(0.76 + 1.2 * aspectRation) without documenting how it came to be.
Sorry for my unspecific title (as well as my tags), I just didn't know how to describe that problem in one sentence.
I think its trivial, however my mind is blocked somehow right now.
Some surface is arbitrarliy tiled into smaller subsurfaces (4x4 in this case).
Now I want every subsurface to be assigned an individual index using the width and height of a subsurface (both=9 in this case) and the coordinates Y,Z, so that
Index=...Y*Z+Z...?
I am trying to write a PCL document, which has several drawing objects (lines, rectangles, texts...)
I found that if I draw the rectangles before anything else, they appear in the right position and size. However, if I draw them among the rest of objects, they are drawn smaller and in the wrong place.
The PCL seems to be OK (although this is yet to be proven), but it has made me think that perhaps graphic objects must be drawn in a particular order (I am using HPGL/2, by the way).
Does someone know if this is so? I have not been able to find anything in the PCL Manual nor in the internet (which leads me to believe that there is not such drawing order).
Perhaps you have written position or scale commands that unintentionally affect your rectangles.
In a 3D scene we often need to apply labels (little textelements or icons) next to 3D object that is moving around (rotation, translation) in the scene. These labels should always face the camera but still move with the object. This technique I believe is called billboard.
An additional cool feature would be if the label would stay always at the same size - no matter how far away the associated object is. So the label seems to live in 2D screenspace and not in the 3D scenegraph.
Does anyone figures out a clever way how to do this in WPF?
For billboarding you need to make sure that the face normal is pointing towards the camera. The algorithm is that the dot product between the face normal and the view direction should be -1 (minus one).
I have some old C code that does this, but it's probably not particularly useful.
For keeping the object the same size you'd need to work out the screen size and then apply a transform to keep it the constant size you desired.
However, if you want the object to appear as though it's in 2D space, why not draw it in a 2D overlay? This will solve both the billboarding and scaling problem at the same time. You work out the screen location of your label and then use the 2D drawing functions.