# Need Help with pushing an object (Sokoban)

Hello everyone!

I have to prepare a collage project and for this project I have to create Sokoban (the game where you have to move blocks on specific places in order to win). I worked on it for a bit but now I am stuck for already 3 days. I tried a few things but nothing worked. My problem is that after creating the main box (that is the player) and creating the boxes that I have to move it seems like anything I tried won’t make the player box push the other boxes. At first I tried to match coordinates. So what I did wast to use an “if” and tell the program to move the objects together if theirs coordinates are equal. After 2 days of not understanding why this works I found out that their coordinates would never be equal because my program apparently things that the player box has one coordinate 0.4000006 and the other coordinate (the one it is supposed to be equal to) is 0.1000001. So even if I move the player box it will never be equal as there will always be a difference.

Now I managed to make it push the box but again I run into a problem: it pushes it if they have the same Y but it doesn’t push it only when it is next to it, but also when it is far away.

Here is the code:

I honestly hope someone is going to help me and explain me what I am supposed to do.

``````#include "glut.h"
#include <stdio.h>

int t = 0;
//float xX = 0.05, yY = -0.05;
float xX = 0, yY = 0;
//float OxA = 0.4, OyA = -0.45, OxB = -0.45, OyB = -0.45, OxC = 0.45, OyC = -0.4, OxD = 0.4, OyD = -0.4;
//float CXA = 0.4, CYA = -0.4, CXB = 0.6, CYB = -0.4, CXC = 0.6, CYC = -0.6, CXD = 0.4, CYD = -0.6;
float CXA = 0.4, CYA = -0.45, CXB = -0.45, CYB = -0.45, CXC = 0.45, CYC = -0.4, CXD = 0.4, CYD = -0.4;
float C1xA = 0.05, C1yA = -0.25, C1xB = 0.1, C1yB = -0.25, C1xC = 0.1, C1yC = -0.2, C1xD = 0.05, C1yD = -0.2;
float C2xA = 0.15, C2yA = -0.25, C2xB = 0.2, C2yB = -0.25, C2xC = 0.2, C2yC = -0.2, C2xD = 0.15, C2yD = -0.2;
float C3xA = 0.25, C3yA = -0.25, C3xB = 0.3, C3yB = -0.25, C3xC = 0.3, C3yC = -0.2, C3xD = 0.25, C3yD = -0.2;

void init(void)
{
glClearColor(0.0, 0.0, 0.0, 0.0);
}

void miscarea(float &x1, float &y1, float &x2, float &y2, float &x3, float &y3, float &x4, float &y4, float q, float w)
{
x1 = x1 + q;  // q este pasul pe x
x2 = x3 + q;
x3 = x3 + q;
x4 = x4 + q;

y1 = y1 + w;  //w pasul pe y
y2 = y2 + w;
y3 = y3 + w;
y4 = y4 + w;
}

void taste()
{
switch (t)
{
case 1:

xX = -0.05;
break;
case 2:
xX = 0.05;
break;
case 3:
yY = 0.05;
break;
case 4:
yY = -0.05;
break;
}
}

void verificare();

void k(unsigned char key, int x, int y)
{
switch (key)
{
case 'w':
t = 3;
glutPostRedisplay();
break;
case 'a':
t = 1;
glutPostRedisplay();
break;
case's':
t = 4;
glutPostRedisplay();
break;
case'd':
t = 2;
glutPostRedisplay();
break;
}

} //comenzi de miscare

