PDA

View Full Version : Using OpenGL with VS 2010



animaks
07-03-2012, 09:59 AM
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <GL/GL.h>
#include <GL/GLU.h>
#include <GL/glew.h>
#include <GL/freeglut.h>
#include <GL/glut.h>
#include <GL/glxew.h>
#include <GL/wglew.h>

#define WINDOW_TITLE_PREFIX "Chapter 1"
int CurrentWidth = 800,
CurrentHeight = 600,
WindowHandle = 0;
void Initialize(int, char*[]);
void InitWindow(int, char*[]);
void ResizeFunction(int, int);
void RenderFunction(void);

int main(int argc, char* argv[])
{
Initialize(argc, argv);
glutMainLoop();
exit(EXIT_SUCCESS);
}
void Initialize(int argc, char* argv[])
{
InitWindow(argc, argv);
fprintf(
stdout,
"INFO: OpenGL Version: %s\n",
glGetString(GL_VERSION));
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
}
void InitWindow(int argc, char* argv[])
{
glutInit(&argc, argv);
glutInitContextVersion(4, 0);
glutInitContextFlags(GLUT_FORWARD_COMPATIBLE);
glutInitContextProfile(GLUT_CORE_PROFILE);
glutSetOption(
GLUT_ACTION_ON_WINDOW_CLOSE,
GLUT_ACTION_GLUTMAINLOOP_RETURNS
);
glutInitWindowSize(CurrentWidth, CurrentHeight);
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
WindowHandle = glutCreateWindow(WINDOW_TITLE_PREFIX);
if(WindowHandle < 1) {
fprintf(
stderr,
"ERROR: Could not create a new rendering window.\n"
);
exit(EXIT_FAILURE);
}
glutReshapeFunc(ResizeFunction);
glutDisplayFunc(RenderFunction);
}
void ResizeFunction(int Width, int Height)
{
CurrentWidth = Width;
CurrentHeight = Height;
glViewport(0, 0, CurrentWidth, CurrentHeight);
}

void RenderFunction(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glutSwapBuffers();
glutPostRedisplay();
}




Hi, I am using the code written below, but it gives me glGetString undefined error , glClearColor undefined error, glViewport undefined error, glClear undefined error... how to be? I've installed all required libraries... please help me

thokra
07-03-2012, 12:47 PM
Please put your code in '['code']' tags before expecting any help.

V-man
07-03-2012, 06:06 PM
Undefined means that it did not find the definition for glGetString and other GL functions. Try including glew.h before gl.h.

thokra
07-03-2012, 11:12 PM
V-man: You ruined my therapeutic approach. ;)

I bet the thread starter is simply forgetting to link to OpenGL32.lib

animaks
07-04-2012, 12:31 AM
thank you so much...:) V-man

thokra
07-04-2012, 12:51 AM
I wonder why cl didn't error out in the first place since GLEW.h contains the following lines:


#if defined(__gl_h_) || defined(__GL_H__) || defined(__X_GL_H)
#error gl.h included before glew.h
#endif

BTW, for your purposes glew.h and freeglut.h (and possibly GLU.h) are completely sufficient. GL.h, is never included after glew.h has been preprocessed because the include guard in GL.h will have the preprocessor ignore the contents of GL.h.

freeglut.h include freeglut_std.h and freeglut_ext.h - glut.h include freeglut_std.h.

Edit: Forgot glxew.h and wglew.h - these provide functions for the GL extensions to the X Window System and Windows. Since freeGLUT is already handling the stuff you can with these they are equally unnecessary in your case.