GIDForums  

Go Back   GIDForums > Computer Programming Forums > OpenGL Programming
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 02-Nov-2006, 15:00
markyp markyp is offline
New Member
 
Join Date: Nov 2006
Posts: 26
markyp is on a distinguished road

OpenGL - using C


Hi i am trying to compile a opengl graphics file on linux does anyone know how to get he program to execute? thanks for your help
  #2  
Old 21-Nov-2007, 00:28
aie0 aie0 is offline
Member
 
Join Date: Dec 2004
Posts: 246
aie0 is a jewel in the roughaie0 is a jewel in the rough

Re: OpenGL - using C


like any other linux program
./programname
  #3  
Old 22-Nov-2007, 08:34
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 4,641
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold

Re: OpenGL - using C


Quote:
Originally Posted by markyp
...opengl graphics file on linux ...


Create a new directory under your home and cd into it.

Code:
cd mkdir gl_hello cd gl_hello

Download or copy a source file from somewhere.
Here is hello.c from http://www.opengl.org/resources/code/samples/redbook/
CPP / C++ / C Code:
/*
 * Copyright (c) 1993-1997, Silicon Graphics, Inc.
 * ALL RIGHTS RESERVED 
 * Permission to use, copy, modify, and distribute this software for 
 * any purpose and without fee is hereby granted, provided that the above
 * copyright notice appear in all copies and that both the copyright notice
 * and this permission notice appear in supporting documentation, and that 
 * the name of Silicon Graphics, Inc. not be used in advertising
 * or publicity pertaining to distribution of the software without specific,
 * written prior permission. 
 *
 * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
 * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
 * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
 * FITNESS FOR A PARTICULAR PURPOSE.  IN NO EVENT SHALL SILICON
 * GRAPHICS, INC.  BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT,
 * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY
 * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION,
 * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF
 * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC.  HAS BEEN
 * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON
 * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
 * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE.
 * 
 * US Government Users Restricted Rights 
 * Use, duplication, or disclosure by the Government is subject to
 * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
 * (c)(1)(ii) of the Rights in Technical Data and Computer Software
 * clause at DFARS 252.227-7013 and/or in similar or successor
 * clauses in the FAR or the DOD or NASA FAR Supplement.
 * Unpublished-- rights reserved under the copyright laws of the
 * United States.  Contractor/manufacturer is Silicon Graphics,
 * Inc., 2011 N.  Shoreline Blvd., Mountain View, CA 94039-7311.
 *
 * OpenGL(R) is a registered trademark of Silicon Graphics, Inc.
 */

/*
 *  aaindex.c
 *  This program draws shows how to draw anti-aliased lines in color
 *  index mode. It draws two diagonal lines to form an X; when 'r' 
 *  is typed in the window, the lines are rotated in opposite 
 *  directions.
 */
#include <GL/glut.h>
#include "stdlib.h"

#define RAMPSIZE 16
#define RAMP1START 32
#define RAMP2START 48

static float rotAngle = 0.;

/*  Initialize antialiasing for color index mode,
 *  including loading a green color ramp starting
 *  at RAMP1START, and a blue color ramp starting
 *  at RAMP2START. The ramps must be a multiple of 16.
 */
void init(void)
{
   int i;

   for (i = 0; i < RAMPSIZE; i++) {
      GLfloat shade;
      shade = (GLfloat) i/(GLfloat) RAMPSIZE;
      glutSetColor(RAMP1START+(GLint)i, 0., shade, 0.);
      glutSetColor(RAMP2START+(GLint)i, 0., 0., shade);
   }

   glEnable (GL_LINE_SMOOTH);
   glHint (GL_LINE_SMOOTH_HINT, GL_DONT_CARE);
   glLineWidth (1.5);

   glClearIndex ((GLfloat) RAMP1START);
}

/*  Draw 2 diagonal lines to form an X
 */
void display(void)
{
   glClear(GL_COLOR_BUFFER_BIT);

   glIndexi(RAMP1START);
   glPushMatrix();
   glRotatef(-rotAngle, 0.0, 0.0, 0.1);
   glBegin (GL_LINES);
      glVertex2f (-0.5, 0.5);
      glVertex2f (0.5, -0.5);
   glEnd ();
   glPopMatrix();

   glIndexi(RAMP2START);
   glPushMatrix();
   glRotatef(rotAngle, 0.0, 0.0, 0.1);
   glBegin (GL_LINES);
      glVertex2f (0.5, 0.5);
      glVertex2f (-0.5, -0.5);
   glEnd ();
   glPopMatrix();

   glFlush();
}