void display(void)
{

xX = 0;
yY = 0;
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glBegin(GL_POLYGON); //asta e patratul de pe drepta
glColor3f(1.0, 0.0, 0.0);
glVertex2f(0.45, 0.5);
glVertex2f(0.5, 0.5);
glVertex2f(0.5, -0.5);
glVertex2f(0.45, -0.5);
glEnd();

glBegin(GL_POLYGON); //patratul de pe Ox
glColor3f(1.0, 0.0, 0.0);
glVertex2f(-0.5, 0);
glVertex2f(-0.1, 0);
glVertex2f(-0.1, -0.05);
glVertex2f(-0.5, -0.05);
glEnd();

glBegin(GL_POLYGON); //patratul de sus
glColor3f(1.0, 0.0, 0.0);
glVertex2f(-0.5, 0.5);
glVertex2f(-0.5, 0.45);
glVertex2f(0.5, 0.45);
glVertex2f(0.5, 0.5);
glEnd();

glBegin(GL_POLYGON);// patratul din stanga sus
glColor3f(1.0, 0.0, 0.0);
glVertex2f(-0.5, 0.5);
glVertex2f(-0.45, 0.5);
glVertex2f(-0.45, 0);
glVertex2f(-0.5, 0);
glEnd();

glBegin(GL_POLYGON); //patrat stanga jos
glColor3f(1.0, 0.0, 0.0);
glVertex2f(-0.15, -0.5);
glVertex2f(-0.1, -0.5);
glVertex2f(-0.1, 0);
glVertex2f(-0.15, 0);
glEnd();

glBegin(GL_POLYGON); //patrat jos
glColor3f(1.0, 0.0, 0.0);
glVertex2f(0.5, -0.5);
glVertex2f(0.5, -0.45);
glVertex2f(-0.15, -0.45);
glVertex2f(-0.15, -0.5);
glEnd();

glBegin(GL_POLYGON); //patratul din dreapta sus mijloc
glColor3f(1.0, 0.0, 0.0);
glVertex2f(0.5, 0.3);
glVertex2f(0.5, 0.25);
glVertex2f(0.1, 0.25);
glVertex2f(0.1, 0.3);
glEnd();

glBegin(GL_POLYGON); //p1
glColor3f(0.0, 1.0, 1.0);
glVertex2f(-0.45, 0.4);
glVertex2f(-0.45, 0.35);
glVertex2f(-0.4, 0.35);
glVertex2f(-0.4, 0.4);
glEnd();

glBegin(GL_POLYGON); //p2
glColor3f(0.0, 1.0, 1.0);
glVertex2f(0.25, 0.3);
glVertex2f(0.25, 0.35);
glVertex2f(0.3, 0.35);
glVertex2f(0.3, 0.3);
glEnd();

glBegin(GL_POLYGON); //p3
glColor3f(0.0, 1.0, 1.0);
glVertex2f(-0.1, 0.0);
glVertex2f(-0.1, -0.05);
glVertex2f(-0.05, -0.05);
glVertex2f(-0.05, 0.0);
glEnd();

taste();

miscarea(CXA, CYA, CXB, CYB, CXC, CYC, CXD, CYD, xX, yY);

//Conditii verif C1

/*1ST ATTEMPT: */   /*if (((((CXA - C1xB) > -0.00005) && (CXA - C1xB) < 0) || ((CXA - C1xB)<0.00005) && (CXA - C1xB) > 0) && (((CYA - C1yB) > -0.00005) && (CYA - C1yB) < 0) || (((CYA - C1yB)<0.00005) && (CYA - C1yB) > 0))
{
miscarea(C1xA, C1yA, C1xB, C1yB, C1xC, C1yC, C1xD, C1yD, xX, yY);
}*/

/*2ND ATTEMPT: */ if ((((((CXA - C1xB) > -0.00005) && (CXA - C1xB) < 0) || ((CXA - C1xB)<0.00005) && (CXA - C1xB) > 0) && (((CYA - C1yB) > -0.00005) && (CYA - C1yB) < 0) || (((CYA - C1yB)<0.00005) && (CYA - C1yB) > 0)) && (((((CXD - C1xC) > -0.00002) && (CXD - C1xC) < 0) || ((CXD - C1xC)<0.00002) && (CXD - C1xC) > 0) && (((CYD - C1yC) > -0.00002) && (CYD - C1yC) < 0) || (((CYD - C1yC)<0.00002) && (CYD - C1yC) > 0) && t==2) )
{
miscarea(C1xA, C1yA, C1xB, C1yB, C1xC, C1yC, C1xD, C1yD, xX, yY);
}

//(((((CXD - C1xC) > -0.00005) && (CXD - C1xC) < 0) || ((CXD - C1xC)<0.00005) && (CXD - C1xC) > 0) && (((CYC - C1yD) > -0.00005) && (CYC - C1yD) < 0) || (((CYC - C1yD)<0.00005) && (CYC - C1yD) > 0))

/*3RD ATTEMPT: */ /* if ((((((CXB - C1xA) > -0.00005) && (CXB - C1xA) < 0) || ((CXB - C1xA)<0.00005) && (CXB - C1xA) > 0) && (((CYB - C1yA) > -0.00005) && (CYB - C1yA) < 0) || (((CYB - C1yA)<0.00005) && (CYB - C1yA) > 0)) && (((((CXC - C1xD) > -0.00002) && (CXC - C1xD) < 0) || ((CXC - C1xD)<0.00002) && (CXC - C1xD) > 0) && (((CYC - C1yD) > -0.00002) && (CYC - C1yD) < 0) || (((CYC - C1yD)<0.00002) && (CYC - C1yD) > 0) && t == 1))
{
miscarea(C1xA, C1yA, C1xB, C1yB, C1xC, C1yC, C1xD, C1yD, xX, yY);                                              //Misca si stanga si dreapta dar si de la distata
}

/*3RD ATTEMPT: */ /* if ((((((CXD - C1xA) > -0.00005) && (CXD - C1xA) < 0) || ((CXD - C1xA)<0.00005) && (CXD - C1xA) > 0) && (((CYD - C1yA) > -0.00005) && (CYD - C1yA) < 0) || (((CYD - C1yA)<0.00005) && (CYD - C1yA) > 0)) && (((((CXC - C1xB) > -0.00002) && (CXC - C1xB) < 0) || ((CXC - C1xB)<0.00002) && (CXC - C1xB) > 0) && (((CYC - C1yB) > -0.00002) && (CYC - C1yB) < 0) || (((CYC - C1yB)<0.00002) && (CYC - C1yB) > 0) && t==1))
{
miscarea(C1xA, C1yA, C1xB, C1yB, C1xC, C1yC, C1xD, C1yD, xX, yY);                                              //Misca si stanga si dreapta dar si de la distata
}

/*3RD ATTEMPT: */  /* if ((((((CXA - C1xD) > -0.00005) && (CXA - C1xD) < 0) || ((CXA - C1xD)<0.00005) && (CXA - C1xD) > 0) && (((CYA - C1yD) > -0.00005) && (CYA - C1yD) < 0) || (((CYA - C1yD)<0.00005) && (CYA - C1yD) > 0)) && (((((CXB - C1xC) > -0.00002) && (CXB - C1xC) < 0) || ((CXB - C1xC)<0.00002) && (CXB - C1xC) > 0) && (((CYB - C1yC) > -0.00002) && (CYB - C1yC) < 0) || (((CYB - C1yC)<0.00002) && (CYB - C1yC) > 0) && t == 4))
{
miscarea(C1xA, C1yA, C1xB, C1yB, C1xC, C1yC, C1xD, C1yD, xX, yY);                                              //Misca si stanga si dreapta dar si de la distata
} */

//DOLAN, PLS D_D

//CREEARE CUB PRINCIPAL
glBegin(GL_POLYGON);
glColor3f(1.0, 0.5, 0.0);
glVertex2f(CXA, CYA);
glVertex2f(CXB, CYB);
glVertex2f(CXC, CYC);
glVertex2f(CXD, CYD);
glEnd();
//SF CUB PRINCIPAL

//CREEARE CUTIA 1
glColor3f(0.0, 0.5, 0.0);
glBegin(GL_POLYGON);
glVertex2f(C1xA, C1yA);
glVertex2f(C1xB, C1yB);
glVertex2f(C1xC, C1yC);
glVertex2f(C1xD, C1yD);
glEnd();
//SF CUTIA 1

//CREEARE CUTIA 2
glColor3f(0.0, 0.5, 0.0);
glBegin(GL_POLYGON);
glVertex2f(C2xA, C2yA);
glVertex2f(C2xB, C2yB);
glVertex2f(C2xC, C2yC);
glVertex2f(C2xD, C2yD);
glEnd();
//SF CUTIA 2

//CREEARE CUTIA 3
glColor3f(0.0, 0.5, 0.0);
glBegin(GL_POLYGON);
glVertex2f(C3xA, C3yA);
glVertex2f(C3xB, C3yB);
glVertex2f(C3xC, C3yC);
glVertex2f(C3xD, C3yD);
glEnd();
//SF CUTIA 3

glDisable(GL_TEXTURE_2D); //sa nu faca backround-ul de la png o poza
glFlush();

}

