Archived

This topic is now archived and is closed to further replies.

Fredric

Help with displaying a polygon! :p

Recommended Posts

I''m having trouble compiling the following piece of code: #include ''windows.h'' #include ''gl/gl.h'' #include ''gl/glaux.h'' #include ''conio.h'' void CALLBACK DrawScene() { glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glClear(GL_COLOR_BUFFER_BIT); glBegin(GL_POLYGON); // being drawing the square glColor3f(0.0, 1.0, 0.0); glVertex2f(0.0, 0.0); glVertex2f(5.0, 0.0); glVertex2f(5.0, 5.0); glVertex2f(0.0, 5.0); glEnd(); glFlush(); // force drawing } void main() { auxInitDisplayMode(AUX_SINGLE / AUX_RGBA); auxInitPosition(100,100,250,250); // size and coordinates auxInitWindow("A simple square"); auxMainLoop(DrawScene); cprintf("Push any key to close the coloured window...\n"); getch(); } I''m a newbie, as you can tell- just in case my code is entirely way off, this application is supposed to display a small square inside a window. Whenever I compile it, I get the following errors: Compiling... simple square.cpp Linking... LIBCD.lib(wincrt0.obj) : error LNK2001: unresolved external symbol _WinMain@16 Debug/Simple Square.exe : fatal error LNK1120: 1 unresolved externals Error executing link.exe. Simple Square.exe - 2 error(s), 0 warning(s) What am I missing? Can anyone help me out? Programming::~Fredric(const Annoy_Ance)

Share this post


Link to post
Share on other sites
Thanks a lot! That solved my problem and got rid of the errors, but when I ran my program, the window that was supposed to display my polygon didn''t show up. I looked at the source code to make sure that I cleared the screen BEFORE I drew the polygon, but the polygon doesn''t show up. What am I doing wrong?

Programming::~Fredric(const Annoy_Ance)

Share this post


Link to post
Share on other sites
before glBegin(..);
type, glTranslatef(0.0f,0.0f,-6.0f);
this moves the figure back 6 places in the Z coordinate. Before it was being clipped. If you want to move it around just use this function.
prototype:
glTranslatef(x, y, z);

Share this post


Link to post
Share on other sites
what''s yer viewport? orthographic or perspective? if it''s perspective, then you have to use gluLookAt(x,y,z, x,y,z,0,1,0) in the render code. if you''re using orthographic, make sure the object is within clipping region.

a2k

Share this post


Link to post
Share on other sites
I know this may be a bother, but I''m a newbie as you can tell! Can one of please do me the huge favor of copy and pasting my original source code into a message and making the necessary changes? If you could that would be awesome!

Programming::~Fredric(const Annoy_Ance)

Share this post


Link to post
Share on other sites
you know what. i tried it, but got the same result. my best advice is to not use the auxiliary library, but either the gl/glu library or the glut library, which is easiest of all. you can download it from any opengl site, like opengl.org. starting with glut is really good, cuz it''s easy. you can go to the NeHe pages, and get lots of code from there. they have EXCELLENT tutorials. nehe.gamedev.net. just go to opengl tutorials link. i swear you''ll learn something from there.

i have a question. how''d you earn martyr status without knowing open gl? are you a direct x expert or something?

good luck, and happy coding =)!!

a2k

Share this post


Link to post
Share on other sites
I got to my current status because I like to talk a lot in then lounge.... as well, I''m a C++ programmer!
If I use the GLUT library, I just change aux with glut! What''s the difference?

Programming::~Fredric(const Annoy_Ance)

Share this post


Link to post
Share on other sites
aux is exactly what it is. it''s auxiliary. it''s pretty much for learning, and it''s pretty limited. i don''t think it''s suitable for programming a game. you know what though, i could be fulla shit, but i learned with glut, and all the books out there now cover glut, and it''s just a nice encapsulation of all gl and glu libraries. that''s all.

a2k

Share this post


Link to post
Share on other sites
I know that AUX is used purely for learning and not necessarily suitable for programming a game, but I checked out the source code in my OpenGL red book, and I basically wrote the entire source code that used GLUT, and replaced each GLUT with AUX (I have some previous basic knowledge of AUX) because I was more comfortable with AUX.
Thus... there has to be some way I can make the polygon appear! I mean, the only way I''m using AUX for is initializing the window and making the MainLoop point to the DrawScene function!

Programming::~Fredric(const Annoy_Ance)

Share this post


Link to post
Share on other sites
#include ''windows.h''
#include ''gl/gl.h''
#include ''gl/glaux.h''
#include ''conio.h''

