Solved

Simple graphics

Posted on 2000-04-13
12
267 Views
Last Modified: 2010-04-10
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.
0
Comment
Question by:Decimal
12 Comments
 

Author Comment

by:Decimal
ID: 2714818
Adjusted points from 32 to 80
0
 
LVL 3

Expert Comment

by:MDarling
ID: 2715170
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);


}
0
 
LVL 9

Expert Comment

by:Pacman
ID: 2715345
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, ... ?
0
 
LVL 1

Expert Comment

by:ntdragon
ID: 2715419
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
0
 

Author Comment

by:Decimal
ID: 2716125
Edited text of question.
0
 

Author Comment

by:Decimal
ID: 2716126
Edited text of question.
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:Decimal
ID: 2716133
Edited text of question.
0
 

Author Comment

by:Decimal
ID: 2716165
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)
0
 

Author Comment

by:Decimal
ID: 2716226
Edited text of question.
0
 
LVL 7

Expert Comment

by:KangaRoo
ID: 2717146
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
0
 
LVL 7

Accepted Solution

by:
KangaRoo earned 80 total points
ID: 2717155
ObjectWindows Reference "Graphics Objects"
C:\BC5\EXAMPLES\OWL\TUTORIAL
0
 

Author Comment

by:Decimal
ID: 2717429
Thanks.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now