(i've updated the code the new better one)
http://www.flickr.com/photos/pkerkm/8251188947/in/photostream
good directions
http://www.flickr.com/photos/pkerkm/8252258464/in/photostream
bad directions
We are using SOIL library
C++
openGL
We drew the symbols of N, S, W, E on one of the images we are displaying, because we thought that the images are being flipped or displayed incorrectly. We were right, but not sure why and how to fix it. Our W is up, E is down, S is right and N is left. This means, that the symbol N is on the left side, as to where it should be on the up part.
Here is the code where we generate the 3-dimmentional array and our pictures.
void genTex(){
texture[0]=SOIL_load_OGL_texture // load an image file directly as a new OpenGL texture
(
"C:\\Users\\Pkerkm\\Documents\\Visual Studio 2010\\Projects\\files\\gameprojecgraphics\\bloodwall2.png",
SOIL_LOAD_AUTO,
SOIL_CREATE_NEW_ID,
SOIL_FLAG_MIPMAPS | SOIL_FLAG_INVERT_Y | SOIL_FLAG_NTSC_SAFE_RGB | SOIL_FLAG_COMPRESS_TO_DXT
);
glBindTexture(GL_TEXTURE_2D, texture[0]);
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);
//glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
}
void /*GraphicsEngine::*/generateMap(){
int i, k, j;
double coordinates[8][3];
for(i=0; i<MAPWIDTH; i++){
for(j=0; j<MAPHEIGHT; j++){
for(k=0; k<MAPDEPTH; k++){
if(stage[i][j][k]==0){
//do nothing
}
else if (stage[i][j][k]==1){
getWallCoordinates(coordinates, i, j, k);
if(j==0 || stage[i][j-1][k]==0){
drawWall(coordinates[0],coordinates[1],coordinates[2],coordinates[3],true);
}
if(j<MAPHEIGHT-1 && stage[i][j+1][k]==0){drawWall(coordinates[7],coordinates[6],coordinates[5],coordinates[4],false);
}
if(i==0 || stage[i-1][j][k]==0){drawWall(coordinates[7],coordinates[4],coordinates[0],coordinates[3],false);
}
if(k==MAPDEPTH-1 || stage[i][j][k+1]==0){drawWall(coordinates[7],coordinates[3],coordinates[2],coordinates[6],false);
}
if(i==MAPWIDTH-1 || stage[i+1][j][k]==0){drawWall(coordinates[6],coordinates[2],coordinates[1],coordinates[5],false);
}
if(k==0 || stage[i][j][k-1]==0){drawWall(coordinates[5],coordinates[1],coordinates[0],coordinates[4],false);
}
}
}
}
}
}
void /*GraphicsEngine::*/drawWall(double a[3],double b[3], double c[3], double d[3], bool floor){
//glColor3f(1.0,0.0,1.0);
if(floor){
glBindTexture(GL_TEXTURE_2D, texture[1]);
}else{
glBindTexture(GL_TEXTURE_2D, texture[0]);
}
//GLuint tex;
//glGenTextures(1, &tex);
glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE,GL_MODULATE );
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
//glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
//glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
//glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
//glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
//tex = LoadTexture("wallsprite.png");
//glBindTexture(GL_TEXTURE_2D, tex);
glEnable(GL_TEXTURE_2D);
glBegin(GL_QUADS);
//glNormal3f(0, 1, 0);
glTexCoord2d(0.0,0.0);
glVertex3dv(a);
glTexCoord2d(-1.0,0.0);
//glVertex3dv(b);
glVertex3dv(d);
glTexCoord2d(-1.0,-1.0);
glVertex3dv(c);
glTexCoord2d(0.0,-1.0);
//glVertex3iv(d);
glVertex3dv(b);
glEnd();
/*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);*/
glDisable( GL_TEXTURE_2D );
}
}
I am thinking the problem is in here, but not sure how to fix it
void /*GraphicsEngine::*/getWallCoordinates(double coordinates[8][3], double x, double y, double z){
int i;
for(i=0;i<8; i++){
if((i/4)>=1){
coordinates[i][1]=BLOCKHEIGHT*(y+1);
}else{
coordinates[i][1]=BLOCKHEIGHT*y;
}
if((i/2)%2==0){
coordinates[i][2]=BLOCKDEPTH*z;
}else{
coordinates[i][2]=BLOCKDEPTH*(z+1);
}
if((i%4)%3==0){
coordinates[i][0]=BLOCKWIDTH*x;
}else{
coordinates[i][0]=BLOCKWIDTH*(x+1);
}
}
}
Simply switch the glTexCoord2f instructions around to rotate the texture by 90 degrees.
Related
I want to render an image on the sphere with any type(e.g jpg tif bmp). so I try the opencv and opengl to do this work. but Iam new for opengl.
below is the code i used.
void createTex(Mat &img)
{
glGenTextures(2, m_texnames);
glBindTexture(GL_TEXTURE_2D, m_texnames[0]);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPLACE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPLACE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
gluBuild2DMipmaps(GL_TEXTURE_2D, 3, img.cols, img.rows, GL_BGR_EXT, GL_UNSIGNED_BYTE, img.data);
}
void sphere()
{
glEnable(GL_TEXTURE_2D);
createTex(src);
glBindTexture(GL_TEXTURE_2D, m_texnames[0]);
glPushMatrix();
gluQuadricTexture(g_text, GLU_TRUE);
gluQuadricDrawStyle(g_text, GLU_FILL);
gluSphere(g_text, 1.0, 64, 64); /*draw sun */
glPopMatrix();
glDisable(GL_TEXTURE_2D);
}
virtual void onDisplay()
{
glClear(GL_COLOR_BUFFER_BIT);
validateCameraPosition();
validateModelPosition();
sphere();
glFlush();
glutSwapBuffers();
}
I cant post a picture for now ; eee.........eee
the picture is very normal (a earth map from wiki), as below.
but ,there is a fault on the sphere when I change the view postion. is there a mistake in my code? and some one can tell why it occurs?
//update:2015.06.28
finally, i found the mistake.
the function gluPerspective() cant take 0.0f that specifies the distance from the viewer to the near clipping plane; i think the 0.0f may disturb the project matix; so the value must be bigger than zero;
below is the code dismistaked;
virtual void onResize(int w, int h)
{
printf("resize window: %d, %d\n", w, h);
glViewport(0, 0, (GLsizei)w, (GLsizei)h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
//gluPerspective(100.0,(GLfloat)w / (GLfloat)h, 0.0/*wrong*/, 20.0);
gluPerspective(100.0, (GLfloat)w / (GLfloat)h, 0.1, 20.0);
//glOrtho(-1, 1, -1, 1,0,20);
}
Not sure if this will help.. but still better than no answers.
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPLACE);
I don't think glTexParameterf is supposed to be used for GL_TEXTURE_WRAP_S. It better be glTextParameteri. Also, I don't thinkg GL_REPLACE is valid value for it. see this reference. I rather:
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
A function that actually uses GL_REPLACE would be glTexEnvi, when pname is GL_TEXTURE_ENV_MODE.
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
Here is a board where some people discussed on that.
Personal note: I would stay away from glu and try to practice rendering myself, with modern OpenGL. Useful tutorial.
I am creating a flat surface and applying a texture for it. But for some reason the texture is not getting applied properly. I am getting something like this.
This is the code that I am using (I have a class for applying textures),
for(int i = 0; i < 512; i++) {
for(int j = 0; j < 512; j++) {
int c = ((((i&0x8)==0)^(((j&0x8))==0)))*255;
checkImage[i][j][0] = (GLubyte) c;
checkImage[i][j][1] = (GLubyte) c;
checkImage[i][j][2] = (GLubyte) c;
checkImage[i][j][3] = (GLubyte)255;
//cout<<"("<<(int)dataForPixel.rgbtRed<<","<<(int)dataForPixel.rgbtGreen<<","<<(int)dataForPixel.rgbtBlue<<")";
}
}
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glGenTextures(1, &texName);
glBindTexture(GL_TEXTURE_2D, texName);
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);
glTexImage2D(GL_TEXTURE_2D,
0,
GL_RGBA,
imageX,
imageY,
0,
GL_RGBA,
GL_UNSIGNED_BYTE,
checkImage
);
glEnable(GL_TEXTURE_2D);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
glBindTexture(GL_TEXTURE_2D, texName);
glBegin(GL_QUADS);
glTexCoord2d(0.0, 0.0); glVertex3d(-100, -100, 0.0);
glTexCoord2d(0.0, 1.0); glVertex3d(-100, 100, 0.0);
glTexCoord2d(1.0, 1.0); glVertex3d( 100, 100, 0.0);
glTexCoord2d(1.0, 0.0); glVertex3d( 100, -100, 0.0);
glEnd();
The image is a 512 x 512 image.
Why is the texture not applying properly.
UPDATE:
The c value is just for producing a chess board pattern which consists of squares of 8 pixels width and height of alternating black and white.
Ok I found out the problem. Seems i was trying to allocate the checkImage memory dynamically but not in one go. So there were gaps in the memory which the OpenGL did not bother with.
Once I fixed it to allocate the memory as one big chunk it worked.
Here is my problem;
Image a box, or a cube, all sides right.
If we were to put the box on a flat surface, the face touching the bottom, would be the floor or base. if the base had an inside, which most boxes do, from the outside you would not be able to see it right.
Unfortunately, in my code you can. instead of a box, you have a room, in which i go outside the room and see the floor, but i should not.
ill post an image of the problem and a video, as well as some code and any code that you might ask for.
http://www.youtube.com/watch?v=ml3-OBGNXXA&feature=youtu.be
http://www.flickr.com/photos/pkerkm/8607171993/
http://www.flickr.com/photos/pkerkm/8608276014/
//here is how i manage the textures
void /*GraphicsEngine::*/drawWall(double a[3],double b[3], double c[3], double d[3], bool floor){
if(floor){
glBindTexture(GL_TEXTURE_2D, texture[1]);
}else{
glBindTexture(GL_TEXTURE_2D, texture[0]);
}
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
//gluBuild2DMipmaps(GL_TEXTURE_2D, 4, width, height, GL_RGBA, GL_UNSIGNED_BYTE, data); // build our texture mipmaps
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
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_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_DECAL);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_DECAL);
//glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
glEnable(GL_TEXTURE_2D);
glBegin(GL_QUADS);
glTexCoord2d(0.0,0.0);
glVertex3dv(a);
glTexCoord2d(-1.0,0.0);
glVertex3dv(d);
glTexCoord2d(-1.0,-1.0);
glVertex3dv(c);
glTexCoord2d(0.0,-1.0);
glVertex3dv(b);
glEnd();
}
//here is the reshape function
void reshape(int w, int h){
//glViewport(0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode(GL_PROJECTION);
//glLoadIdentity();
gluPerspective(60.0, (GLfloat) w/(GLfloat) h, 1.0, 200.0);
glMatrixMode(GL_MODELVIEW);
//glTranslatef(0.0, 0.0, -3.6);
//glLoadIdentity();
}
//here is the display function
void /*GraphicsEngine::*/display(){
//glClearColor (0.0, 0.0, 0.0, 1.0);
//glLoadIdentity ();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
//glShadeModel(GL_FLAT);
//glClearDepth(1.0);
//glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
setPos();
gluLookAt(currentXPos,currentYPos,currentZPos,currentXFace,currentYFace,currentZFace,0,1,0);
generateMap();
graphicsFloor();
int i = 0;
if(projectiles.size()>0){
for(i= 0; i< projectiles.size(); i++){
arrow(projectiles.operator[](i).getXPos(),projectiles.operator[](i).getYPos(),projectiles.operator[](i).getZPos(),0.5,BLOCKWIDTH);
}
projectileMotion();
player.advance();
//glutPostRedisplay();
/*}else if(player.advance()){
glutPostRedisplay();
}*/
}
//glFlush();
glutSwapBuffers();
}
//here is what tells where to draw the floor and the walls
void graphicsFloor(){
int x,z;
//up
for(x=0;x<7;x+=7){
for(z=0;z<105;z+=7){
double a[3] = {x,0,z};
double b[3] = {x+7,0,z};
double c[3] = {x+7,0,z+7};
double d[3] = {x,0,z+7};
drawWall(d,a,b,c,true);
}
}
}
// the walls
void generateMap(){
int z;
int x;
for(z =0;z<105;z+=7){
double a[3] = {0,0,z};
double b[3] = {0,0,z+7};
double c[3] = {0,MAPHEIGHT,z+7};
double d[3] = {0,MAPHEIGHT,z};
drawWall(d,a,b,c,false);
}
for(z =0;z<42;z+=7){
double a[3] = {7,0,z};
double b[3] = {7,0,z+7};
double c[3] = {7,MAPHEIGHT,z+7};
double d[3] = {7,MAPHEIGHT,z};
drawWall(d,a,b,c,false);
}
}
//and here is how i load up the textures
void genTex(){
texture[0]=SOIL_load_OGL_texture // load an image file directly as a new OpenGL texture
(
//"C:\\Users\\Eddy\\Desktop\\Senior Project\\Senior Project\\bloodwall2.png",
"C:\\Users\\Pkerkm\\Documents\\Visual Studio 2010\\Projects\\files\\gameprojecgraphics\\bloodwall2.png",
SOIL_LOAD_AUTO,
SOIL_CREATE_NEW_ID,
SOIL_FLAG_MIPMAPS | SOIL_FLAG_INVERT_Y | SOIL_FLAG_NTSC_SAFE_RGB | SOIL_FLAG_COMPRESS_TO_DXT
//SOIL_FLAG_POWER_OF_TWO| SOIL_FLAG_MIPMAPS| SOIL_FLAG_MULTIPLY_ALPHA| SOIL_FLAG_COMPRESS_TO_DXT| SOIL_FLAG_DDS_LOAD_DIRECT| SOIL_FLAG_INVERT_Y
);
glBindTexture(GL_TEXTURE_2D, texture[0]);
}
It looks like depth testing is disabled. Enable it:
glEnable(GL_DEPTH_TEST);
If that doesn't work, make sure you have a depth buffer and try again.
I'm newbie in OpenGL and trying to get color difference between 2 textures.
It's my init function:
glGenTextures(1, &TEX0);
glBindTexture(GL_TEXTURE_2D, TEX0);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_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_MIN_FILTER, GL_NEAREST);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
glGenTextures(1, &TEX1);
glBindTexture(GL_TEXTURE_2D, TEX1);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_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_MIN_FILTER, GL_NEAREST);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, w, h, 0, MODE, GL_UNSIGNED_BYTE, BUFFER0);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, w, h, 0, MODE, GL_UNSIGNED_BYTE, BUFFER1);
It's my display func:
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glColor3f(1.0f, 1.0f, 1.0f);
glEnable(GL_TEXTURE_2D);
glUseProgram(shader);
glActiveTexture(GL_TEXTURE0 + 0);
glBindTexture(GL_TEXTURE_2D, TEX0);
glActiveTexture(GL_TEXTURE0 + 1);
glBindTexture(GL_TEXTURE_2D, TEX1);
glUniform1i(glGetUniformLocation(shader, "tex0"), 0);
glUniform1i(glGetUniformLocation(shader, "tex1"), 1);
glBegin(GL_QUADS);
glTexCoord2f(0,0); glVertex2f(-1,-1);
glTexCoord2f(0,1); glVertex2f(-1,+1);
glTexCoord2f(1,1); glVertex2f(+1,+1);
glTexCoord2f(1,0); glVertex2f(+1,-1);
glEnd();
glDisable(GL_TEXTURE_2D);
glUseProgram(0);
glFlush();
glutSwapBuffers();
And it's my fragment shader:
uniform sampler2D tex0;
uniform sampler2D tex1;
void main()
{
vec4 otex = texture2D(oframe, gl_TexCoord[0].st);
vec4 ntex = texture2D(nframe, gl_TexCoord[0].st);
gl_FragColor = vec4(abs(otex.rgb - ntex.rgb), 1.0);
}
So the problem is the first activated texture always black. How to solve this?
There are a lot of similar topics, but none of them helped me. Thank you.
First mistake: OpenGL is a state machine. The call of glTexImage effects on the currently bound texture in the currently selective texture unit. You must write it this way:
glGenTextures(1, &tex0);
glBindTexture(GL_TEXTURE_2D, tex0);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, w, h, 0, MODE, GL_UNSIGNED_BYTE, BUFFER0);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glGenTextures(1, &tex1);
glBindTexture(GL_TEXTURE_2D, tex1);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, w, h, 0, MODE, GL_UNSIGNED_BYTE, BUFFER1);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
It doesn't really matter if glTexImage comes before or after glTexParameter of glTexEnv, it works either way. Since you're using a fragment shader glTexEnv is unneccesary. Everything glTexEnv could set has been replaced by the versatility of an expression in a fragment shader.
I'm programming in c++ in opengl.
I'm supposed to make a texture and I made the following code:
void makeCheckImage(void){
int i, j, c;
for (i = 0; i < checkImageHeight; i++) {
for (j = 0; j < checkImageWidth; j++) {
c = ((((i&0x8)==0)^((j&0x8))==0))*255;
checkImage[i][j][0] = (GLubyte) c;
checkImage[i][j][1] = (GLubyte) c;
checkImage[i][j][2] = (GLubyte) c;
checkImage[i][j][3] = (GLubyte) 255;
}
}
}
void init(void){
glClearColor(0.0, 0.0, 0.0, 0.0);
glShadeModel(GL_FLAT);
glEnable(GL_DEPTH_TEST);
makeCheckImage();
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glGenTextures(1, &texName);
glBindTexture(GL_TEXTURE_2D, texName);
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, checkImageWidth,
checkImageHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE,
checkImage);
}
my problem is that this beautiful piece of code (or maybe not) is applying textures to the whole scene! And I just want it to apply to one object...
Can anybody help me?
glEnable(GL_TEXTURE_2D);
//Draw object
glDisable(GL_TEXTURE_2D);