OpenGl rotating triangles have some bad effects

I wrote some code to draw 10 yellow triangles on the screen and rotate them for animation. I'll add 2 frames below:frame 1frame 2

This is all very nice, but when I add the number of rectangles to be around 800 I see this:

open gl cannot handle 800 triangles 1...

In the case where I have 500 triangles, I see the following problems:

500 triangles problem 1500 triangles problem 2500 triangles problem 3500 triangles problem 4

As you can see, I don't even have these colors. (I only have black and yellow). In fact, you can see any color there, depending on the number of triangles. I think this is an OpenGL issue. I'm new to OpenGL and I'm guessing I was using something wrong in OpenGL. Here is the code. It's in cocos2d-x (C ++), but you can figure out what is being done here:

Color4F color1e(239.0f / 255, 255.0f / 255, 138.0f / 255, 1);

auto sunNode = DrawNode::create();
sunNode->setContentSize(_size);

int bansCount = 1000;
Vec2 center(_size / 2);

float angleStep = (2 * 3.1415926) / bansCount;

auto rotated = [angleStep, center](float mult) {
Vec2 vc(0, 0);
vc.rotate(center, angleStep * mult);
return vc - center;
};

for(int i = 0; i < bansCount; i+=2) {
   sunNode->drawTriangle(
   Vec2(0,0), // vertex 1
    rotated(i), // vertex 2
    rotated(i + 1), // vertex 3
    color1e // color of vertices
);
}

addChild(sunNode, 2); // add to sceen
sunNode->setPosition(center); // position on center

// infinitely rotate 
sunNode->runAction(RepeatForever::create(RotateBy::create(0.05, 3.1415926 / 10)));

      

The entire code is here, in case anyone wants to look at or experiment: https://github.com/jonyrock/Cocos2dxDrawingArtifacts

+3


source to share


2 answers


The interference pattern is normal, and this is because the edges are quantized (down to a pixel or some fixed subpixel value) and the steps create these interference patterns at a much lower frequency than the step rate itself.

The color is not normal and I can imagine two possibilities:

  • Using desaturated RGB colors and technology like "cleartype" that tries to use separate subpixel intensity values ​​to improve resolution (and this can interact with interference patterns)

  • Mistake



If this is the first case, then using pure red, pure green, or pure blue like

Color4F color1e(255.0f / 255, 0.0f / 255, 0.0f / 255, 1); // Pure red

      

additional colors should not be entered.

+3


source


The patterns you see are clearly the result of a pattern you are trying to make, with finer structure than the display can allow (i.e. you are violating the so-called Nyquist limit). This leads to the so-called "aliasing moare". The colors you see may be the result of mixing artifacts in the anti-aliasing pattern, or if anti-aliasing is enabled by bleeding blood vessels into subpixels (where the pixel structure of the monitor is used to artificially increase the resolution). In any case, the problem arises because your template has a higher spatial resolution than the target framebuffer can resolve.



0


source







All Articles