GL_TEXTURE_2D и всё ужасно рендерится
Пишу на opengl c glut.
Код:
#include <GL/glut.h>
void Reshape(int width, int height)
{
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(-1, 1, -1, 1);
glMatrixMode(GL_MODELVIEW);
}
void Draw(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(0.0f, 0.0f, 1.0f);
glLineWidth(1);
glBegin(GL_LINES);
glVertex2f(0, 0.5f);
glVertex2f(0, -0.5f);
glEnd();
glFlush();
}
int main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutInitWindowSize(400, 300);
glutInitWindowPosition(100, 100);
glutInitDisplayMode(GLUT_RGB);
glutCreateWindow("Demo Screen");
glutReshapeFunc(Reshape);
glutDisplayFunc(Draw);
glClearColor(0, 0, 0, 0);
glutMainLoop();
return 0;
}
void Reshape(int width, int height)
{
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(-1, 1, -1, 1);
glMatrixMode(GL_MODELVIEW);
}
void Draw(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(0.0f, 0.0f, 1.0f);
glLineWidth(1);
glBegin(GL_LINES);
glVertex2f(0, 0.5f);
glVertex2f(0, -0.5f);
glEnd();
glFlush();
}
int main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutInitWindowSize(400, 300);
glutInitWindowPosition(100, 100);
glutInitDisplayMode(GLUT_RGB);
glutCreateWindow("Demo Screen");
glutReshapeFunc(Reshape);
glutDisplayFunc(Draw);
glClearColor(0, 0, 0, 0);
glutMainLoop();
return 0;
}
возможно неправильно загружается текстура. напиши свой загрузчик или изучи урок того же nehe по загрузке tga
UserNet2008, этот код работает, выводит на чёрный фон линию. Мне кажется, что у меня дело в glEnable(GL_TEXTURE_2D), но если это убрать, текстура (а затекстурирован у меня был только фон) выглядит как зелёный квадрат.
void Reshape(int width, int height)
{
glViewport(2, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(-1, 1, -1, 1);
glMatrixMode(GL_MODELVIEW);
}
void Draw(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(0.0f, 0.1f, 0.0f, 1.0f);
glLineWidth(1.0f);
glBegin(GL_LINES);
glVertex2f(0, 0.5f);
glVertex2f(0, -0.5f);
glEnd();
glFlush();
}
int main(int argc, char *argv[])
glBegin(GL_LINES);
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(0.0f, 1.0f, 0.0f, 1.0f);
glLineWidth(1.0f);
glFlush();
{
glutInit(&argc, argv);
glutInitWindowSize(400, 300);
glutInitWindowPosition(100, 100);
glutInitDisplayMode(GLUT_RGB);
glutCreateWindow("Demo Screen");
glutReshapeFunc(Reshape);
glutDisplayFunc(Draw);
glClearColor(0, 0, 0, 0);
glutMainLoop();
return 0;
}
Может у Вас редактор не настроен (это я про VC++), а если Borland C++ то это не ко мне.
Код:
#include <GL/gl.h>
#include <GL/glu.h>
#include <glut.h>
#include <stdlib.h>
#include <stdio.h>
#define checkImageW 16
#define checkImageH 16
static GLubyte ShowImage1[checkImageH][checkImageW][4];
static GLuint ObjectName;
void makeCheckImage(void)
{
int i, j, c;
for (i = 0; i < checkImageH; i++) {
for (j = 0; j < checkImageW; j++) {
c = ((((i&0x8)==0)^((j&0x8))==0))*255;
ShowImage1[i][j][0] = (GLubyte) c;
ShowImage1[i][j][1] = (GLubyte) c;
ShowImage1[i][j][2] = (GLubyte) c;
ShowImage1[i][j][3] = (GLubyte) 255;
}
}
}
void init(void)
{
glClearColor (1.0,0.0,0.0,0.0);
glShadeModel(GL_FLAT);
glEnable(GL_DEPTH_TEST);
makeCheckImage();
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glGenTextures(1, &ObjectName);
glBindTexture(GL_TEXTURE_2D, ObjectName);
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_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, checkImageW,
checkImageH, 0, GL_RGBA, GL_UNSIGNED_BYTE,
ShowImage1);
}
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable(GL_TEXTURE_2D);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
glBindTexture(GL_TEXTURE_2D, ObjectName);
glBegin(GL_QUADS);
glTexCoord2f(0.0, 0.0); glVertex3f(-2.0, -1.0, 0.0);
glTexCoord2f(0.0, 1.0); glVertex3f(-2.0, 1.0, 0.0);
glTexCoord2f(1.0, 1.0); glVertex3f(0.0, 1.0, 0.0);
glTexCoord2f(1.0, 0.0); glVertex3f(0.0, -1.0, 0.0);
glEnd();
glFlush();
glDisable(GL_TEXTURE_2D);
}
void reshape(int w, int h)
{
glViewport(52, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(60.0, (GLfloat) w/(GLfloat) h, 1.0, 30.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0.0, 0.0, -3.6);
}
void keyboard (unsigned char key, int x, int y)
{
switch (key) {
case 27:
exit(0);
break;
default:
break;
}
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(250, 250);
glutInitWindowPosition(100, 100);
glutCreateWindow("Demo Screen");
init();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutKeyboardFunc(keyboard);
glutMainLoop();
return 0;
}
#include <GL/glu.h>
#include <glut.h>
#include <stdlib.h>
#include <stdio.h>
#define checkImageW 16
#define checkImageH 16
static GLubyte ShowImage1[checkImageH][checkImageW][4];
static GLuint ObjectName;
void makeCheckImage(void)
{
int i, j, c;
for (i = 0; i < checkImageH; i++) {
for (j = 0; j < checkImageW; j++) {
c = ((((i&0x8)==0)^((j&0x8))==0))*255;
ShowImage1[i][j][0] = (GLubyte) c;
ShowImage1[i][j][1] = (GLubyte) c;
ShowImage1[i][j][2] = (GLubyte) c;
ShowImage1[i][j][3] = (GLubyte) 255;
}
}
}
void init(void)
{
glClearColor (1.0,0.0,0.0,0.0);
glShadeModel(GL_FLAT);
glEnable(GL_DEPTH_TEST);
makeCheckImage();
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glGenTextures(1, &ObjectName);
glBindTexture(GL_TEXTURE_2D, ObjectName);
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_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, checkImageW,
checkImageH, 0, GL_RGBA, GL_UNSIGNED_BYTE,
ShowImage1);
}
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable(GL_TEXTURE_2D);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
glBindTexture(GL_TEXTURE_2D, ObjectName);
glBegin(GL_QUADS);
glTexCoord2f(0.0, 0.0); glVertex3f(-2.0, -1.0, 0.0);
glTexCoord2f(0.0, 1.0); glVertex3f(-2.0, 1.0, 0.0);
glTexCoord2f(1.0, 1.0); glVertex3f(0.0, 1.0, 0.0);
glTexCoord2f(1.0, 0.0); glVertex3f(0.0, -1.0, 0.0);
glEnd();
glFlush();
glDisable(GL_TEXTURE_2D);
}
void reshape(int w, int h)
{
glViewport(52, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(60.0, (GLfloat) w/(GLfloat) h, 1.0, 30.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0.0, 0.0, -3.6);
}
void keyboard (unsigned char key, int x, int y)
{
switch (key) {
case 27:
exit(0);
break;
default:
break;
}
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(250, 250);
glutInitWindowPosition(100, 100);
glutCreateWindow("Demo Screen");
init();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutKeyboardFunc(keyboard);
glutMainLoop();
return 0;
}
2.
s Super Game 2\TSGame2 v.0.2 - копия\main.cpp|14|error: 'checkImageH' was not declared in this scope|
s Super Game 2\TSGame2 v.0.2 - копия\main.cpp|14|error: 'checkImageW' was not declared in this scope|
s Super Game 2\TSGame2 v.0.2 - копия\main.cpp||In function 'void makeCheckImage()':|
s Super Game 2\TSGame2 v.0.2 - копия\main.cpp|22|error: 'checkImageH' was not declared in this scope|
s Super Game 2\TSGame2 v.0.2 - копия\main.cpp|23|error: 'checkImageW' was not declared in this scope|
s Super Game 2\TSGame2 v.0.2 - копия\main.cpp|24|warning: suggest parentheses around comparison in operand of '^'|
s Super Game 2\TSGame2 v.0.2 - копия\main.cpp|25|error: 'ShowImage1' was not declared in this scope|
s Super Game 2\TSGame2 v.0.2 - копия\main.cpp||In function 'void init()':|
s Super Game 2\TSGame2 v.0.2 - копия\main.cpp|51|error: 'checkImageW' was not declared in this scope|
s Super Game 2\TSGame2 v.0.2 - копия\main.cpp|52|error: 'checkImageH' was not declared in this scope|
s Super Game 2\TSGame2 v.0.2 - копия\main.cpp|53|error: 'ShowImage1' was not declared in this scope|
||=== Build finished: 8 errors, 1 warnings (0 minutes, 2 seconds) ===|