top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

What will be the programming code for graphics in C and C++?

+2 votes
387 views

can anyone help me?

posted Aug 31, 2014 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button
use openGL for C/C++ Graphics Programming which includes library files.like
freeglut.h,glut.h and many more.

2 Answers

+2 votes

Run this program to draw a line using codeblock and link it with -lfreeglut,-lopengl32 and -lglu32

#include<bits/stdc++.h>
#include <GL/glut.h>
double X1, Y1, X2, Y2;
float round_value(float v)
{
  return floor(v + 0.5);
}
void LineDDA(void)
{
  double dx=(X2-X1);
  double dy=(Y2-Y1);
  double steps;
  float xInc,yInc,x=X1,y=Y1;
  steps=(abs(dx)>abs(dy))?(abs(dx)):(abs(dy));
  xInc=dx/(float)steps;
  yInc=dy/(float)steps;
  glClear(GL_COLOR_BUFFER_BIT);
  glBegin(GL_POINTS);
  glVertex2d(x,y);
  int k;
  for(k=0;k<steps;k++)
  {
    x+=xInc;
    y+=yInc;
    glVertex2d(round_value(x), round_value(y));
  }
  glEnd();
  glFlush();
}
void Init()
{
  glClearColor(1.0,1.0,1.0,0);
  glColor3f(0.0,0.0,0.0);
  gluOrtho2D(0 , 640 , 0 , 480);
}
int main(int argc, char **argv)
{
  printf("Enter two end points:\n");
  scanf("%lf %lf %lf %lf",&X1,&Y1,&X2,&Y2);
  glutInit(&argc,argv);
  glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
  glutInitWindowPosition(0,0);
  glutInitWindowSize(640,480);
  glutCreateWindow("DDA_Line");
  Init();
  glutDisplayFunc(LineDDA);
  glutMainLoop();
  return 0;
}
answer May 21, 2016 by Shivam Kumar Pandey
0 votes
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
#include<graphics.h>
#include<stdio.h>

int main(void)
{
   /* request auto detection */
   int gdriver = DETECT, gmode, errorcode;

   /* initialize graphics mode */
   initgraph(&gdriver, &gmode, "");

   /* read result of initialization */
   errorcode = graphresult();

   if (errorcode != grOk)  /* an error occurred */
   {
      printf("Graphics error: %s\n", grapherrormsg(errorcode));
      printf("Press any key to halt:");
      getch();
      exit(1);             /* return with error code */
   }

    /* draw a line */
   moveto(190,90);
   outtext("hey");
   line(200,100,250,150);
   moveto(200,100);
   linerel(-50,50);
   moveto(138,150);
   char *c="helo";
   outtext(c);
   moveto(140,160);
   linerel(-50,50);
   moveto(140,160);
   linerel(50,50);
   /* clean up */
   getch();
   closegraph();
   return 0;
}
answer Dec 2, 2014 by Shivaranjini
Similar Questions
+3 votes

http://en.wikipedia.org/wiki/Relational_database_management_system

There are Database Backup and restore utilities for RDBMS Systems.
The Backup program generates a (.Bak) Binary File as output which can later be restored in case the Database crashes.

What could be the Algorithm/s in database backup/s and restore programs ?. i.e. C/C++ Programming logic/Algorithm.

...