Thanks Photon.
This is my test code. Run in windows using visual studio 2008. This problem also happens in ios and android devices.
#include “stdafx.h”
#include “windows.h” // include windows header file
#include <stdio.h>
#include <stdlib.h>
#define GL_GLEXT_PROTOTYPES
#include <gl/glew.h>
#include <GL/gl.h>
#include <GL/glu.h>
//#include <GL/glx.h> // comment this line for compiling
#include <GL/glut.h>
#include <gl/glaux.h>
#pragma comment( lib, “opengl32.lib” ) // Link OpenGL32.lib
#pragma comment( lib, “glu32.lib” ) // Link GLu32.lib
#pragma comment( lib, “glaux.lib” ) // Link GLaux.lib
void checkGLError( const char hdr[] )
{
int err = glGetError();
if( err )
{
fprintf(stderr, "ERROR %s: %s
", hdr, gluErrorString(err));
exit(1);
}
}
void reshape(GLsizei w, GLsizei h)
{
glViewport(0, 0, w, h);
glutPostRedisplay();
}
void keyboard( unsigned char key, int x, int y )
{
// Key Bindings
switch( key )
{
case 27 : exit(0); break;
}
}
int LoadGLTextures(); // Load Bitmaps And Convert To Textures
void SceneShow(GLfloat x, GLfloat y); // Draw Texture
void SceneShowFull(GLfloat x, GLfloat y); // Draw full Texture buffer in video card
void SceneSetView();
void display()
{
glClearColor( 1, 0, 0, 1 );
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
SceneShow(1, 1.496);
SceneShow(71, 1.497);
SceneShow(141, 1.498);
SceneShow(211, 1.499); // a white line appears
SceneShow(1, 71.500); // a white line appears
SceneShow(71, 71.501); // a white line appears
SceneShow(141, 71.502);
SceneShow(211, 71.503);
SceneShowFull(1, 141.496);
SceneShowFull(71, 141.497);
SceneShowFull(141, 141.498);
SceneShowFull(211, 141.499); // the image’s top line appears in bottom
SceneShowFull(1, 211.500); // the image’s top line appears in bottom
SceneShowFull(71, 211.501); // the image’s top line appears in bottom
SceneShowFull(141, 211.502);
SceneShowFull(211, 211.503);
glutSwapBuffers();
checkGLError( “display() end” );
}
void main( int argc, char *argv[] )
{
glutInit( &argc, argv );
glutInitDisplayMode( GLUT_DOUBLE | GLUT_DEPTH | GLUT_RGB );
glutCreateWindow( “window title” );
checkGLError( “Create window” );
SceneSetView();
LoadGLTextures();
glutReshapeFunc ( reshape );
glutDisplayFunc ( display );
glutKeyboardFunc( keyboard );
glutPostRedisplay();
glutMainLoop();
}
AUX_RGBImageRec *LoadBMP(char *Filename) // Loads A Bitmap Image
{
FILE *File=NULL;
if (!Filename) // Make Sure A Filename Was Given
{
return NULL; // If Not Return NULL
}
File=fopen(Filename,"r");
if (File) // Does The File Exist?
{
fclose(File); // Close The Handle
//return auxDIBImageLoad((LPCWSTR)(Filename)); // Load The Bitmap And Return A Pointer
return auxDIBImageLoadA(Filename);
}
return NULL; // If Load Failed Return NULL
}
#define MAX_TEXTURE 1
char *ForTextureBMP[MAX_TEXTURE]=
{
“lawnpic.bmp”,
};
GLuint texture[1];
int NextPowerOf2( size_t in )
{
–in; // in -= 1;
in |= in >> 16;
in |= in >> 8;
in |= in >> 4;
in |= in >> 2;
in |= in >> 1;
return (++in); // in + 1;
}
int LoadGLTextures() // Load Bitmaps And Convert To Textures
{
int Status=FALSE; // Status Indicator
int TotalBmp = MAX_TEXTURE;
int WPowerof2;
int HPowerof2;
AUX_RGBImageRec *TextureImage[1]; // Create Storage Space For The Texture
memset(TextureImage,0,sizeof(void *)*1); // Set The Pointer To NULL
// Load The Bitmap, Check For Errors, If Bitmap's Not Found Quit
for (int i = 0; i < TotalBmp; i++)
{
if (TextureImage[0]=LoadBMP(ForTextureBMP[i]))
{
Status=TRUE; // Set The Status To TRUE
glGenTextures(1, &texture[i]); // Create The Texture
// Typical Texture Generation Using Data From The Bitmap
glBindTexture(GL_TEXTURE_2D, texture[i]);
WPowerof2 = NextPowerOf2(TextureImage[0]->sizeX);
HPowerof2 = NextPowerOf2(TextureImage[0]->sizeY);
char* tmppixel = new char [WPowerof2 * WPowerof2 * 3];
memset(tmppixel, 0xFF, WPowerof2 * WPowerof2 * 3); // fill texture buffer with white color
// Generate The Texture
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, WPowerof2, HPowerof2, 0, GL_RGB, GL_UNSIGNED_BYTE, tmppixel);
delete [] tmppixel;
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, TextureImage[0]->sizeX, TextureImage[0]->sizeY, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); // Nearest Filtering
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); // Nearest Filtering
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); !!!!!!!! discomment still won't solve the problem
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); !!!!!!!! discomment still won't solve the problem
}
if (TextureImage[0]) // If Texture Exists
{
if (TextureImage[0]->data) // If Texture Image Exists
{
free(TextureImage[0]->data); // Free The Texture Image Memory
}
free(TextureImage[0]); // Free The Image Structure
}
}
return Status; // Return The Status
}
void SceneSetView()
{
glutInitWindowPosition(400,400);
glutInitWindowSize(320, 320);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, 300, 300, 0, 0, 1); // !!! IMPORTANT : Maybe this line cause the problem
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glEnable(GL_TEXTURE_2D);
}
void SceneShow(GLfloat argx, GLfloat argy)
{
float x = argx;
float y = argy;
float m_nImageWf = (float)(60);
float m_nImageHf = (float)(60);
GLfloat coordinates[] = {
0, 0,
60.0/64.0, 0,
0, 60.0/64.0,
60.0/64.0, 60.0/64.0
};
GLfloat vertices[] = {
x, y,
m_nImageWf + x, y,
x, m_nImageHf + y,
m_nImageWf + x, m_nImageHf + y };
glBindTexture(GL_TEXTURE_2D, texture[0]);
glTexCoordPointer(2, GL_FLOAT, 0, coordinates);
glVertexPointer(2, GL_FLOAT, 0, vertices);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
}
void SceneShowFull(GLfloat argx, GLfloat argy)
{
float x = argx;
float y = argy;
float m_nImageWf = (float)(60);
float m_nImageHf = (float)(60);
GLfloat coordinates[] = {
0, 0,
1, 0,
0, 1,
1, 1
};
GLfloat vertices[] = {
x, y,
m_nImageWf + x, y,
x, m_nImageHf + y,
m_nImageWf + x, m_nImageHf + y };
glBindTexture(GL_TEXTURE_2D, texture[0]);
glTexCoordPointer(2, GL_FLOAT, 0, coordinates);
glVertexPointer(2, GL_FLOAT, 0, vertices);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
}
This is my test image.[ATTACH=CONFIG]214[/ATTACH]. I’m using a bitmap which not allowed to be uploaded in the code above, so convert to a bmp file by yourself.
Thanks again.