🔒 Locked
Help with code please.
Advertisement
Original Post
I put the code from chapter 8 in my program for texture mapping from Dave and Kevins book, it compiles fine but when i run it, not cube or texture shows up. Any ideas why this might be? Thanks in advance.
Try posting a little more. Try and isolate the problem yourself; retype the tutorial. Try your damndest to find the problem.
The information you''ve posted gives no clue as to what the problem might be. Possible problems would be:
Not calling glBindTexture(...) before drawing the cube
Having the camera incorrectly positioned
not having called glEnable(GL_TEXTURE_2D)
Not having typed in object coordinates correctly...
Not having typed in texture coordinates correctly...
Try getting it to draw a cube without texture mapping first; if you can''t do that, than your problem probably doesn''t have anything to do with your texture mapping code.
Read, reread, and read again the tutorial. Eventually you''ll get it.
-=skjin=-
The information you''ve posted gives no clue as to what the problem might be. Possible problems would be:
Not calling glBindTexture(...) before drawing the cube
Having the camera incorrectly positioned
not having called glEnable(GL_TEXTURE_2D)
Not having typed in object coordinates correctly...
Not having typed in texture coordinates correctly...
Try getting it to draw a cube without texture mapping first; if you can''t do that, than your problem probably doesn''t have anything to do with your texture mapping code.
Read, reread, and read again the tutorial. Eventually you''ll get it.
I've been working on the code and i got a cube to come up but something's wrong. The cube is drawing but it has parts missing or something, any ideas? here's a link to a screenshot of what's messing up.
http://www21.brinkster.com/asptest8
[edited by - caffeineaddict on January 11, 2003 4:40:33 PM]
http://www21.brinkster.com/asptest8
[edited by - caffeineaddict on January 11, 2003 4:40:33 PM]
OK, i experienced something pretty strange. I put the program on my old computer, running Windows ME, and it ran fine, but the computer i''m developing on is XP and it doesn''t work right on it, any ideas?
Could be a driver issue. Once again, more code will probably expedite a solution.
void DrawTextureCube(float xPos, float yPos, float zPos)
{
glPushMatrix();
glTranslatef(xPos, yPos, zPos);
glBegin(GL_QUADS);
glTexCoord2f(0.0f, 0.0f); glVertex3f(-0.5f, -0.5f, -0.5f);
glTexCoord2f(1.0f, 0.0f); glVertex3f(0.5f, 0.5f, 0.5f);
glTexCoord2f(1.0f, 1.0f); glVertex3f(0.5f, 0.5f, -0.5f);
glTexCoord2f(0.0f, 1.0f); glVertex3f(-0.5f, 0.5f, -0.5f);
glEnd();
glBegin(GL_QUADS);
glTexCoord2f(0.0f, 0.0f); glVertex3f(0.5f, -0.5f, 0.5f);
glTexCoord2f(1.0f, 0.0f); glVertex3f(0.5f, 0.5f, 0.5f);
glTexCoord2f(1.0f, 1.0f); glVertex3f(-0.5f, -0.5f, 0.5f);
glTexCoord2f(0.0f, 1.0f); glVertex3f(-0.5f, -0.5f, 0.5f);
glEnd();
glBegin(GL_QUADS);
glTexCoord2f(0.0f, 0.0f); glVertex3f(0.5f, 0.5f, -0.5f);
glTexCoord2f(1.0f, 0.0f); glVertex3f(0.5f, 0.5f, 0.5f);
glTexCoord2f(1.0f, 1.0f); glVertex3f(0.5f, -0.5f, 0.5f);
glTexCoord2f(0.0f, 1.0f); glVertex3f(0.5f, -0.5f, -0.5f);
glEnd();
glBegin(GL_QUADS);
glTexCoord2f(0.0f, 0.0f); glVertex3f(-0.5f, -0.5f, 0.5f);
glTexCoord2f(1.0f, 0.0f); glVertex3f(-0.5f, 0.5f, 0.5f);
glTexCoord2f(1.0f, 1.0f); glVertex3f(-0.5f, 0.5f, -0.5f);
glTexCoord2f(0.0f, 1.0f); glVertex3f(-0.5f, -0.5f, -0.5f);
glEnd();
glBegin(GL_QUADS);
glTexCoord2f(0.0f, 0.0f); glVertex3f(0.5f, -0.5f, 0.5f);
glTexCoord2f(1.0f, 0.0f); glVertex3f(-.5f, -0.5f, 0.5f);
glTexCoord2f(1.0f, 1.0f); glVertex3f(-.5f, -0.5f, -0.5f);
glTexCoord2f(0.0f, 1.0f); glVertex3f(0.5f, -0.5f, -0.5f);
glEnd();
glBegin(GL_QUADS);
glTexCoord2f(0.0f, 0.0f); glVertex3f(0.5f, 0.5f, -0.5f);
glTexCoord2f(1.0f, 0.0f); glVertex3f(0.5f, -0.5f, -0.5f);
glTexCoord2f(1.0f, 1.0f); glVertex3f(-0.5f, -0.5f, -0.5f);
glTexCoord2f(0.0f, 1.0f); glVertex3f(-0.5f, 0.5f, -0.5f);
glEnd();
glPopMatrix();
}
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); // Declaration For WndProc
GLvoid ReSizeGLScene(GLsizei width, GLsizei height){ // Resize And Initialize The GL Window
if (height==0){ // Prevent A Divide By Zero By
height = 1; // Making Height Equal One
}
glViewport(0, 0, width, height); // Reset The Current Viewport
glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
glLoadIdentity(); // Reset The Projection Matrix
// Calculate The Aspect Ratio Of The Window
gluPerspective(45.0f, (GLfloat)width/(GLfloat)height, 0.1f, 100.0f);
// Reset The Modelview Matrix
}
int InitGL(GLvoid){
glMatrixMode(GL_PROJECTION); // Select The Modelview Matrix
glLoadIdentity();// All Setup For OpenGL Goes Here
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glShadeModel(GL_SMOOTH);
glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
glFrontFace(GL_CCW);
glEnable(GL_TEXTURE_2D);
int DrawGLScene(GLvoid){ // Here's Where We Do All The Drawing
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslatef(0.0f, 0.0f, -3.0f);
DrawTextureCube(0.0f, 0.0f, 0.0f);
if(angle>=360.0f)
angle = 0.0f;
angle += 0.2f;
glFlush();
SwapBuffers(hDC); // Everything Went OK
return 0;
}
this is the main drawing code
[edited by - caffeineaddict on January 11, 2003 5:46:05 PM]
Probably because he wants to define the location of the cube in global coordinates but doesn''t want the transformations to affect the state of the modelview matrix outside of the cube drawing function.
It appears you forgot to call glMatrixMode(GL_MODELVIEW) before drawing.
--------------------------
Those who dance are considered insane by those who cannot hear the music.
Focus On: 3-D Models
--------------------------
Those who dance are considered insane by those who cannot hear the music.
Focus On: 3-D Models
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement