Anonymous
GldiSable (gl_lighting) не имеет значения
Сообщение
Anonymous » 19 сен 2025, 14:58
У меня есть кубик, вращающийся перед 4 плоскими прямоугольниками, которые меняют цвет. Вызов Gldisable (gl_lighting) не останавливает цвета прямоугольников, влияющих на цвет куба. Как я делаю цвет куба, не затронутым прямоугольными цветами?
Код: Выделить всё
//-lglut -lGLEW -lGL -lGLU
#include
#include // Include the GLEW header file
#include
#include // Include the GLUT header file
#include
#include
#include
GLuint texture;
GLfloat angle = 0.0;
// Rotate X
double rX = 0;
// Rotate Y
double rY = 0;
bool running = true;
bool inc = false;
bool inc2 = false;
bool inc3 = false;
bool inc4 = false;
bool* keyStates = new bool[ 256 ];
float yVal = 0.0f;
float yVal2 = 0.1f;
float yVal3 = 0.0f;
float yVal4 = 0.1f;
GLuint LoadBMP( const char* fileName )
{
FILE* file = fopen( fileName, "rb" );
if( !file )
{
printf( "Image could not be loaded\n" );
return 0;
}
unsigned char header[ 54 ];
fread( header, 1, 54, file );
unsigned int dataPos = *(int*)&( header[ 0x0A ] );
unsigned int imageSize = *(int*)&( header[ 0x22 ] );
unsigned int width = *(int*)&( header[ 0x12 ] );
unsigned int height = *(int*)&( header[ 0x16 ] );
if( imageSize == 0 )
{
imageSize = width * height * 3;
}
if( dataPos == 0 )
{
dataPos = 54;
}
unsigned char* data = new unsigned char[ imageSize ];
fread( data, 1, imageSize, file );
fclose( file );
glGenTextures( 1, &texture );
glBindTexture( GL_TEXTURE_2D, texture );
glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_BGR, GL_UNSIGNED_BYTE, data );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
delete( data );
return texture;
}
void FreeTexture( GLuint texture )
{
glDeleteTextures( 1, &texture );
}
void init()
{
glEnable( GL_TEXTURE_2D );
texture = LoadBMP( "Me8.bmp" );
}
void drawCube( void )
{
glBindTexture( GL_TEXTURE_2D, texture );
glScalef( 0.5, 0.5, 0.5 );
glBegin( GL_QUADS );
//front
glTexCoord2f( 0.0f, 0.0f );
glVertex3f( -1.0f, -1.0f, 1.0f );
glTexCoord2f( 1.0f, 0.0f );
glVertex3f( 1.0f, -1.0f, 1.0f );
glTexCoord2f( 1.0f, 1.0f );
glVertex3f( 1.0f, 1.0f, 1.0f );
glTexCoord2f( 0.0f, 1.0f );
glVertex3f( -1.0f, 1.0f, 1.0f );
//back
glTexCoord2f( 0.0f, 0.0f );
glVertex3f( -1.0f, -1.0f, -1.0f );
glTexCoord2f( 1.0f, 0.0f );
glVertex3f( 1.0f, -1.0f, -1.0f );
glTexCoord2f( 1.0f, 1.0f );
glVertex3f( 1.0f, 1.0f, -1.0f );
glTexCoord2f( 0.0f, 1.0f );
glVertex3f( -1.0f, 1.0f, -1.0f );
//top
glTexCoord2f( 0.0f, 0.0f );
glVertex3f( -1.0f, 1.0f, -1.0f );
glTexCoord2f( 1.0f, 0.0f );
glVertex3f( 1.0f, 1.0f, -1.0f );
glTexCoord2f( 1.0f, 1.0f );
glVertex3f( 1.0f, 1.0f, 1.0f );
glTexCoord2f( 0.0f, 1.0f );
glVertex3f( -1.0f, 1.0f, 1.0f );
//bottom
glTexCoord2f( 0.0f, 0.0f );
glVertex3f( -1.0f, -1.0f, -1.0f );
glTexCoord2f( 1.0f, 0.0f );
glVertex3f( 1.0f, -1.0f, -1.0f );
glTexCoord2f( 1.0f, 1.0f );
glVertex3f( 1.0f, -1.0f, 1.0f );
glTexCoord2f( 0.0f, 1.0f );
glVertex3f( -1.0f, -1.0f, 1.0f );
//right
glTexCoord2f( 0.0f, 0.0f );
glVertex3f( 1.0f, -1.0f, -1.0f );
glTexCoord2f( 1.0f, 0.0f );
glVertex3f( 1.0f, 1.0f, -1.0f );
glTexCoord2f( 1.0f, 1.0f );
glVertex3f( 1.0f, 1.0f, 1.0f );
glTexCoord2f( 0.0f, 1.0f );
glVertex3f( 1.0f, -1.0f, 1.0f );
//left
glTexCoord2f( 0.0f, 0.0f );
glVertex3f( -1.0f, -1.0f, -1.0f );
glTexCoord2f( 1.0f, 0.0f );
glVertex3f( -1.0f, 1.0f, -1.0f );
glTexCoord2f( 1.0f, 1.0f );
glVertex3f( -1.0f, 1.0f, 1.0f );
glTexCoord2f( 0.0f, 1.0f );
glVertex3f( -1.0f, -1.0f, 1.0f );
glEnd();
}
void display( void )
{
glClearColor( 0.0, 0.0, 0.0, 1.0 );
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glLoadIdentity();
if( inc )
yVal -= 0.005f;
else
yVal += 0.005f;
if( yVal < -0.1f )
inc = false;
else if( yVal > 1.0f )
inc = true;
if( inc2 )
yVal2 -= 0.005f;
else
yVal2 += 0.005f;
if( yVal2 < -0.1f )
inc2 = false;
else if( yVal2 > 1.0f )
inc2 = true;
if( inc3 )
yVal3 -= 0.005f;
else
yVal3 += 0.005f;
if( yVal3 < -1.0f )
inc3 = false;
else if( yVal3 > 1.0f )
inc3 = true;
if( inc4 )
yVal4 -= 0.005f;
else
yVal4 += 0.005f;
if( yVal4 < -0.5f )
inc4 = false;
else if( yVal4 > 1.0f )
inc4 = true;
// Draw the cube
glColor3f( yVal, 0.0, 0.0 ); // Red
//glRectf(-1.0,1.0,1.0,0.5);
glBegin( GL_QUADS );
glVertex3f( -1.0, 0.5, 0.5 );
glVertex3f( 1.0, 0.5, 0.5 );
glVertex3f( 1.0, 1.0, 0.5 );
glVertex3f( -1.0, 1.0, 0.5 );
glEnd();
glColor3f( 0.0, yVal2, 0.0 ); // Green
glBegin( GL_QUADS );
glVertex3f( -1.0, 0.0, 0.5 );
glVertex3f( 1.0, 0.0, 0.5 );
glVertex3f( 1.0, 0.5, 0.5 );
glVertex3f( -1.0, 0.5, 0.5 );
glEnd();
glColor3f( yVal3, 0.25, 0.0 ); // Orange
glBegin( GL_QUADS );
glVertex3f( -1.0, -0.5, 0.5 );
glVertex3f( 1.0, 0. - 0.5, 0.5 );
glVertex3f( 1.0, 0.0, 0.5 );
glVertex3f( -1.0, 0.0, 0.5 );
glEnd();
glColor3f( 0.0, yVal4, 0.25 ); // Orange
glBegin( GL_QUADS );
glVertex3f( -1.0, -0.5, 0.5 );
glVertex3f( 1.0, 0. - 0.5, 0.5 );
glVertex3f( 1.0, -1.0, 0.5 );
glVertex3f( -1.0, -1.0, 0.5 );
glEnd();
glRotatef( rX, 1.0, 0.0, 0.0 );
// angle Specifies the angle of rotation, in degrees.
//x, y, z Specify the x, y, and z coordinates of a vector, respectively.
glRotatef( rY, 0.0, 1.0, 0.0 );
rX += 0.1;
rY += 0.1;
glutPostRedisplay();
drawCube();
glFlush();
glutSwapBuffers();
}
void reShape( int w, int 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_SINGLE | GLUT_RGB | GLUT_DEPTH );
glutInitWindowSize( 250, 250 );
glutInitWindowPosition( 100, 100 );
glutCreateWindow( "OpenGL Photo Example" );
init();
glutDisplayFunc( display ); //glutDisplayFunc
glDisable( GL_LIGHTING );
glEnable( GL_DEPTH_TEST );
glutMainLoop();
return 0;
}
Я попробовал GldiSable (gl_lighting), чтобы остановить цвета прямоугольников, влияющих на цвет куба, но он не сработал.>
Подробнее здесь:
https://stackoverflow.com/questions/797 ... difference
1758283093
Anonymous
У меня есть кубик, вращающийся перед 4 плоскими прямоугольниками, которые меняют цвет. Вызов Gldisable (gl_lighting) не останавливает цвета прямоугольников, влияющих на цвет куба. Как я делаю цвет куба, не затронутым прямоугольными цветами?[code]//-lglut -lGLEW -lGL -lGLU #include #include // Include the GLEW header file #include #include // Include the GLUT header file #include #include #include GLuint texture; GLfloat angle = 0.0; // Rotate X double rX = 0; // Rotate Y double rY = 0; bool running = true; bool inc = false; bool inc2 = false; bool inc3 = false; bool inc4 = false; bool* keyStates = new bool[ 256 ]; float yVal = 0.0f; float yVal2 = 0.1f; float yVal3 = 0.0f; float yVal4 = 0.1f; GLuint LoadBMP( const char* fileName ) { FILE* file = fopen( fileName, "rb" ); if( !file ) { printf( "Image could not be loaded\n" ); return 0; } unsigned char header[ 54 ]; fread( header, 1, 54, file ); unsigned int dataPos = *(int*)&( header[ 0x0A ] ); unsigned int imageSize = *(int*)&( header[ 0x22 ] ); unsigned int width = *(int*)&( header[ 0x12 ] ); unsigned int height = *(int*)&( header[ 0x16 ] ); if( imageSize == 0 ) { imageSize = width * height * 3; } if( dataPos == 0 ) { dataPos = 54; } unsigned char* data = new unsigned char[ imageSize ]; fread( data, 1, imageSize, file ); fclose( file ); glGenTextures( 1, &texture ); glBindTexture( GL_TEXTURE_2D, texture ); glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_BGR, GL_UNSIGNED_BYTE, data ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); delete( data ); return texture; } void FreeTexture( GLuint texture ) { glDeleteTextures( 1, &texture ); } void init() { glEnable( GL_TEXTURE_2D ); texture = LoadBMP( "Me8.bmp" ); } void drawCube( void ) { glBindTexture( GL_TEXTURE_2D, texture ); glScalef( 0.5, 0.5, 0.5 ); glBegin( GL_QUADS ); //front glTexCoord2f( 0.0f, 0.0f ); glVertex3f( -1.0f, -1.0f, 1.0f ); glTexCoord2f( 1.0f, 0.0f ); glVertex3f( 1.0f, -1.0f, 1.0f ); glTexCoord2f( 1.0f, 1.0f ); glVertex3f( 1.0f, 1.0f, 1.0f ); glTexCoord2f( 0.0f, 1.0f ); glVertex3f( -1.0f, 1.0f, 1.0f ); //back glTexCoord2f( 0.0f, 0.0f ); glVertex3f( -1.0f, -1.0f, -1.0f ); glTexCoord2f( 1.0f, 0.0f ); glVertex3f( 1.0f, -1.0f, -1.0f ); glTexCoord2f( 1.0f, 1.0f ); glVertex3f( 1.0f, 1.0f, -1.0f ); glTexCoord2f( 0.0f, 1.0f ); glVertex3f( -1.0f, 1.0f, -1.0f ); //top glTexCoord2f( 0.0f, 0.0f ); glVertex3f( -1.0f, 1.0f, -1.0f ); glTexCoord2f( 1.0f, 0.0f ); glVertex3f( 1.0f, 1.0f, -1.0f ); glTexCoord2f( 1.0f, 1.0f ); glVertex3f( 1.0f, 1.0f, 1.0f ); glTexCoord2f( 0.0f, 1.0f ); glVertex3f( -1.0f, 1.0f, 1.0f ); //bottom glTexCoord2f( 0.0f, 0.0f ); glVertex3f( -1.0f, -1.0f, -1.0f ); glTexCoord2f( 1.0f, 0.0f ); glVertex3f( 1.0f, -1.0f, -1.0f ); glTexCoord2f( 1.0f, 1.0f ); glVertex3f( 1.0f, -1.0f, 1.0f ); glTexCoord2f( 0.0f, 1.0f ); glVertex3f( -1.0f, -1.0f, 1.0f ); //right glTexCoord2f( 0.0f, 0.0f ); glVertex3f( 1.0f, -1.0f, -1.0f ); glTexCoord2f( 1.0f, 0.0f ); glVertex3f( 1.0f, 1.0f, -1.0f ); glTexCoord2f( 1.0f, 1.0f ); glVertex3f( 1.0f, 1.0f, 1.0f ); glTexCoord2f( 0.0f, 1.0f ); glVertex3f( 1.0f, -1.0f, 1.0f ); //left glTexCoord2f( 0.0f, 0.0f ); glVertex3f( -1.0f, -1.0f, -1.0f ); glTexCoord2f( 1.0f, 0.0f ); glVertex3f( -1.0f, 1.0f, -1.0f ); glTexCoord2f( 1.0f, 1.0f ); glVertex3f( -1.0f, 1.0f, 1.0f ); glTexCoord2f( 0.0f, 1.0f ); glVertex3f( -1.0f, -1.0f, 1.0f ); glEnd(); } void display( void ) { glClearColor( 0.0, 0.0, 0.0, 1.0 ); glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); glLoadIdentity(); if( inc ) yVal -= 0.005f; else yVal += 0.005f; if( yVal < -0.1f ) inc = false; else if( yVal > 1.0f ) inc = true; if( inc2 ) yVal2 -= 0.005f; else yVal2 += 0.005f; if( yVal2 < -0.1f ) inc2 = false; else if( yVal2 > 1.0f ) inc2 = true; if( inc3 ) yVal3 -= 0.005f; else yVal3 += 0.005f; if( yVal3 < -1.0f ) inc3 = false; else if( yVal3 > 1.0f ) inc3 = true; if( inc4 ) yVal4 -= 0.005f; else yVal4 += 0.005f; if( yVal4 < -0.5f ) inc4 = false; else if( yVal4 > 1.0f ) inc4 = true; // Draw the cube glColor3f( yVal, 0.0, 0.0 ); // Red //glRectf(-1.0,1.0,1.0,0.5); glBegin( GL_QUADS ); glVertex3f( -1.0, 0.5, 0.5 ); glVertex3f( 1.0, 0.5, 0.5 ); glVertex3f( 1.0, 1.0, 0.5 ); glVertex3f( -1.0, 1.0, 0.5 ); glEnd(); glColor3f( 0.0, yVal2, 0.0 ); // Green glBegin( GL_QUADS ); glVertex3f( -1.0, 0.0, 0.5 ); glVertex3f( 1.0, 0.0, 0.5 ); glVertex3f( 1.0, 0.5, 0.5 ); glVertex3f( -1.0, 0.5, 0.5 ); glEnd(); glColor3f( yVal3, 0.25, 0.0 ); // Orange glBegin( GL_QUADS ); glVertex3f( -1.0, -0.5, 0.5 ); glVertex3f( 1.0, 0. - 0.5, 0.5 ); glVertex3f( 1.0, 0.0, 0.5 ); glVertex3f( -1.0, 0.0, 0.5 ); glEnd(); glColor3f( 0.0, yVal4, 0.25 ); // Orange glBegin( GL_QUADS ); glVertex3f( -1.0, -0.5, 0.5 ); glVertex3f( 1.0, 0. - 0.5, 0.5 ); glVertex3f( 1.0, -1.0, 0.5 ); glVertex3f( -1.0, -1.0, 0.5 ); glEnd(); glRotatef( rX, 1.0, 0.0, 0.0 ); // angle Specifies the angle of rotation, in degrees. //x, y, z Specify the x, y, and z coordinates of a vector, respectively. glRotatef( rY, 0.0, 1.0, 0.0 ); rX += 0.1; rY += 0.1; glutPostRedisplay(); drawCube(); glFlush(); glutSwapBuffers(); } void reShape( int w, int 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_SINGLE | GLUT_RGB | GLUT_DEPTH ); glutInitWindowSize( 250, 250 ); glutInitWindowPosition( 100, 100 ); glutCreateWindow( "OpenGL Photo Example" ); init(); glutDisplayFunc( display ); //glutDisplayFunc glDisable( GL_LIGHTING ); glEnable( GL_DEPTH_TEST ); glutMainLoop(); return 0; } [/code] Я попробовал GldiSable (gl_lighting), чтобы остановить цвета прямоугольников, влияющих на цвет куба, но он не сработал.> Подробнее здесь: [url]https://stackoverflow.com/questions/79768840/gldisablegl-lighting-not-making-a-difference[/url]