Link to home
Start Free TrialLog in
Avatar of Decimal
Decimal

asked on

Simple graphics

Argh! I'm having such a hard time finding any information on how
to start programming simple graphics in Windows. I see names
being thrown around like DirectX, OpenGL, GDI, but how on earth
do I get started using them? What I want to know is what .h/.lib
file I need to get my hands on, and how to initialize the screen so
I can draw simple 2D objects like lines and circles, full screened or in
a window. I use Borland C++ 5 (not Builder) on a computer with
no 3D graphics card.

Any directions to thorough tutorials would be greatly appreciated as well.

Thank you.
Avatar of Decimal
Decimal

ASKER

Adjusted points from 32 to 80
you don't need any of these libraries to draw lines and circles.  You just need to look at MFC Object CDC or the SDK HDC which it wraps.

This question would be better in the Windows programming forum.

void Class::OnDraw(CDC *pDC)
{
   pDC->MoveTo(10,10);
   pDC->LineTo(100,10);

   pDC->Rectangle(&m_rect);


}
I would say it depends on what you want to do with graphics.

DirectX for fast graphics (2D, 3D)
OpenGL for 3D-Rendering

if you want to draw two dimensional "simple" things, then the lowest level is  using GDI via API-functions.

What's your framework ?
API, MFC, ... ?
i used OpenGL for my graphic project

what you have to find is opengl libs
if you are using windows 98 u already have it
then you have to find glut fils
that is glut.h and glut32.dll
then if you use C++Builder you have to extrect a lib file from the glut32.dll

take the glut32.dll and a prog named implib.exe you"ll find it in the bin folder of your C++Builder then make a lib file from the Glut32.dll and name it glut.lib then
copy the glut.h file into the include floder and the glut.lib into the lib folder

then when you are strting a project in C++Builder add to the makefile
at the line "ALLIB" at the end :glut.lib

now here is a simple example in OpenGL for you:



#pragma hdrstop

#include <condefs.h>

#pragma argsused

#include <iostream.h>

#include <gl/glut.h>



GLfloat Cube[][3]={{-1,-1,-1},{1,-1,-1},

{1,1,-1},{-1,1,-1},{-1,-1,1},

{1,-1,1},{1,1,1},{-1,1,1}};



GLfloat Octa[][3]={{-1,0,-1},{1,0,-1},

{1,0,1},{-1,0,1},{0,2,0},{0,-2,0}};



GLfloat Tetra[][3]={{-1,-0.64,-1},{1,-0.64,-1},

{0,-0.64,1.23},{0,1.29,0}};







GLfloat colors[][3]={{0,0,0},{1,0,0},

{1,1,0},{0,1,0},{0,0,1},

{1,0,1},{1,1,1},{0,1,1}};



void Polygon(int a,int b,int c,int d)

{

       glBegin(GL_POLYGON);



          glColor3fv(colors[a]);

          glVertex3fv(Cube[a]);



            glColor3fv(colors[b]);

          glVertex3fv(Cube[b]);



           glColor3fv(colors[c]);

          glVertex3fv(Cube[c]);



            glColor3fv(colors[d]);

          glVertex3fv(Cube[d]);

      glEnd();

}



void Cubemsgeret(int a,int b,int c,int d)

{

       glBegin(GL_LINE_LOOP);

          glColor3f(0,0,0);



          glVertex3fv(Cube[a]);



          glVertex3fv(Cube[b]);



          glVertex3fv(Cube[c]);



          glVertex3fv(Cube[d]);



      glEnd();

}



void Triangle(int a,int b,int c)

{

       glBegin(GL_POLYGON);



          glColor3fv(colors[a]);

          glVertex3fv(Octa[a]);



            glColor3fv(colors[b]);

          glVertex3fv(Octa[b]);



           glColor3fv(colors[c]);

          glVertex3fv(Octa[c]);



      glEnd();

}



void Octamsgeret(int a,int b,int c)

{

       glBegin(GL_LINE_LOOP);

          glColor3f(0,0,0);



          glVertex3fv(Octa[a]);

          glVertex3fv(Octa[b]);

          glVertex3fv(Octa[c]);



      glEnd();

}



void TriangleTetra(int a,int b,int c)

{

       glBegin(GL_POLYGON);



          glColor3fv(colors[a]);

          glVertex3fv(Tetra[a]);



            glColor3fv(colors[b]);

          glVertex3fv(Tetra[b]);



           glColor3fv(colors[c]);

          glVertex3fv(Tetra[c]);



      glEnd();

}



void Tetramsgeret(int a,int b,int c)