void reshape(int w, int h)
{
   glViewport(0, 0, (GLsizei) w, (GLsizei) h);
   glMatrixMode(GL_PROJECTION);
   glLoadIdentity();
   if (w <= h) 
      gluOrtho2D (-1.0, 1.0, 
         -1.0*(GLfloat)h/(GLfloat)w, 1.0*(GLfloat)h/(GLfloat)w);
   else 
      gluOrtho2D (-1.0*(GLfloat)w/(GLfloat)h, 
         1.0*(GLfloat)w/(GLfloat)h, -1.0, 1.0);
   glMatrixMode(GL_MODELVIEW);
   glLoadIdentity();
}

void keyboard(unsigned char key, int x, int y)
{
   switch (key) {
      case 'r':
      case 'R':
         rotAngle += 20.;
         if (rotAngle >= 360.) rotAngle = 0.;
         glutPostRedisplay();	
         break;
      case 27:  /*  Escape Key */
         exit(0);
         break;
      default:
         break;
    }
}

/*  Main Loop
 *  Open window with initial window size, title bar, 
 *  color index display mode, and handle input events.
 */
int main(int argc, char** argv)
{
   glutInit(&argc, argv);
   glutInitDisplayMode (GLUT_SINGLE | GLUT_INDEX);
   glutInitWindowSize (200, 200);
   glutCreateWindow (argv[0]);
   init();
   glutReshapeFunc (reshape);
   glutKeyboardFunc (keyboard);
   glutDisplayFunc (display);
   glutMainLoop();
   return 0;
}

Create a file named Makefile. Here is an example. (Just paste it directly from this post.)

Code:
CC = gcc CFLAGS = -Wall -W -pedantic LDFLAGS = -lm -lglut hello: hello.c $(CC) $(CFLAGS) $< $(LDFLAGS) -o $@ clean: rm hello

Note that it is very important for the GNU make program that the line containing $(CC)... that the leading character is a tab, not spaces.
Also for the line after dlean:, the leading character is a tab character, not spaces.

Enter the following at the command line:

make


When I do this on my Centos Linux system I see the following:

Code:
gcc -Wall -W -pedantic hello.c -lm -lglut -o hello

There were no messages of any kind from the compiler or linker

The directory now contains three files, the source file, the make file, and the executable, named "hello"

Enter the following on the command line:
Code:
./hello

I get a window with "hello" in the title bar. The display in the window consists of a white square inside a black square.

Now, if something else happens at any of these steps, then tell us exactly what happened. Also, and this is important, tell us what Linux distribution you are using.

Regards,

Dave

Footnote: you don't have to have a Makefile; you can just enter the command by hand:
Code:
gcc -Wall -W -pedantic hello.c -lm -lglut -o hello

But you might as well get used to using some of the tools that are available on your Linux system. Other gl projects can start with a copy of the makefile that I showed; just use your program name in place of "hello.c" and "hello". More complicated projects will have additional things in their Makefiles, but this is a start.
  #4  
Old 23-Nov-2007, 07:01
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 4,641
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold

Re: OpenGL - using C


Quote:
Originally Posted by davekw7x

It has been pointed out to me that the file I previously posted was not hello.c. In fact, the particular program that I posted may not work on all systems (depending on your video card's graphics capabilities and depending on what video driver modules you have installed).

Here is the real hello.c. It should work for any Linux platform that has glut libraries and glut development libraries. If it works for you, I recommend that you download "redbook.zip" from the site that I linked above. Many other examples are illustrated there.

Regards,

Dave
 
 

Recent GIDBlogNARMY by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
OpenGL in Normal FLTK Windows automatedreason FLTK Forum 2 25-Apr-2008 05:44
What is OpenGL? Shrikharan OpenGL Programming 6 21-Dec-2005 17:47
C++ game programming OpenGL oozsakarya OpenGL Programming 2 13-Nov-2005 13:50
nVidia & OpenGL Problems in windows XP marjasin Computer Hardware Forum 21 30-Aug-2004 00:57

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 19:26.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.