int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(700, 700);
glutInitWindowPosition(100, 100);
glutCreateWindow("Sokoban");
init();
glutDisplayFunc(display);
glutKeyboardFunc(k);
glutMainLoop();
return 0;
}
``````

Best regards,
Mihai Ilie

Hi,

is it part of the assignment that you have to use OpenGL? Elsewise you would probably do yourself a hugh favor by using a 2D-widget library like Qt, GTK+ or SFML. OpenGL seems very overkill for this.

``````int t = 0;
//float xX = 0.05, yY = -0.05;
float xX = 0, yY = 0;
//float OxA = 0.4, OyA = -0.45, OxB = -0.45, OyB = -0.45, OxC = 0.45, OyC = -0.4, OxD = 0.4, OyD = -0.4;
//float CXA = 0.4, CYA = -0.4, CXB = 0.6, CYB = -0.4, CXC = 0.6, CYC = -0.6, CXD = 0.4, CYD = -0.6;
float CXA = 0.4, CYA = -0.45, CXB = -0.45, CYB = -0.45, CXC = 0.45, CYC = -0.4, CXD = 0.4, CYD = -0.4;
float C1xA = 0.05, C1yA = -0.25, C1xB = 0.1, C1yB = -0.25, C1xC = 0.1, C1yC = -0.2, C1xD = 0.05, C1yD = -0.2;
float C2xA = 0.15, C2yA = -0.25, C2xB = 0.2, C2yB = -0.25, C2xC = 0.2, C2yC = -0.2, C2xD = 0.15, C2yD = -0.2;
float C3xA = 0.25, C3yA = -0.25, C3xB = 0.3, C3yB = -0.25, C3xC = 0.3, C3yC = -0.2, C3xD = 0.25, C3yD = -0.2;
``````