{

       glBegin(GL_LINE_LOOP);

          glColor3f(0,0,0);



          glVertex3fv(Tetra[a]);

          glVertex3fv(Tetra[b]);

          glVertex3fv(Tetra[c]);



      glEnd();

}







void ColorCube()

{

        Polygon(0,3,2,1);

      Polygon(2,3,7,6);

      Polygon(0,4,7,3);

      Polygon(1,2,6,5);

      Polygon(4,5,6,7);

      Polygon(0,1,5,4);



            Cubemsgeret(0,3,2,1);

      Cubemsgeret(2,3,7,6);

      Cubemsgeret(0,4,7,3);

      Cubemsgeret(1,2,6,5);

      Cubemsgeret(4,5,6,7);

      Cubemsgeret(0,1,5,4);

}





void ColorOcta()

{

      Triangle(0,3,4);

        Triangle(0,1,4);

        Triangle(1,2,4);

      Triangle(2,3,4);

        Triangle(0,3,5);

        Triangle(0,1,5);

        Triangle(1,2,5);

      Triangle(2,3,5);



        Octamsgeret(0,3,4);

        Octamsgeret(0,1,4);

        Octamsgeret(1,2,4);

      Octamsgeret(2,3,4);

        Octamsgeret(0,3,5);

        Octamsgeret(0,1,5);

        Octamsgeret(1,2,5);

      Octamsgeret(2,3,5);

}



void ColorTetra()

{

        TriangleTetra(0,1,2);

      TriangleTetra(1,2,3);

      TriangleTetra(2,0,3);

      TriangleTetra(0,1,3);



        Tetramsgeret(0,1,2);

      Tetramsgeret(1,2,3);

      Tetramsgeret(2,0,3);

      Tetramsgeret(0,1,3);

}



static GLfloat theta[]={0,0,0};

static GLint axis=2;



void display()

{

      glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

      glLoadIdentity();

        glRotatef(theta[0],1,0,0);

      glRotatef(theta[1],0,1,0);

      glRotatef(theta[2],0,0,1);

      ColorCube();



      glFlush();

      glutSwapBuffers();

}



void spincube()

{

   theta[axis]+=2;

   if (theta[axis]>360) theta[axis]-=360;

   glutPostRedisplay();

}



void RotateMenuFunc(int id)

{

        if (id==1) axis=0;

        if (id==2) axis=1;

        if (id==3) axis=2;

}



void reshape(int w,int h)

{

      glViewport(0,0,w,h);

      glMatrixMode(GL_PROJECTION);

      glLoadIdentity();

      if (w<=h)

        glOrtho(-2,2,-2*(GLfloat)h/(GLfloat)w,

        2*(GLfloat)h/(GLfloat)w,-10,10);

      else

        glOrtho(-2*(GLfloat)w/(GLfloat)h,

        2*(GLfloat)w/(GLfloat)h,-2,2,-20,10);

      glMatrixMode(GL_MODELVIEW);

}



void main(int argc,char **argv)

{

        int Rotate_Menu;

        glutInit(&argc,argv);

      glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGBA|GLUT_DEPTH);

      glutInitWindowSize(800,600);

      glutCreateWindow("Figures");

      glutReshapeFunc(reshape);

      glutDisplayFunc(display);

      glutIdleFunc(spincube);

        Rotate_Menu=glutCreateMenu(RotateMenuFunc);

        glutAddMenuEntry("Rotate X",1);

        glutAddMenuEntry("Rotate Y",2);

        glutAddMenuEntry("Rotate Z",3);

        glutAttachMenu(GLUT_LEFT_BUTTON);

      glEnable(GL_DEPTH_TEST);

           glEnable(GL_NORMALIZE);

      glutMainLoop();

}
//end
if you have any questions just ask
Avatar of Decimal

ASKER

Edited text of question.
Avatar of Decimal

ASKER

Edited text of question.
Avatar of Decimal

ASKER

Edited text of question.
Avatar of Decimal

ASKER

Well, I'm going to forego the 3D graphics for now,
seeing as I'm having trouble even getting 2D to work.
So OpenGL is out. Thanks for the example, ntDragon,
but I'm not using Builder anyway.

MDarling, Pacman, you've just thrown more acronyms
at me that I don't understand or know how to use. =(
(MFC, CDC, SDK, HDC, API)
Avatar of Decimal

ASKER

Edited text of question.
BC5... Check the examples directory for OWL:

C:\BC5\EXAMPLES\OWL\APPS\BMPVIEW
C:\BC5\EXAMPLES\OWL\APPS\DRAW

Replace C:\BC5 with the installation directory of BC
ASKER CERTIFIED SOLUTION
Avatar of KangaRoo
KangaRoo

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Decimal

ASKER

Thanks.