This is my first real attempt at OpenGL with GLFW. In this example I’m trying to bind a texture to a sphere and triangle, but the 512x512 TGA file appears as seemingly an average of the colors in the image. A pointer to correct this problem would be appreciated.
Thanks.
</font><blockquote><font size=“1” face=“Verdana, Arial”>code:</font><hr /><pre style=“font-size:x-small; font-family: monospace;”>
#include <stdio.h>
#include <GL/glfw.h>
#include <gl/glu.h>
GLUquadricObj *sph1;
GLuint texid;
void drawsphere(int x, double t)
{
sph1 = gluNewQuadric();
glTranslatef(0.0, 3.0, 0.0);
glRotatef( 0.3*(GLfloat)x + (GLfloat)t*10.0f, 0.0f, 0.0f, 1.0f );
glBindTexture(GL_TEXTURE_2D, texid);
gluSphere(sph1, 1.0, 20.0, 20.0);
}
void triangle1 ( int x, double t)
{
glTranslatef( 0.0f, 14.0f, 0.0f );
glRotatef( 0.3*(GLfloat)x + (GLfloat)t*100.0f, 0.0f, 0.0f, 1.0f );
glBindTexture(GL_TEXTURE_2D, texid);
glBegin( GL_TRIANGLES );
glVertex3f( -5.0f, 0.0f, -4.0f );
glVertex3f( 5.0f, 0.0f, -4.0f );
glVertex3f( 0.0f, 0.0f, 6.0f );
glEnd();
}
int main( void )
{
int width, height, running, frames, x, y;
double t, t0, fps;
char titlestr[ 200 ];
glfwInit();
if( !glfwOpenWindow( 640, 480, 0,0,0,0, 0,0, GLFW_WINDOW ) )
{
glfwTerminate();
return 0;
}
glGenTextures( 1, &texid );
glBindTexture( GL_TEXTURE_2D, texid );
if( !glfwLoadTexture2D( "one.tga", GLFW_BUILD_MIPMAPS_BIT ) )
{
glfwTerminate();
return 0;
}
// glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
// GL_LINEAR_MIPMAP_LINEAR );
// glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
// GL_LINEAR );
//glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
//glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
glEnable( GL_TEXTURE_2D );
glfwEnable( GLFW_STICKY_KEYS );
glfwSwapInterval( 0 );
running = GL_TRUE;
frames = 0;
t0 = glfwGetTime();
while( running )
{
t = glfwGetTime();
glfwGetMousePos( &x, &y );
if( (t-t0) > 1.0