If it is like the original Sokoban, you don’t need float to store their positions. Int is good enough and only two coordinates per box: one x and one y.

[QUOTE=Hermannicus;1282683]Hi,

is it part of the assignment that you have to use OpenGL? Elsewise you would probably do yourself a hugh favor by using a 2D-widget library like Qt, GTK+ or SFML. OpenGL seems very overkill for this.

``````int t = 0;
//float xX = 0.05, yY = -0.05;
float xX = 0, yY = 0;
//float OxA = 0.4, OyA = -0.45, OxB = -0.45, OyB = -0.45, OxC = 0.45, OyC = -0.4, OxD = 0.4, OyD = -0.4;
//float CXA = 0.4, CYA = -0.4, CXB = 0.6, CYB = -0.4, CXC = 0.6, CYC = -0.6, CXD = 0.4, CYD = -0.6;
float CXA = 0.4, CYA = -0.45, CXB = -0.45, CYB = -0.45, CXC = 0.45, CYC = -0.4, CXD = 0.4, CYD = -0.4;
float C1xA = 0.05, C1yA = -0.25, C1xB = 0.1, C1yB = -0.25, C1xC = 0.1, C1yC = -0.2, C1xD = 0.05, C1yD = -0.2;
float C2xA = 0.15, C2yA = -0.25, C2xB = 0.2, C2yB = -0.25, C2xC = 0.2, C2yC = -0.2, C2xD = 0.15, C2yD = -0.2;
float C3xA = 0.25, C3yA = -0.25, C3xB = 0.3, C3yB = -0.25, C3xC = 0.3, C3yC = -0.2, C3xD = 0.25, C3yD = -0.2;
``````

If it is like the original Sokoban, you don’t need float to store their positions. Int is good enough and only two coordinates per box: one x and one y.[/QUOTE]

Yes, unfortunately I have to use openGL. What do you mean by using only 2 coordinates per box? do you mean like… for box one I will only have one X and one Y that will define the box?

Best regards!

Exactly if it is like the original Sokoban the coordinates of a box can only have integer values as coordinates and since all boxes have the same size and don’t rotate, you don’t need to store the coordinates of each corner. Two coordinates should be enough.

Hey!

Thanks for you answer! Meanwhile I finished the source code for the game. It works perfectly. Now I have to add textures and I want to modify some things.

