Sign in to follow this  
I_U_3_4

"Linker error" in dev-c++

Recommended Posts

What libraries are required to do any lessons in OpenGL in dev-c++? Whenever I try to compile it, I get all kinds of "linker errors" relating to GLMatrixMode etc...basically anything beginning with GL. Help PLease!

Share this post


Link to post
Share on other sites
In the project settings under Linker you need to add -lopengl32 -lglu32, then it should work... And do NOT remove the other libs which relate to windows as this might result in other "undefined reference" errors

EDIT: Why dont you try the Nehe-Lessons with Dev-C++ project files? (http://nehe.gamedev.net/data/lessons/devc/lesson01.zip)

Share this post


Link to post
Share on other sites
For future reference, when you get errors always post them, with code if possible (for small amount of code at least). Copy them directly from your compiler output. It will help us help you faster.

Share this post


Link to post
Share on other sites
ok...now, instead of a "winmain@16" error I'm getting a "undefined reference to 'SDL_main' linker error.

when I try to add this
"int main(int argc, char *argv[])"

it gives me different errors:
"expected init-declarator before 'HGLRC' "
and
"expected ',' or ';' before 'HGLRC' "

here's my code..


#include <windows.h>
#include <gl\gl.h>
#include <gl\glu.h>
#include <gl\glaux.h>
#include "SDL.h"







HGLRC hRC=NULL;
HDC hDC=NULL;
HWND hWnd=NULL;
HINSTANCE hInstance;



bool keys[256];
bool active=true;
bool fullscreen=true;

LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);


GLvoid ReSizeGLScene(GLsizei width, GLsizei height)
{
if (height==0)
{
height=1;
}

glViewport(0,0, width, height);

glMatrixMode(GL_PROJECTION);
glLoadIdentity();

gluPerspective(45.0f, (GLfloat)width/(GLfloat)height, 0.1f,100.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}

int InitGL(GLvoid)
{
glShadeModel(GL_SMOOTH);
glClearColor(0.0f, 0.0f, 0.0f, 0.5f); //black background
glClearDepth(1.0f);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);

return TRUE;
}

//prep ends, drawing begins

int DrawGLScene(GLvoid)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslatef(-1.5f,0.0f,-6.0f); //move left 1.5 untis, into screen 6.0
glBegin(GL_TRIANGLES); //begin drawing triangle
glVertex3f( 0.0f, 1.0f, 0.0f); //top
glVertex3f(-1.0f,-1.0f, 0.0f); //bottom left
glVertex3f( 1.0f,-1.0f, 0.0f); //bottom right
glEnd(); //el fin
glTranslatef(3.0f,0.0f,0.0f);
glBegin(GL_QUADS);
glVertex3f(-1.0f, 1.0f, 0.0f);
glVertex3f( 1.0f, 1.0f, 0.0f);
glVertex3f( 1.0f,-1.0f, 0.0f);
glVertex3f(-1.0f,-1.0f, 0.0f);
glEnd();
return TRUE;
}

Share this post


Link to post
Share on other sites
Where do I put it, and how do I put it? whenever I put just main() I get
23 C:\cygwin\home\NCS Customer\OpenGL\main.cpp expected constructor, destructor, or type conversion before "GLvoid"
and
9 C:\cygwin\home\NCS Customer\OpenGL\main.cpp expected constructor, destructor, or type conversion before "HGLRC"

so, where to put it and how to put it?

--edit--
That's if I put either main() or winmain().

Share this post


Link to post
Share on other sites
After everything else, put this. Place the include with your own includes.


#include <iostream>

// set these to your preferred screen dimensions
const int WIDTH = 800, HEIGHT = 600;

int main( int argc, char **argv ) // you can use char *argv[] if you prefer
{
if( SDL_Init(SDL_INIT_VIDEO) < 0 )
{
std::cerr << "Couldn't init sdl: " << SDL_GetError() << '\n';
return 1;
}
atexit(&SDL_Quit);
if( SDL_SetVideoMode(WIDTH,HEIGHT,0,SDL_OPENGL) == NULL )
{
std::cerr << "Couldn't set video mode: " << SDL_GetError() << '\n';
return 1;
}

InitGL();
ReSizeGLScene(WIDTH,HEIGHT);

SDL_Event event;
bool running = true;
while(running)
{
while(SDL_PollEvent(&event)
{
if(event.type == SDL_QUIT){running = false;}
}
DrawGLScene();
SDL_GL_SwapBuffers();
}
}




Note that this hasn't been compiled or tested and may contain errors or typos.

Note that your code looks like a mish-mash from a number of sources, probably online tutorials. As such there are more changes that you could make, but that should compile for you at the moment.

[edit:]

Ok, compiled tested and slightly cleaned version. As predicted, I made a slight mistake, I left out a closing right parentheses around the SDL_PollEvent() call.

Here is code that ran for me:

#include <iostream>
#include "SDL.h"
#include "SDL_opengl.h"

void ReSizeGLScene(int width, int height)
{
if (height==0)
{
height = 1;
}

glViewport(0,0, width, height);

glMatrixMode(GL_PROJECTION);
glLoadIdentity();

gluPerspective(45.0f, (GLfloat)width/(GLfloat)height, 0.1f,100.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}

void InitGL()
{
glShadeModel(GL_SMOOTH);
glClearColor(0.0f, 0.0f, 0.0f, 0.5f); //black background
glClearDepth(1.0f);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
}

void DrawGLScene()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslatef(-1.5f,0.0f,-6.0f); //move left 1.5 untis, into screen 6.0
glBegin(GL_TRIANGLES); //begin drawing triangle
glVertex3f( 0.0f, 1.0f, 0.0f); //top
glVertex3f(-1.0f,-1.0f, 0.0f); //bottom left
glVertex3f( 1.0f,-1.0f, 0.0f); //bottom right
glEnd(); //el fin

glTranslatef(3.0f,0.0f,0.0f);
glBegin(GL_QUADS);
glVertex3f(-1.0f, 1.0f, 0.0f);
glVertex3f( 1.0f, 1.0f, 0.0f);
glVertex3f( 1.0f,-1.0f, 0.0f);
glVertex3f(-1.0f,-1.0f, 0.0f);
glEnd();
}


// set these to your preferred screen dimensions
const int WIDTH = 800, HEIGHT = 600;

int main( int argc, char **argv ) // you can use char *argv[] if you prefer
{
if( SDL_Init(SDL_INIT_VIDEO) < 0 )
{
std::cerr << "Couldn't init sdl: " << SDL_GetError() << '\n';
return 1;
}
atexit(&SDL_Quit);
if( SDL_SetVideoMode(WIDTH,HEIGHT,0,SDL_OPENGL) == NULL )
{
std::cerr << "Couldn't set video mode: " << SDL_GetError() << '\n';
return 1;
}

InitGL();
ReSizeGLScene(WIDTH,HEIGHT);

SDL_Event event;
bool running = true;
while(running)
{
while(SDL_PollEvent(&event))
{
if(event.type == SDL_QUIT){running = false;}
}
DrawGLScene();
SDL_GL_SwapBuffers();
}
}

Share this post


Link to post
Share on other sites
THANK YOU THANK YOU
Very Much!!

it now runs...openGL app w/ a triangle & square!!!
colored after I modified the code a little bit..

Thanks you very much!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this