void CALLBACK DrawScene()
{
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_POLYGON); // being drawing the square
glTranslatef(0.0f,0.0f,-6.0f);
glColor3f(0.0, 1.0, 0.0);
glVertex2f(0.0, 0.0);
glVertex2f(5.0, 0.0);
glVertex2f(5.0, 5.0);
glVertex2f(0.0, 5.0);
glEnd();

glFlush(); // force drawing
}

void main()
{
auxInitDisplayMode(AUX_SINGLE / AUX_RGBA);
auxInitPosition(100,100,250,250); // size and coordinates
auxInitWindow("A simple square");

auxMainLoop(DrawScene);


cprintf("Push any key to close the coloured window...\n");
getch();
}

that''s about all you have to do. I usaually use a Win32 console app for OpenGL so my background is a little different. I don''t use the auxilary library. somewhere in the initialization you need to declare the projection type, but this should work.
~Julio

Share this post


Link to post
Share on other sites
I put Translatef() before glBegin()... it compiled fine and everything, but it didn''t make any difference to the output! I still can''t see that green-square that I drew in the window!
Hehe, someone (I think it was you) mentioned that it might be in Orthographic view.. how do I do that? Perhaps that would do the trick? I don''t know! I just wanted some practice in drawing with polygons...

Programming::~Fredric(const Annoy_Ance)

Share this post


Link to post
Share on other sites
i dunno, dude. i''ve been trying yer code for a while now, and i can''t figure it out. actually, one thing, i get this error: "selecting a pixel format failed" if i don''t include glut.h. but here''s the code that i''ve been trying, that has the ortho code in it.

#include
#include
#include
#include
#include


void CALLBACK DrawScene()
{
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClear(GL_COLOR_BUFFER_BIT);

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glPushMatrix();
glTranslatef(0,0,-5);
glBegin(GL_POLYGON); // being drawing the square
glColor3f(1.0, 1.0, 1.0);
glVertex2f(0.0, 0.0);
glVertex2f(5.0, 0.0);
glVertex2f(5.0, 5.0);
glVertex2f(0.0, 5.0);
glEnd();
glPopMatrix();

glFlush(); // force drawing
}

void CALLBACK ChangeSize(GLsizei w, GLsizei h)
{
if (h ==0)
h = 1;

glViewport(0,0,w,h);
glLoadIdentity();
//glOrtho(left, right, bottom, top, near, far)
glOrtho(0, 50, 0, 50, 1, 10);
}


void main()
{
auxInitDisplayMode(AUX_SINGLE / AUX_RGBA);
auxInitPosition(100,100,250,250); // size and coordinates
auxInitWindow("A simple square");
auxReshapeFunc(ChangeSize);
auxMainLoop(DrawScene);


cprintf("Push any key to close the coloured window...\n");
getch();
}



Share this post


Link to post
Share on other sites
Yo Fredric,

To set an Ortographic projection, do that in your main function, after the calls to the AUX library:

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

That will create an Ortho projection that is 10 units large. To create a Perspective projection, do the following:

glMatrixMode(GL_PROJECTION);
glLoadIdentity;
gluPerspective( 45, WINDOW_WIDTH/WINDOW_HEIGHT, 10, 0.1, 10);
glMatrixMode(GL_MODELVIEW);

If you''re learning OpenGL, I would recommend you the Red Book... if you''re like me, you don''t have money to buy it, so here''s its URL:
http://heron.cc.ukans.edu/ebt-bin/nph-dweb/dynaweb/SGI_Developer/OpenGL_PG/@Generic__BookTocView/7109;cd=7;td=6

good luck, hope that helps,
Nicodemus.
glMatrixMode(GL_MODELVIEW);

Share this post


Link to post
Share on other sites
Yo a2k,

Try to remove that part from your DrawScene function:

glMatrixMode(GL_PROJECTION);
glLoadIdentity;
glMatrixMode(GL_MODELVIEW);

and see if it works.

hope that helps,
Nicodemus.

Share this post


Link to post
Share on other sites
nope, still a blank screen.

have you tried out the code? you got it working? i''ve been doing everything known by me, everything in my power, all knowledge of opengl to help this guy out, and it doesn''t work. i don''t use glaux, so i really don''t know if this has an effect, but if you''ve been using glut, fredric, and you got it working, stick with that.


but nicodemus, if you can get it working, i''d like to see the code, cuz it''s got me pretty flustered, myself.

a2k

Share this post


