I am drawing in line mode using glPolygonMode(GL_FRONT_AND_BACK, GL_LINE).
When I draw a polygon using glBegin(GL_POLYGON) I get the following result, see the blue lines:
but when I draw it using glBegin(GL_TRIANGLES) I get the following result, see the blue lines:
I am on Windows 10, on a VMware virtual machine. OpenGL details using glcapsviewer:
OpenGL version: 2.1 Mesa 11.2.0 (git-1d8818d)
Renderer: Gallium 0.4 on SVGA3D; build: RELEASE; LLVM;
What can the issue in using GL_POLYGON mode that I am not getting a closed triangle?
Your polygons don't look convex. OpenGL does allow drawing convex polygons only. If you try otherwise the results are undefined.
Related
I am trying to fit an entire 2D scene of triangles into a window. I am using a shader program to handle drawing the triangles. I only a fraction of the 900 triangles I expect to see. However, when I use the deprecated OpenGL API to draw squares in a similar scene, it works as expected.
It must have somethig to do with the MVP matrix that I am passing into the vertex shader. See the paintGL() method in the scene.cpp module. That is where I setup the glViewport and the mvpMatrix before drawing the triangles.
I have outlined what I have done below.
Tools
Linux
Qt 5.11.1
OpenGL ES
Setup
The scene is 1M x 1M
900 triangles are added to the scene using a shader program
It is a grid of 30 x 30 triangles evenly distributed in the scene
Problem
An attempt was made to fit the entire scene inside the window.
The result was that only 75 out of the 900 triangles are visible in the window.
Here is a screenshot of the triangles demo.
Triangles demo source:
The scene.cpp module contains the paintGL method.
The triangles.cpp module is where the shader program is setup and the triangles are constructed.
The full source to the triangles demo is on github.
What worked
I found that using the deprecated OpenGL API, drawing squares using GL_QUADS, does what I am looking for. However, I would like to be using shaders.
Here is a screenshot of the squares demo. It is a grid of 10 x 10 squares in a 1M x 1M scene.
Squares demo source:
The full source to the squares demo is on github.
I found the bug. It was in triangles.cpp where I was allocating the VBO. I was using the wrong byte count.
Changing:
_vertexBuffer.allocate(_vertexes, _vertexCount);
to:
_vertexBuffer.allocate(_vertexes, _vertexCount * sizeof(QVector3D));
fixed the problem.
I'm trying to write code to draw shapes on my JOGL canvas. I have the canvas on screen, but I can't figure out how to draw shapes. In GL2 examples, I see examples like:
gl.glBegin( GL2.GL_LINES );
gl.glVertex3f( 0.0f,0.75f,0 );
gl.glVertex3f( -0.75f,0f,0 );
gl.glEnd();
However, this doesn't work for me when gl is an instance of GL4 (gl is an instance of GL2 in this example).
OpenGL 3.x Core Profile has deprecated immediate mode statements.
Use vertex arrays or vertex buffers.
I cannot offer an example in JOGL, but in other languages, one of related calls is glDrawArrays(). You'll need to enable and set up the data source arrays before calling glDrawArrays(); if memory serves well, you'll be interested in glEnableClientState(), glVertexPointer() et al.
In Cocos2d-iphone 3.4 I want to draw a bezier curve and be able to manipulate it by dragging points on it.
It looks like in previous versions of Cocos2d I would have used: ccDrawQuadBezier
ccDrawCubicBezier
ccDrawCatmullRom
ccDrawCardinalSpline
These don't appear to be available in Cocos2d 3.4
I've started to learn OpenGL few days ago and I just realised that Quad and Polygons are now deprecated on OpenGL 3.1 or above. The information I found here after having an error on a beginner tutorial which I just wanted to make a change between a triangle to a square. Anyway, instead of use glDrawArrays(GL_TRIANGLE, 0, 3); I changed the code to glDrawArrays(GL_TRIANGLE_FAN, 0, 4); and I got what I wanted. But my questions are:
1 - If triangle fan isnt the best option now a days to draw a simple square what should I use to do it on openGL 3.1 or above?
2 - Why exactly Polygons and Quads became deprecated after a while?
1 - If triangle fan isnt the best option now a days to draw a simple square what should I use to do it on openGL 3.1 or above?
Downside of the triangle-fan approach is you can't render them in batches without getting creative with degenerate triangles or dropping back to indexed rednering and primitive restart.
GL_TRIANGLES lets you keep glDrawArrays() and do large batches at the expense of 2 extra vertices per quad.
2 - Why exactly Polygons and Quads became deprecated after a while?
Quads are decomposed into triangles before rasterization. Khronos just cut out the middleman.
I'm setting up a OpenGL 3.2 Core context on Mac OS X. I want to be able to draw some thick black likes on the screen. In pervious version of OpenGL, I could just set
glLineWidth(10.0f);
and I will get a line 10 pixels wide. However when I check the line width ranges in 3.2 Core
GLint range[2];
glGetIntegerv(GL_ALIASED_LINE_WIDTH_RANGE, range);
glGetIntegerv(GL_SMOOTH_LINE_WIDTH_RANGE, range);
I get the values of 1 for Aliased Lines and 0-1 for Smooth lines. How can I make a line that is 10.0 pixels wide in screen space? Is there a simple way to draw this other than making each line segment a rectangle?
Using OpenGL 3.2 core profile, calling glLineWidth with a value greater than 1.0 give an INVALID_VALUE error (call glGetError to prove it).
Surely you can get the wanted result by determining the quad required for drawing the line.
I think you should be able to generate quads from from line points: hey, a larger line is a quad! Maybe you could use techinques like this to get your wanted result.
The key is: instead of rely on LineWidth, you give a unit quad as input (4 vertices using triangle strip), then transform incoming vertices inside a shader passing to it appropriate uniforms.
Maybe another approach would be rendering using a geometry shader: generate a quad from a point. However, I'm not sure about this point. I don't know if a geometry shader (only if it feasible, of course) would be the best approach: the cost of drawing a line strip using a single quad would be the shader uniform setup for each line composing the strip.
This could be depending on the type of projection you set up. Are you using orthographic or perspective projection matrix?
I think that if you are not using the orthographic projection, the final rasterisation of the primitive will be subject to the distance of the object (model matrix) from the camera (view matrix).
Cheers
Line width > 1.0 is deprecated and not further supported in a core profile OpenGL Context.
However, it is still maintained in a compatibility profile context.
See OpenGL 4.6 API Core Profile Specificatio - E.2.1 Deprecated But Still Supported Features:
The following features are deprecated, but still present in the core profile. They
may be removed from a future version of OpenGL, and are removed in a forwardcompatible context implementing the core profile.
Wide lines - LineWidth values greater than 1.0 will generate an INVALID_VALUE error
For a core profile context possible solutions are presented in the answers to:
OpenGL Line Width
GLSL Geometry shader to replace glLineWidth
Drawing a variable width line in openGL (No glLineWidth)
OpenGL : thick and smooth/non-broken lines in 3D