But I ran into another problem and I do not really know how to fix it. I want to add a timer in the upper left corner of the window. I found this function “void glutTimerFunc( unsigned int msecs, void (*func)(int value), value);” but it seems I cannot make it working.

Any ideas on how can I do this?

Best regards,
Mihai Ilie

https://www.opengl.org/resources/libraries/glut/spec3/node64.html

i think you have to “register” that callback to a function you have to create/provide:

``````
void mytimer(int value)
{
}

...

// you can register multiple timers, that value is just to distinguish all your timers ...
int ID = 12345;

// timer in milliseconds
unsigned int frequency = 100;

// before entering the main loop, register your function:
glutTimerFunc(frequency, mytimer, ID);

glutMainLoop();

``````

another way to get the current time is to use the c++ feature:
http://www.cplusplus.com/reference/chrono/high_resolution_clock/now/

[QUOTE=john_connor;1282712]

i think you have to “register” that callback to a function you have to create/provide:

``````
void mytimer(int value)
{
}

...

// you can register multiple timers, that value is just to distinguish all your timers ...
int ID = 12345;

// timer in milliseconds
unsigned int frequency = 100;

// before entering the main loop, register your function:
glutTimerFunc(frequency, mytimer, ID);

glutMainLoop();

``````

another way to get the current time is to use the c++ feature:
[url[/QUOTE]

Thank you! Now I am dealing with a new problem! I try to add a texture for box nr 1 ( I use a box texture from mario). Not just it doesn’t work as supposed. It also inverts the box, puts it in an angle and the color looks weird (like a tv glitch)

Here is what I mean :

[ATTACH=CONFIG]1387[/ATTACH]

Here are the parts of codes that I am using for textures:

``````

#pragma warning (disable : 4996)
#define  tex_width 30
#define tex_height 30

static GLubyte texImage[tex_width][tex_height][3];
static GLuint texName[1];

{
FILE *file;
GLubyte data;
int i, j, k;
file = fopen("box1.raw", "rb");
for (i = 0; i<tex_width; i++)
{
for (j = 0; j<tex_height; j++)
{
for (k = 0; k<3; k++)
{
texImage[i][j][k] = (GLubyte)data;
}
}
}
fclose(file);
}
//etexturi

void init(void)
{
glClearColor(0.2, 0.6, 0.7, 0.0);
glGenTextures(1, texName);
glBindTexture(GL_TEXTURE_2D, texName[0]);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, tex_width, tex_height, 0, GL_RGB, GL_UNSIGNED_BYTE, texImage);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
}

// BOX 1
//glColor3f(0.0, 0.5, 0.0);
glEnable(GL_TEXTURE_2D);
glBegin(GL_POLYGON);
glTexCoord2f(1, 0);
glVertex2f(C1xA, C1yA);
glTexCoord2f(1, 1);
glVertex2f(C1xB, C1yB);
glTexCoord2f(0, 1);
glVertex2f(C1xC, C1yC);
glTexCoord2f(0, 0);
glVertex2f(C1xD, C1yD);
glEnd();
glDisable(GL_TEXTURE_2D);

//END BOX 1

``````
``````void readt(void)
{
FILE *file;
GLubyte data;
int i, j, k;
file = fopen("box1.raw", "rb");
for (i = 0; i<tex_width; i++)
{
for (j = 0; j<tex_height; j++)
{
for (k = 0; k<3; k++)
{
texImage[i][j][k] = (GLubyte)data;
}
}
}
fclose(file);
}
``````

If you’re opening a file with fopen, you’re directly reading from it without parsing it by any means. Most file formats have some metadata at the start or are compressed, which you are interpreting as rgb-values if you do it like this. You should use some library, which can parse image files properly.

[QUOTE=Hermannicus;1282718]

``````void readt(void)
{
FILE *file;
GLubyte data;
int i, j, k;
file = fopen("box1.raw", "rb");
for (i = 0; i<tex_width; i++)
{
for (j = 0; j<tex_height; j++)
{
for (k = 0; k<3; k++)
{
texImage[i][j][k] = (GLubyte)data;
}
}
}
fclose(file);
}
``````

If you’re opening a file with fopen, you’re directly reading from it without parsing it by any means. Most file formats have some metadata at the start or are compressed, which you are interpreting as rgb-values if you do it like this. You should use some library, which can parse image files properly.[/QUOTE]

While your words make some kinds of sens to my beginner ears, could you please give me an example of such a library…or code…or how can I do this? Honestly I just want to get done with it so I can rest. It’s killing me already. (Please do not take this as an offense…I am the stupid one here that doesn’t understand.) So yeah…I would e grateful for and example or telling me what to do to fix it.

Best regards,
Mihai Ilie

you have to use a library to load pictures/ textures, since many file types (png, jpg etc) are partially compressed and are not so easy to load …
libraries are the solution for this kind of problem, not every coder has to reinvent the wheel ^^
https://www.opengl.org/wiki/Image_Libraries

choose a lib that can load the file type of your picture
http://www.libraw.org/docs/API-CXX-eng.html

[QUOTE=john_connor;1282720]you have to use a library to load pictures/ textures, since many file types (png, jpg etc) are partially compressed and are not so easy to load …
libraries are the solution for this kind of problem, not every coder has to reinvent the wheel ^^
https://www.opengl.org/wiki/Image_Libraries

choose a lib that can load the file type of your picture[/QUOTE]

Hmm…so I have to use a library even if I converted the picture to a .raw?

Best regards,
Mihai Ilie

http://www.libraw.org/docs/API-CXX-eng.html

Okay, so I am pretty much done with the code. Also a few textures. Now I only have to apply one more texture that is repeating. It’s a texture of a wall (23x25) and I have to apply it on a polygon that is the same width but is taller. how can I make the texture repeat until it fills up the polygon? I tried googling but couldn’t find anything.

Best regards,
Mihai Ilie

``````glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
``````

You’re clamping them. Replace this with:

``````glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
``````

I tried doing that but it doesn’t seem to work. Here are the parts of the code I use for what I am trying to do:

``````

#define  tex_width 256
#define tex_height 256

static GLubyte wallImage[tex_width][tex_height][3];

static GLuint texName[8]; (I have 8 textures up until now)

{
FILE *file;
GLubyte data;
int i, j, k;
file = fopen("wall.raw", "rb");
for (i = 0; i <tex_width; i++)
{
for (j = 0; j <tex_height; j++)
{
for (k = 0; k < 3; k++)
{
wallImage[i][j][k] = (GLubyte)data;
}
}
}
fclose(file);

}

AND IN VOID INIT:

void init(void)
{

glGenTextures(8, texName);

glBindTexture(GL_TEXTURE_2D, texName[6]);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, tex_width, tex_height, 0, GL_RGB, GL_UNSIGNED_BYTE, wallImage);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);

}

AND IN VOID DISPLAY

void display(void)

{

glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texName[6]);   //limita dreapta
glBegin(GL_POLYGON);
glColor3f(1.0, 0.0, 0.0);
glTexCoord2f(1, 0);
glVertex2f(0.45, 0.5);
glTexCoord2f(1, 1);
glVertex2f(0.5, 0.5);
glTexCoord2f(0, 0);
glVertex2f(0.5, -0.5);
glTexCoord2f(1, 0);
glVertex2f(0.45, -0.5);
glEnd();
glDisable(GL_TEXTURE_2D);

}

``````

This is the texture I want to use (It is a 256x256)

And this is how it looks when I apply it.

I also tried to change TexCoord2f(1, 1) (i.e) with TexCoord2f(4, 4) so it will repeat it 4 times but it doesn’t work either.

Please someone help me fix this. All I have to do left now is to put textures on the wall and make a sprite for the player I move.

Best regards,
Mihai Ilie

You are using the coord glTexCoord2f(1, 0); twice. One should probably be (0, 1).

Unfortunately that did not do it.

I am running out of ideas. I really hope you guys can help me.

Best regards,
Mihai Ilie

UPDATE 1: By repalcing again the first GL_REPEAT with CLAMP I noticed that it won-t repeat it horizontally (as it was also repeating it horizontally). The photo is still not how it should look like. I am pretty sure it’s the dimensions of the texture that are wrong but I do not know how to figure out which re the right dimensions. I am still waiting for help.