Link to post
Share on other sites
Alright, well thanks for your help. I''ll find my answer from my Math teacher (he likes OpenGL, but I never ask him anything cuz he''s a dick). The reason I asked you and not him is simply because the past two days I didn''t have scholl, so I couldn''t see him, and now I do. I''m sure he''ll be able to resolve my problem! Thanks anyhow, I very much appreciate you trying to help me on this, I really do!

Programming::~Fredric(const Annoy_Ance)

Share this post


Link to post
Share on other sites
Hi Fredric,

I remember when I started programming with OpenGL back in the old days (i.e. about a year ago), I too had problems like this that pissed me off no end.

I haven''t actually tried this code out, but at a glance I picked a few mistakes with what people were giving you (sorry people, I don''t mean to cut you down or anything... peace ).

Try this...


#include ''windows.h''
#include ''gl/gl.h''
#include ''gl/glaux.h''
#include ''conio.h''

void CALLBACK DrawScene()
{
glClear(GL_COLOR_BUFFER_BIT);
glLoadIdentity(); //clears ModelView matrix - I always have it set as the current matrix at this point

//now set up view transformations
glTranslatef(0.0, 0.0, -5.0);

//now you can draw your objects
glPushMatrix(); //save matrix state before drawing
glBegin(GL_POLYGON); // being drawing the square
glColor3f(0.0, 1.0, 0.0);
glVertex2f(0.0, 0.0);
glVertex2f(5.0, 0.0);
glVertex2f(5.0, 5.0);
glVertex2f(0.0, 5.0);
glEnd();
glPopMatrix(); //restore matrix state

glFlush(); // force drawing
}

void CALLBACK ChangeSize(GLsizei w, GLsizei h)
{
/* this gets called on startup, if I''m not mistaken, so this will set up your projection for you to begin with */
if (h ==0)
h = 1;

glViewport(0,0,w,h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
//glOrtho(left, right, bottom, top, near, far)
glOrtho(-10, 10, -10, 10, 0, 10); //mess around with these if you want to change clipping volume

//set matrix mode back to MODELVIEW - just good practice
glMatrixMode(GL_MODELVIEW);
}


void main()
{
auxInitDisplayMode(AUX_SINGLE / AUX_RGBA);
auxInitPosition(100,100,250,250); // size and coordinates
auxInitWindow("A simple square");

//init OpenGL state
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glMatrixMode(GL_MODELVIEW);

//register your resize function
auxReshapeFunc(ChangeSize);

auxMainLoop(DrawScene);


cprintf("Push any key to close the coloured window...\n");
getch();
}



Sorry if I cocked it up and that doesn''t work. BTW, I thoroughly recommend the OpenGL SuperBible (either edition) for learning OpenGL... everything is explained really well.

thankyoubye


-------------
squirrels are a remarkable source of protein...

Share this post


Link to post
Share on other sites
i''m about to try yer code, bad monkey, but yes, opengl superbible is a VERY GOOD recommendation. i live by that one, more useful to game programmers than the red book.

a2k

Share this post


Link to post
Share on other sites
nope, still got that "selecting a pixel format failed" error. and then i add in glut.h, then it causes no errors, but still no square.

i think this is considered an emergency already.
hey fredri, you're math professor give you the answer? cuz this crap is pissing me off. (not that i'm spending all my time on it.)


a2k

(oh, and it's okay if we're all wrong. just get the damn thing working.)




Edited by - a2k on 4/10/00 10:01:10 PM

Edited by - a2k on 4/10/00 10:02:24 PM

Edited by - a2k on 4/10/00 10:02:47 PM

Share this post


Link to post
Share on other sites
Bad Monkey has it correct there. What was happening is that you were using the default modelview and projection transformations from OpenGL - not a good idea. When he sets up that Ortho, it''s telling GL what matrix will put all the vertices in the right position on the screen. The modelview tells GL how you''re eye point affects the points. Naturally, if it can''t tell where your eye is and it also can''t tell how you want it up on the screen, you''re gonna get crap. Good luck in your endeavors.

Pythius

"The object of war is not to die for your country, but to make the other bastard die for his." - General G.C. Patton

Share this post


Link to post
Share on other sites
have you tried compiling it? please tell me you''ve tried to compile it. i''m gonna lose sleep over this, and it''s not even my problem. it''s just not working for me. when i get word that somebody has actually seen this white square on the screen, then tell us all.

a2k

Share this post


Link to post
Share on other sites
BTW, a2k, the message board doesn''t let you use the bar in your message - it is converted to a forward slash.

"The Church says that the world is flat, but I know it is round. For I have seen the shadow of the Earth on the moon, and I have more faith in the shadow than in the Church."

Share this post


Link to post
Share on other sites