## Archive Pages Design\$type=blogging

Looking for the code to draw triangles in OpenGL C++ Computer graphics, here we give full source code with explanation.

To draw a triangle in opengl  we just need to use simple primitive functions. There are many ways you can draw but using primitive function is one of easy method. In this post we are going to draw few triangles using the different primitive functions defined in OpenGL graphics Library.

One of the blog reader requested to have the code for Triangle. Hence to help and all other reader in this post we going to see many types of triangles. We are going to have full source code with explanation. So get the code and spread the knowledge, don't forget to tell other and share the post.

### Draw First Type of Triangle in OpenGL

Here we are going to use the GL_TRINAGLES and glVertex() to draw our triangle in a simple manner. Her we have drawn two triangles -red and white, both as right angled triangle. You can change the vertexes to make others varities of Triangle.

#include "glut.h"

void Display(void)
{
glClear(GL_COLOR_BUFFER_BIT);

glBegin(GL_TRIANGLES);
glColor3f(1,1,1);
glVertex3f(0,0,0);
glVertex3f(-1,0,0);
glVertex3f(0,1,0);

glColor3f(1,0,0);
glVertex3f(0,0,0);
glVertex3f(1,0,0);
glVertex3f(0,-1,0);
glEnd();

glFlush();
}

int main(void)
{
glutCreateWindow("MY Triangle");
glutDisplayFunc(Display);
glutMainLoop();
return 0;
}

#### Draw Striped Triangle in OpenGL C++

You may have heard about the Strip triangles, now we are going to see it. Just as in above are using glVertex() but this time GL_TRIANGLE_STRIP.

#include "glut.h"

void Display(void)
{
glClear(GL_COLOR_BUFFER_BIT);

glBegin(GL_TRIANGLE_STRIP);
glVertex3f(0,0,0);
glVertex3f(1,0,0);
glVertex3f(0,1,0);
glVertex3f(0.9,0.9,0);
glVertex3f(1,-1,0);
glEnd();

glFlush();
}

int main(void)
{
glutCreateWindow("MY STRIP TRIANGLE");
glutDisplayFunc(Display);
glutMainLoop();
return 0;
}

### Draw Triangle Fan in OpenGL

Now its time to Draw a Triangle Fan. You might have seen this as used in our Nuclear Power Plant Project in OpenGL, where the turbine have it.

#include "glut.h"

void Display(void)
{
glClear(GL_COLOR_BUFFER_BIT);

glBegin(GL_TRIANGLE_STRIP);
glVertex3f(0,0,0);
glVertex3f(1,0,0);
glVertex3f(0,1,0);
glVertex3f(-1,0,0);
glVertex3f(-1,-1,0);
glEnd();

glFlush();
}

int main(void)
{
glutCreateWindow("Triangle Fans");
glutDisplayFunc(Display);
glutMainLoop();
return 0;
}

Name

3D Bi-Cycle 3D Game 3D Laptop 3D Objects 3D Projects 3D Zoo Algorithm Android Aquarium Bellman-Ford Algorithm BÃ©zier curves Block Breaker Blockshooting Bucket Sort C# Chess Clock Code Blocks Colors Complex Project Complex Projects Crab Pong Cross Zero Doll DSAV Escapa Fighter Jet First Come First Serve Flag Flag Hoisting flag of usa Fluids Font Demo Games Gear Motion GlutDino Glutplane Graphics Editor iOS iPhone Java Java OpenGL Graphics Programming Light Torus Linked List Ludo Board Game Mancala board games Martyr’s Monument Memory blocks game Memory Game Menu Mickey Mouse Minesweeper Miniature Steam Engine moth Motion Blur MoveLight moving car Moving Ship Multiplex Networking Based Project Nuclear Power Plant Olympic opengl c++ examples OpenGL ES OpenGL Programming OpenGL Tutorial Origami OS Based Projects Paint Paper Folding Particles Drop Path Finding ping pong Pong Game Project Report Projects Report Puzzles qix like Queuqe Random Flowing lines Ray Rigid Body Rings Robot sample c++ opengl code Screen Saver Screen Saver Ship Shadow Cube Shadowfun Shaheed Minar Ship Iceberg Simple Drawing Simple Haloed Lined Wireframe Simple Move Light Simple Project Simulation SNAKE XENZIA GAME Solar system Sorting Space Invaders Sphere Spot Light Swing Stack Stars Taj Mahal The Edge Game Tic Tac Toe Tower of Hanoi Traffic Signal Transformation Triangular Animation Trippy Tutorial water ripple effects Whirlpool
false
ltr
item
OpenGL Projects: How to Draw Different Types of Triangles in OpenGL
How to Draw Different Types of Triangles in OpenGL
Looking for the code to draw triangles in OpenGL C++ Computer graphics, here we give full source code with explanation.
OpenGL Projects
https://www.openglprojects.in/2014/08/how-to-draw-triangles-in-opengl.html
https://www.openglprojects.in/
https://www.openglprojects.in/
https://www.openglprojects.in/2014/08/how-to-draw-triangles-in-opengl.html
true
2020194800836807725
UTF-8