Menu

Open GL/Glut troubles

Jazz Cat
2010-03-10
2012-09-26
  • Jazz Cat

    Jazz Cat - 2010-03-10

    Hi guys. Am attempting to play with Glut and Open GL. Complete novice. I'm
    attempting to compile(?) the following code:

    // Here is your first OpenGL tutorial. How to make a Window.
    // First off you need to call the OpenGL header files. The basics are
    // gl.h and glut.h, with these two your program will run on whatever OS
    // it is compiled in as it does not currently rely on Windows.

    // So that you know, the gl.h supplies the openGL commands while glut.h
    // allows us to call the glut commands. If you are not using glut, then
    // do not bother to call this.

    // After this next little bit, the rest of the code is explained below in the
    actual code.

    // To reshape a window in GLUT you need one command in the 'main' function
    // this is:
    // glutInitWindowSize (500, 500);
    // this will set it to 500 pixels wide and 500 high.
    // The other line you may notice I have added is:
    // glutInitWindowPosition (100, 100);
    // This sets where the window is located on the screen, in this case
    // 100 pixels down and 100 to the right.

    include <GL gl.h=""> //include the gl header file

    include <GL glut.h=""> //include the glut header file

    void display (void) {
    glClearColor (0.0,0.0,0.0,1.0); //clear the color of the window
    glClear (GL_COLOR_BUFFER_BIT); //Clear teh Color Buffer (more buffers later
    on)
    glLoadIdentity(); //load the Identity Matrix
    gluLookAt (0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0); //set the view
    glFlush(); //flush it all to the screen
    }

    int main (int argc, char **argv) {
    glutInit (&argc, argv); //initialize the program.
    glutInitDisplayMode (GLUT_SINGLE); //set up a basic display buffer (only
    singular for now)
    glutInitWindowSize (500, 500); //set whe width and height of the window
    glutInitWindowPosition (100, 100); //set the position of the window
    glutCreateWindow ("A basic OpenGL Window") //set the caption for the window
    glutDisplayFunc (display); //call the display function to draw our world
    glutMainLoop (); //initialize the OpenGL loop cycle
    return 0;
    }

    i get the following errors:

    22 C:\Dev-Cpp\Programs\main.cpp In file included from main.cpp
    50 C:\Dev-Cpp\include\GL\glut.h redeclaration of C++ built-in type short' C:\Dev-Cpp\Programs\main.cpp In functionint main(int, char**)':
    38 C:\Dev-Cpp\Programs\main.cpp expected `;' before "glutDisplayFunc"
    C:\Dev-Cpp\Programs\Makefile.win Error 1

    Firstly, am I diving in at the deep end trying to play with this kind of code
    before getting through all the basics of C++?
    Secondly, does anyone know of any well written tutorials or books that present
    OpenGL to complete dummies? I'v attempted to decipher something called the Red
    book but it just floods you with complicated terms like contexts and matrices.
    Thirdly, if someone could explain the errors and how to get around them, I'd
    much appreciate it.

     
  • BoogieGLX

    BoogieGLX - 2010-03-10

    "am I diving in at the deep end" - YES! How do you expect to use a C library
    like gl without knowing C?
    "any well written tutorials or books that present OpenGL" - OpenGL Superbible
    is a must have. Google it.
    "getting through all the basics of C++?" - Get the best beginner book "Teach
    Yourself C++ in 21 Days".

    "Thirdly, if someone could explain the errors" - OK, read this translation,
    then read the actual log again, and again:
    In file included from main.cpp...
    in the included file, glut.h, there is an illegal redeclaration of the C++
    built-in type `short'
    Also, in main.cpp, within the function, "int main(int, char**)"...
    there is a missing";" which you should have added to the line right above
    where you typed "glutDisplayFunc"
    A fatal build error has occurred.

    BTW, I taught myself C, C++, and OpenGL. You have a long road ahead of you. My
    advice? - Before you go too far with gl, ask yourself, "Am I strong in 3D math
    - vectors, cartesion coordinates, matrices, trigonometry, and such?". If the
    answer is no, then you are simply wasting your time.

    Good luck to you.
    MLB

     
  • Jazz Cat

    Jazz Cat - 2010-03-10

    Hi stinky.....thanks for the advice and for taking the time to answer my
    questions.

    Just an added question. You said how do I expect to use a C library like gl
    without knowing C? Does this mean I need to first learn C before I even touch
    C++ in order to pursue 3D programming or are the terms kind of interchangable?

    Another question, did you use books or did you find enough resources on the
    web to teach yourself what you know?
    I'm interested to hear back from you.

    JazzCat

     
  • BoogieGLX

    BoogieGLX - 2010-03-11

    First of all, unlike Clifford, I do recommend learning C before C++. It cannot
    hurt, and what you learn will carry over to C++.
    You see, C++ is built on top of C. IOW, it adds to C.
    C is easier to learn.
    OpenGL is a C library - you do not need to know C++ to use it, just C. Same
    with glut.

    C++ came out to help C programmers to more easily write and maintain large
    projects.

    I can tell you that Quake III was all C, no C++. Since then, ID has started
    using C++ - games are very large now.

    Funny - in that gl redbook, in the glossary has C defined as "God's
    programming language" while C++ is defined as "The object-oriented programming
    language of a pagan deity". Guess the C vs C++ wars are still going strong.

    "did you use books or did you find enough resources on the web" - I bought
    some 30 programming books from Borders. I prefer books - they are edited by
    experts, and they are much easier on the eyes(it will take a lot of time to
    master this language).
    A dozen of which are geared toward openGL and 3D math. Some of these are
    beginner books that would be perfect for you - I am going to be listing these
    and much more on eBay this Sunday evening - I'll be selling stuff for the next
    couple of months.
    Check it out if you like, lesterdeals is my eBay handle.

    Again, if you are not good in the math - forget it.

    MLB

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.