Archive Pages Design$type=blogging

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.

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;
 }

COMMENTS

Name

3D Bi-Cycle 3D Game 3D Laptop 3D Objects 3D Projects 3D Zoo Algorithm Android Aquarium Bellman-Ford Algorithm Block Breaker Blockshooting Bucket Sort C# Chess Clock Code Blocks Colors Complex Project Complex Projects Crab Pong Cross Zero DSAV Escapa First Come First Serve 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 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 Tutorial Origami OS Based Projects Paint Paper Folding Particles Drop Path Finding ping pong Pong Game Project Report Projects Report Puzzles qix like Random Flowing lines Rigid Body Rings Robot sample c++ opengl code Screen Saver Screen Saver Ship Shadow Cube Shadowfun Ship Iceberg Simple Drawing Simple Haloed Lined Wireframe Simple Move Light Simple Project Simulation SNAKE XENZIA GAME Solar system Sorting Sphere Spot Light Swing Stars Taj Mahal The Edge Game Tic Tac Toe Tower of Hanoi Traffic Signal Transformation Triangular Animation 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
http://www.openglprojects.in/2014/08/how-to-draw-triangles-in-opengl.html
http://www.openglprojects.in/
http://www.openglprojects.in/
http://www.openglprojects.in/2014/08/how-to-draw-triangles-in-opengl.html
true
2020194800836807725
UTF-8
Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago