![]() |
| | #1 |
| and the Hat of Clumsiness Join Date: Oct 2002
Posts: 1,101
| OpenGL - look trough surface -nehe lesson Im following the Nehe lessons and I'm currently at lesson 06. Since the lesson where he started drawing 3d shapes ( pyramid , cube ) I've experienced some weird things. It seems that if I draw a pyramid, cube or whatever, I can look trough the surface of some quads or triangles. I though that working with textures would resolve this, but it didn't, in fact its when I began working with textures I really saw what was going wrong. Here you can see some screenshots of what is happening. Apart from the texture being a yellow car, and its getting displayed as a blue one, you can see that you can look trough the surfaces .... As you can see it seems as if some quads are not being drawn, although I draw them in my renderScene function... I first though that maybe I should change the point of view ( as in change the z-position, since maybe I might be viewing trough the cube ) but that didnt do anything. This is how I setup the window ( I start from a console window ): Code: void initWindow(int * argc,char *argv[]) {
glutInit(argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
glutCreateWindow("Lesson06");
glutFullScreen();
}
This is how I draw the cube along with it's textures: Code: void renderScene(void) {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslatef(0.0,0.0,0.0);
glRotatef(xrot,1.0,1.0,0.0);
glRotatef(yrot,0.0,1.0,0.0);
glRotatef(zrot,0.0,0.0,1.0);
glEnable(GL_TEXTURE_2D);
/*selecteer ons geladen texture , dit kan niet tussen glBegin en glEnd */
glBindTexture(GL_TEXTURE_2D, 13);
/*start render code*/
glBegin(GL_QUADS);
// Front Face
glNormal3f( 0.0f, 0.0f, 1.0f);
glTexCoord2f(0.0f, 0.0f); glVertex3f(-0.5f, -0.5f, 0.5f); // Bottom Left Of The Texture and Quad
glTexCoord2f(1.0f, 0.0f); glVertex3f( 0.5f, -0.5f, 0.5f); // Bottom Right Of The Texture and Quad
glTexCoord2f(1.0f, 1.0f); glVertex3f( 0.5f, 0.5f, 0.5f); // Top Right Of The Texture and Quad
glTexCoord2f(0.0f, 1.0f); glVertex3f(-0.5f, 0.5f, 0.5f); // Top Left Of The Texture and Quad
// Back Face
glNormal3f( 0.0f, 0.0f,-1.0f);
glTexCoord2f(1.0f, 0.0f); glVertex3f(-0.5f, -0.5f, -0.5f); // Bottom Right Of The Texture and Quad
glTexCoord2f(1.0f, 1.0f); glVertex3f(-0.5f, 0.5f, -0.5f); // Top Right Of The Texture and Quad
glTexCoord2f(0.0f, 1.0f); glVertex3f( 0.5f, 0.5f, -0.5f); // Top Left Of The Texture and Quad
glTexCoord2f(0.0f, 0.0f); glVertex3f( 0.5f, -0.5f, -0.5f); // Bottom Left Of The Texture and Quad
// Top Face
glNormal3f( 0.0f, 1.0f, 0.0f);
glTexCoord2f(0.0f, 1.0f); glVertex3f(-0.5f, 0.5f, -0.5f); // Top Left Of The Texture and Quad
glTexCoord2f(0.0f, 0.0f); glVertex3f(-0.5f, 0.5f, 0.5f); // Bottom Left Of The Texture and Quad
glTexCoord2f(1.0f, 0.0f); glVertex3f( 0.5f, 0.5f, 0.5f); // Bottom Right Of The Texture and Quad
glTexCoord2f(1.0f, 1.0f); glVertex3f( 0.5f, 0.5f, -0.5f); // Top Right Of The Texture and Quad
// Bottom Face
glNormal3f( 0.0f,-1.0f, 0.0f);
glTexCoord2f(1.0f, 1.0f); glVertex3f(-0.5f, -0.5f, -0.5f); // Top Right Of The Texture and Quad
glTexCoord2f(0.0f, 1.0f); glVertex3f( 0.5f, -0.5f, -0.5f); // Top Left Of The Texture and Quad
glTexCoord2f(0.0f, 0.0f); glVertex3f( 0.5f, -0.5f, 0.5f); // Bottom Left Of The Texture and Quad
glTexCoord2f(1.0f, 0.0f); glVertex3f(-0.5f, -0.5f, 0.5f); // Bottom Right Of The Texture and Quad
// Right face
glNormal3f( 1.0f, 0.0f, 0.0f);
glTexCoord2f(1.0f, 0.0f); glVertex3f( 0.5f, -0.5f, -0.5f); // Bottom Right Of The Texture and Quad
glTexCoord2f(1.0f, 1.0f); glVertex3f( 0.5f, 0.5f, -0.5f); // Top Right Of The Texture and Quad
glTexCoord2f(0.0f, 1.0f); glVertex3f( 0.5f, 0.5f, 0.5f); // Top Left Of The Texture and Quad
glTexCoord2f(0.0f, 0.0f); glVertex3f( 0.5f, -0.5f, 0.5f); // Bottom Left Of The Texture and Quad
// Left Face
glNormal3f(-1.0f, 0.0f, 0.0f);
glTexCoord2f(0.0f, 0.0f); glVertex3f(-0.5f, -0.5f, -0.5f); // Bottom Left Of The Texture and Quad
glTexCoord2f(1.0f, 0.0f); glVertex3f(-0.5f, -0.5f, 0.5f); // Bottom Right Of The Texture and Quad
glTexCoord2f(1.0f, 1.0f); glVertex3f(-0.5f, 0.5f, 0.5f); // Top Right Of The Texture and Quad
glTexCoord2f(0.0f, 1.0f); glVertex3f(-0.5f, 0.5f, -0.5f); // Top Left Of The Texture and Quad
glEnd();
/*einde render code */
glutSwapBuffers();
}
Code: int loadGLTextures(const char *textureFileName) {
bitmap bmp;
if(loadBmp(textureFileName,&bmp)==0) {
return 0;
}
glBindTexture(GL_TEXTURE_2D, 13);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
glTexImage2D (GL_TEXTURE_2D, 0, GL_RGB, bmp.width, bmp.height, 0, GL_RGB, GL_UNSIGNED_BYTE, bmp.imageData);
free(bmp.imageData);
return 1;
}
Any help is really appreciated, its probably something stupid but I just don't find the problem. Thanks in advance, Ganglylamb. Last edited by Ken Fitlike; 08-24-2006 at 04:29 AM. Reason: fixed project link |
| GanglyLamb is offline | |
| | #2 |
| Registered User Join Date: Aug 2001
Posts: 244
| maybe enable depth testing glEnable( GL_DEPTH_TEST );
__________________ signature under construction |
| Raven Arkadon is offline | |
| | #3 |
| and the Hat of Clumsiness Join Date: Oct 2002
Posts: 1,101
| Bleh, I saw nehe using that function as well, when it just didnt want to work i removed all the unnecesary things imo. Although before when I used it I called that function before I called createWindow and glutFullScreen... By placing glEnable(GL_DEPTH_TEST); after those two it works perfect .Thanks alot .* nehe's tuts are good, but they lack too much information imo on what each function does exactly and when/ in which order you should call them * |
| GanglyLamb is offline | |
| | #4 |
| Registered User Join Date: Aug 2001
Posts: 244
| thats why there are opengl references which explain every function in detail
__________________ signature under construction |
| Raven Arkadon is offline | |
| | #5 | ||
| and the Hat of Clumsiness Join Date: Oct 2002
Posts: 1,101
| True like http://www.mevis.de/opengl/glEnable.html But for someone that is just starting out with anything graphics related, 3d graphics ( although I have worked with 3dmax etc but that is completely different ), the following does not makes too much sense:Quote:
Quote:
One has a hard time tracking down an error like this, if one does not know the call should be made before a call to some other function, and it is not reported as an error when one does.. the only thing one can do is guess ... Maybe I should just get myself a book, internet tutorials are great, but maybe a book will go about it step by step , instead of jumping into the coding without even having a fair background of the graphics library or 3d graphics using the library... | ||
| GanglyLamb is offline | |
| | #6 |
| Registered User Join Date: Aug 2001
Posts: 244
| hm i guess the red book should be enough to understand the basics of 3d graphics. http://fly.srk.fer.hr/~unreal/theredbook/
__________________ signature under construction Last edited by Raven Arkadon; 08-24-2006 at 06:14 PM. |
| Raven Arkadon is offline | |
| | #7 |
| The Right Honourable Join Date: Mar 2004 Location: Where circles begin.
Posts: 1,068
| You also may want to have a look at Beginning OpenGL Game Programming.
__________________ Memorial University of Newfoundland Computer Science Mac and OpenGL evangelist. |
| psychopath is offline | |
| | #8 |
| and the Hat of Clumsiness Join Date: Oct 2002
Posts: 1,101
| psychopath: That was exactly the book I had in mind, after looking at the sticky at the top of this board and some amazon searching. Raven: I've already bookmarked it, thanks . ( although I still prefer a book over a html version of a book, I like the smell of a fresh book )Thanks everyone in my quest to understand openGL . |
| GanglyLamb is offline | |
| | #9 |
| Super Moderator Join Date: Aug 2001
Posts: 7,819
| Or you can submit to the forces of evil and succumb to the dark side of DX. ![]() Bill is Palpatine. I should get paid to be a DX tech evangelist.
__________________ If you aim at everything you will hit something but you won't know what it is. |
| Bubba is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| OpenGL: How to make surface shiny | ting | Game Programming | 6 | 06-18-2008 05:09 PM |
| OpenGL Window | Morgul | Game Programming | 1 | 05-15-2005 12:34 PM |
| OpenGL Lesson 3 | Gonavitch | C++ Programming | 8 | 08-09-2004 09:31 PM |
| NeHe OpenGL Tut Dont Compile. | oobootsy1 | C++ Programming | 3 | 03-08-2004 10:21 PM |
| Game update... | jdinger | Game Programming | 14 | 11-08-2002 07:10 AM |