Skip to content

Instantly share code, notes, and snippets.

@abrarShariar
Created May 28, 2018 04:30
Show Gist options
  • Save abrarShariar/0c55205b00656cfb70b7d8e2e2b6e405 to your computer and use it in GitHub Desktop.
Save abrarShariar/0c55205b00656cfb70b7d8e2e2b6e405 to your computer and use it in GitHub Desktop.
opengl lab
#include <GL/gl.h>
#include <GL/glut.h>
void display(void)
{
/* clear all pixels */
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0, 1.0, 0.0);//(R,G,B)
//Draw a triangle using line.
glBegin(GL_LINES);
glVertex3i(25, 70, 0);
glVertex3i(275, 70, 0);
glEnd();
glColor3f(1.0, 0.0, 0.0);
glBegin(GL_LINES);
glVertex3i(25, 70, 0);
glVertex3i(25, 270, 0);
glEnd();
glColor3f(0.0, 1.0, 0.0);
glBegin(GL_LINES);
glVertex3i(25, 270, 0);
glVertex3i(275, 270, 0);
glEnd();
glColor3f(0.0, 0.0, 1.0);
glBegin(GL_LINES);
glVertex3i(275, 270, 0);
glVertex3i(275, 70, 0);
glEnd();
//new square
glColor3f(1.0, 1.0, 0.0);//(R,G,B)
//Draw a triangle using line.
glBegin(GL_LINES);
glVertex3i(25, 70, 0);
glVertex3i(275, 70, 0);
glEnd();
glColor3f(1.0, 0.0, 0.0);
glBegin(GL_LINES);
glVertex3i(15, 60, 0);
glVertex3i(15, 260, 0);
glEnd();
glColor3f(0.0, 1.0, 0.0);
glBegin(GL_LINES);
glVertex3i(25, 270, 0);
glVertex3i(275, 270, 0);
glEnd();
glColor3f(0.0, 0.0, 1.0);
glBegin(GL_LINES);
glVertex3i(275, 270, 0);
glVertex3i(275, 70, 0);
glEnd();
//glVertex3f(0.25, 0.25, 0.0);
//glVertex3f(0.75, 0.25, 0.0);
//glColor3f(1.0, 0.0, 0.0);
//glVertex3f(0.25, 0.25, 0.0);
//glVertex3f(0.50, 0.75, 0.0);
//glColor3f(0.0, 0.0, 1.0);
//glVertex3f(0.50, 0.75, 0.0);
//glVertex3f(0.75, 0.25, 0.0);
//Draw a Simple Triangle.
/*
glBegin(GL_TRIANGLES);
glVertex3f(0.25, 0.25, 0.0);
glVertex3f(0.75, 0.25, 0.0);
glVertex3f(0.75, 0.75, 0.0);
//Draw a simple rectangle.
//glBegin(GL_POLYGON);
glBegin(GL_QUADS);
glVertex3f(0.25, 0.25, 0.0);
glVertex3f(0.75, 0.25, 0.0);
glVertex3f(0.25, 0.75, 0.0);
glVertex3f(0.75, 0.75, 0.0);
//glVertex3f(0.90, 0.50, 0.0);
/*glEnd();
glBegin(GL_POLYGON);
glVertex3f(0.75, 0.75, 0.0);
glVertex3f(0.25, 0.75, 0.0);
glVertex3f(0.10, 0.50, 0.0);
*/
/* don’t wait!
* start processing buffered OpenGL routines
*/
glFlush();
}
void init(void)
{
/* select clearing (background) color */
glClearColor(0.0, 0.0, 0.0, 0.0);
/* initialize viewing values */
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
//glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0);
gluOrtho2D(0.0, 300.0, 0, 300.0);
}
/*
* Declare initial window size, position, and display mode
* (single buffer and RGBA). Open window with “hello”
* in its title bar. Call initialization routines.
* Register callback function to display graphics.
* Enter main loop and process events.
*/
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(300, 300);
glutInitWindowPosition(800, 100);
glutCreateWindow("hello");
init();
glutDisplayFunc(display);
glutMainLoop();
return 0; /* ISO C requires main to return int. */
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment