Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 9 of 9

Thread: A simple opengl question

  1. #1
    Junior Member Newbie
    Join Date
    Jan 2013
    Posts
    23

    A simple opengl question

    When I install Microsoft Visual Studio 2010, it is assumed OpenGL is already installed (I am not taliking about glut.h, I am only talking about gl.h and glu.h). But while compiling one program I found that if I don't include gl.h, it shows error.
    Then I had to include the following for compilation:



    #include <gl/gl.h>

    But to me, the program should compile without it.

    As I am new in this field, things may not be clear to me. It would be good if anyone clarifies it. Thanks.

  2. #2
    Senior Member OpenGL Pro
    Join Date
    Jan 2012
    Location
    Australia
    Posts
    1,097
    Mine is in the Microsoft Windows SDK - I don't think that installs with VS.

  3. #3
    Super Moderator OpenGL Guru
    Join Date
    Feb 2000
    Location
    Montreal, Canada
    Posts
    4,264
    What message did your compiler give?
    What makes you say you don't need to include gl.h?
    ------------------------------
    Sig: http://glhlib.sourceforge.net
    an open source GLU replacement library. Much more modern than GLU.
    float matrix[16], inverse_matrix[16];
    glhLoadIdentityf2(matrix);
    glhTranslatef2(matrix, 0.0, 0.0, 5.0);
    glhRotateAboutXf2(matrix, angleInRadians);
    glhScalef2(matrix, 1.0, 1.0, -1.0);
    glhQuickInvertMatrixf2(matrix, inverse_matrix);
    glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
    glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);

  4. #4
    Junior Member Newbie
    Join Date
    Jan 2013
    Posts
    23
    Usually when I write a openGl program in MSVC 2010, I don't include the following header files:

    #include <GL/gl.h>
    #include <GL/glu.h>

    But I downloaded one program from the website, while trying to compile it, it was looking for gl.h file. But my question is why I don't need to include those headers in all appications.
    I am new in OpenGL, so I need this clarification. Thanks

  5. #5
    Super Moderator OpenGL Guru
    Join Date
    Feb 2000
    Location
    Montreal, Canada
    Posts
    4,264
    It could be that you are using another header file that themselves include gl.h and glu.h.
    ------------------------------
    Sig: http://glhlib.sourceforge.net
    an open source GLU replacement library. Much more modern than GLU.
    float matrix[16], inverse_matrix[16];
    glhLoadIdentityf2(matrix);
    glhTranslatef2(matrix, 0.0, 0.0, 5.0);
    glhRotateAboutXf2(matrix, angleInRadians);
    glhScalef2(matrix, 1.0, 1.0, -1.0);
    glhQuickInvertMatrixf2(matrix, inverse_matrix);
    glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
    glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);

  6. #6
    Junior Member Newbie
    Join Date
    Jan 2013
    Posts
    23
    I have included the following file which does not include gl.h or glu.h


    I have included the following file which uses neither GL.h nor GLU.h, but I can run and comiple it in my machine.

    #include <iostream>
    #include <stdlib.h>
    #include <stdio.h>
    #include <GL/glut.h>
    #include <vector>
    using namespace std;

    void display(void)
    {
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(-10, 10, -10, 10, -1, 1);

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

    glPushMatrix();
    glScalef(5,5,5);
    glBegin(GL_QUADS);
    glColor3ub(255,0,0);
    glVertex2f(-1,-1);
    glColor3ub(0,255,0);
    glVertex2f(1,-1);
    glColor3ub(0,0,255);
    glVertex2f(1,1);
    glColor3ub(255,255,255);
    glVertex2f(-1,1);
    glEnd();
    glPopMatrix();

    glutSwapBuffers();
    }

    int win_w = 0;
    int win_h = 0;
    void reshape(int w, int h)
    {
    win_w = w;
    win_h = h;
    glViewport(0, 0, w, h);
    }

    void mouse( int x, int y )
    {
    // 4 bytes per pixel (RGBA), 1x1 bitmap
    std::vector< unsigned char > pixels( 1 * 1 * 4 );
    glReadPixels( x, win_h - y, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &pixels[0] );

    cout << "r: " << (int)pixels[0] << endl;
    cout << "g: " << (int)pixels[1] << endl;
    cout << "b: " << (int)pixels[2] << endl;
    cout << "a: " << (int)pixels[3] << endl;
    cout << endl;
    }

    int main(int argc, char **argv)
    {
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_RGBA | GLUT_DEPTH | GLUT_DOUBLE);

    glutInitWindowSize(800,600);
    glutCreateWindow("glReadPixels()");

    glutDisplayFunc(display);
    glutReshapeFunc(reshape);
    glutPassiveMotionFunc(mouse);
    glutMainLoop();
    return 0;
    }

  7. #7
    Junior Member Newbie
    Join Date
    Feb 2013
    Posts
    11
    glut.h includes gl.h and glu.h

  8. #8
    Junior Member Newbie
    Join Date
    Jan 2013
    Posts
    23
    Thank you very much for clarification.

  9. #9
    Intern Contributor
    Join Date
    Dec 2012
    Posts
    74
    Your question is without the least regard to opengl but a basic c/c++ one. Why not first try it in your national computer technology forum but directly submit here such an international and authoritative one?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •