PDA

View Full Version : A simple opengl question



hayden
01-29-2013, 11:10 AM
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.

tonyo_au
01-29-2013, 05:20 PM
Mine is in the Microsoft Windows SDK - I don't think that installs with VS.

V-man
01-31-2013, 07:11 AM
What message did your compiler give?
What makes you say you don't need to include gl.h?

hayden
01-31-2013, 09:24 AM
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

V-man
01-31-2013, 07:11 PM
It could be that you are using another header file that themselves include gl.h and glu.h.

hayden
02-07-2013, 09:50 AM
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;
}

skeezix6
02-07-2013, 12:55 PM
glut.h includes gl.h and glu.h

hayden
02-07-2013, 05:58 PM
Thank you very much for clarification.

newbiecow
02-08-2013, 03:06 AM
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?