undefined reference to `WinMain@16

Started by
1 comment, last by Salatinjsh 12 years, 10 months ago
Hi!

I'm writing a OpenGL program and for texture reading I'm using SDL, but when i add SDL header file it says - "undefined reference to `WinMain@16". I haven't written function to load image and added this SDL header and without SDL header program works. I hope you can help me.

Here is the code:






#include "include/GL/glew.h"
#include "include/GL/glut.h"
#include "include/SDL/SDL.h"




int width = 500;
int height = 500;


GLfloat LightPosition[] = { 0, 0, 0, 0};
GLfloat LightAmbient[] = { 0, 0, 0, 1 };
GLfloat LightDiffuse[] = { 1, 1, 1, 1 };

GLfloat fogColor[4] = {0.5, 0.5, 0.5, 1};


void SetUpFog ()
{
glClearColor(0.5, 0.5, 0.5, 1);

glFogi (GL_FOG_MODE, GL_LINEAR);
glFogfv (GL_FOG_COLOR, fogColor);
glFogf (GL_FOG_DENSITY, 0.01);
glHint (GL_FOG_HINT, GL_NICEST);
glFogf (GL_FOG_START, 0);
glFogf (GL_FOG_END, 10);
}

void Init ()
{
glEnable (GL_BLEND);
glEnable (GL_DEPTH_TEST);
glEnable (GL_COLOR_MATERIAL);
glEnable (GL_LIGHT0);
glEnable (GL_LIGHTING);
glEnable (GL_FOG);
SetUpFog ();
//glutFullScreen();
}

void SetUpLight ()
{
glLightfv(GL_LIGHT0, GL_AMBIENT, LightAmbient);
glLightfv(GL_LIGHT0, GL_DIFFUSE, LightDiffuse);
glLightfv(GL_LIGHT0, GL_POSITION, LightPosition);

glColorMaterial (GL_FRONT, GL_AMBIENT_AND_DIFFUSE);
}




float posz = -6;

void Display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();

glTranslatef(0.0f, 0.0f, posz);

glRotatef(25, 1, 0, 0);
glRotatef(25, 0, 1, 0);

void ToDraw()
{
glColor4f(1, 0, 0, 1);
//glBindTexture(GL_TEXTURE_2D, texture[0]);
glBegin(GL_QUADS);
// Front Face
glNormal3f(0,0,1);
glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f); // Bottom Left Of The Texture and Quad
glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 1.0f); // Bottom Right Of The Texture and Quad
glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, 1.0f); // Top Right Of The Texture and Quad
glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, 1.0f); // Top Left Of The Texture and Quad
// Back Face
glNormal3f(0,0,-1);
glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f); // Bottom Right Of The Texture and Quad
glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f); // Top Right Of The Texture and Quad
glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, 1.0f, -1.0f); // Top Left Of The Texture and Quad
glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f); // Bottom Left Of The Texture and Quad
// Top Face
glNormal3f(0,1,0);
glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f); // Top Left Of The Texture and Quad
glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, 1.0f, 1.0f); // Bottom Left Of The Texture and Quad
glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, 1.0f, 1.0f); // Bottom Right Of The Texture and Quad
glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, -1.0f); // Top Right Of The Texture and Quad
// Bottom Face
glNormal3f(0,-1,0);
glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, -1.0f, -1.0f); // Top Right Of The Texture and Quad
glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, -1.0f, -1.0f); // Top Left Of The Texture and Quad
glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 1.0f); // Bottom Left Of The Texture and Quad
glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f); // Bottom Right Of The Texture and Quad
// Right face
glNormal3f(1,0,0);
glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f); // Bottom Right Of The Texture and Quad
glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, -1.0f); // Top Right Of The Texture and Quad
glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, 1.0f, 1.0f); // Top Left Of The Texture and Quad
glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 1.0f); // Bottom Left Of The Texture and Quad
// Left Face
glNormal3f(-1,0,0);
glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f); // Bottom Left Of The Texture and Quad
glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f); // Bottom Right Of The Texture and Quad
glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, 1.0f, 1.0f); // Top Right Of The Texture and Quad
glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f); // Top Left Of The Texture and Quad
//ground
glNormal3f(0,1,0);
glVertex3f(-100,-1,-100);
glVertex3f(100,-1,-100);
glVertex3f(100,-1,100);
glVertex3f(-100,-1,100);
glEnd();
}

glutSwapBuffers();
}


void OnReshape(int w, int h)
{
glViewport(0, 0, (GLsizei)w, (GLsizei)h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(60, (GLfloat)w / (GLfloat)h, 1.0, 100.0);
glMatrixMode(GL_MODELVIEW);
}

int main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode (GLUT_DOUBLE| GLUT_RGBA);
glutInitWindowSize (width, height);
glutInitWindowPosition (100, 100);
glutCreateWindow ("TEST");

Init();

glutDisplayFunc (Display);
glutIdleFunc (Display);
glutKeyboardFunc (Keyboard);
glutSpecialFunc (KeyboardSpec);
glutReshapeFunc (OnReshape);

glutMainLoop();

return 0;
}






If i could find way how to load OpenGL textures without SDL and it works for every OS i wouldn't use SDL.
Advertisement
SDL is #defining your main function to a function called SDL_main. Try to disable this by using #undef main.

Another option is to use SDL for your windowing and input. Personally I much prefer using SDL for setting up my OpenGL code, because I can structure the code in my own way and avoid using globals.

SDL is #defining your main function to a function called SDL_main. Try to disable this by using #undef main.

Thank you! everything works fine :) but now i have next problem i have to solve :D

This topic is closed to new replies.

Advertisement