title: loading bmp images OPENGL 3.x - only loading one pixel?
body: <p>So Im having a bit of trouble loading texture images. I am not exactly sure what I could be doing wrong. It seems to only be reading the last pixel and I am not sure why?
  Any help is appreciated.  Here is my code:</p>
  
  <pre><code>#include "Angel.h"
  #include &lt;glew.h&gt;
  #include &lt;glut.h&gt;
  
  #include &lt;typeinfo&gt;
  #include &lt;iostream&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;stdint.h&gt;
  using namespace std;
  
  
  
  vec4 gridLines[] = {
      vec4(-0.5, -0.5, 0.0, 1.0), //v1
      vec4(0.5, -0.5, 0.0, 1.0), //v2
      vec4(-0.5, 0.5, 0.0, 1.0), //v3
      vec4(0.5, 0.5, 0.0, 1.0),  //v4
  };
  
  GLuint vertexID[3];
  GLuint bufferID2;
  GLuint ProjectionLocation, ModelViewLocation;
  mat4 instance;
  
  
  //----------------------------------------------------------------------------
  //----------------------------------------------------------------------------
  
  float
  roundTo(float value, int digits)//Ensures rounding is done correct
  {
      //check to see if the value is very close to zero
      if ((int)(value*10.0) == 0){
          return 0.0;
      }
      double factor = pow(10.0, digits - ceil(log10(fabs(value))));
      return round(value * factor) / factor;
  }
  
  
  
  
  void
  init(void) //Initialize Buffers for all objects
  {
      //1. Load shaders and use the resulting shader program
      GLuint program = InitShader("vshader81.glsl", "fshader81.glsl");
      glUseProgram(program);
      GLuint vPosition = glGetAttribLocation(program, "vPosition");
      GLuint vColor = glGetAttribLocation(program, "vColor");
  
  
  
      glGenVertexArrays(1, &amp;vertexID[1]);
  
      vec4 colors2[] = {
          vec4(1.0, 1.0, 1.0, 1.0),  //1
          vec4(1.0, 1.0, 1.0, 1.0),  //2
          vec4(1.0, 1.0, 1.0, 1.0),  //3
          vec4(1.0, 1.0, 1.0, 1.0),  //4
      };
  
      // Create and initialize a buffer object
      glBindVertexArray(vertexID[1]);
      glGenBuffers(1, &amp;bufferID2);
      glBindBuffer(GL_ARRAY_BUFFER, bufferID2);
      glBufferData(GL_ARRAY_BUFFER, sizeof(gridLines)+sizeof(colors2), NULL, GL_STATIC_DRAW);
      glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(gridLines), gridLines);
      glBufferSubData(GL_ARRAY_BUFFER, sizeof(gridLines), sizeof(colors2), colors2);
  
      glEnableVertexAttribArray(vPosition);
      glVertexAttribPointer(vPosition, 4, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(0));
  
  
      GLuint textureid;
      // Texture coordinates
      vec4 tex_coords[] = {
          vec4(-0.5, -0.5, 0.0, 1.0), //v1
          vec4(0.5, -0.5, 0.0, 1.0), //v2
          vec4(-0.5, 0.5, 0.0, 1.0), //v3
          vec4(0.5, 0.5, 0.0, 1.0),  //v4
      };
      glGenTextures(1, &amp;textureid);
      glBindTexture(GL_TEXTURE_2D, textureid);
  
  
  
      /***********************************************/
      const char * imagepath = "checkboard2.bmp";
      // Data read from the header of the BMP file
      unsigned char header[54]; // Each BMP file begins by a 54-bytes header
      unsigned int dataPos;     // Position in the file where the actual data begins
      unsigned int width, height;
      unsigned int imageSize;   // = width*height*3
      // Actual RGB data
      unsigned char * data;
  
      // Open the file
      FILE * file = fopen(imagepath, "rb");
      if (!file) { printf("Image could not be opened\n"); }
  
      if (fread(header, 1, 54, file) != 54){ // If not 54 bytes read : problem
          printf("Not a correct BMP file\n");
      }
  
      if (header[0] != 'B' || header[1] != 'M'){
          printf("Not a correct BMP file\n");
      }
  
      cout &lt;&lt; "great.." &lt;&lt; endl;
      // Read ints from the byte array
      dataPos = *(int*)&amp;(header[0x0A]);
      imageSize = *(int*)&amp;(header[0x22]);
      cout &lt;&lt; "Image Size: " &lt;&lt; imageSize &lt;&lt; endl;
      width = *(int*)&amp;(header[0x12]);
      cout &lt;&lt; "width: " &lt;&lt; width &lt;&lt; endl;
      height = *(int*)&amp;(header[0x16]);
  
      // Some BMP files are misformatted, guess missing information
      if (imageSize == 0)    imageSize = width*height * 3; // 3 : one byte for each Red, Green and Blue component
      if (dataPos == 0)      dataPos = 54; // The BMP header is done that way
  
      // Create a buffer
      data = new unsigned char[imageSize];
  
      // Read the actual data from the file into the buffer
      fread(data, 1, imageSize, file);
  
      //Everything is in memory now, the file can be closed
      fclose(file);
      //GLuint Texture = loadBMP_custom("brick_converted.bmp");
  
  
      glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_BGR, GL_UNSIGNED_BYTE, data);
  
  
  //  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_NEAREST);
      glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
      //glActiveTexture(GL_TEXTURE0);
  
  
  
      GLuint vTexCoord = glGetAttribLocation(program, "vTexCoord");
      glEnableVertexAttribArray(vTexCoord);
      glVertexAttribPointer(vTexCoord, 2, GL_FLOAT, GL_FALSE, 0,
          BUFFER_OFFSET(sizeof(gridLines)));
  
      glUniform1i(glGetUniformLocation(program, "texture"), 0);
  
      //4. Bind all Buffers
      glBindVertexArray(0);
  
  
  
  
      //5.Set Background Color
      glClearColor(0.5, 0.5, 0.5, 0.0); // background
  }
  
  //----------------------------------------------------------------------------
  // Draw on Screen
  //----------------------------------------------------------------------------
  
  void
  paintOnScreen()
  {
      glBindVertexArray(vertexID[1]);
      glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
  }
  
  void
  display(void) //Display to screen
  {
      //1.Clear the window
      glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
      glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
      glEnable(GL_CULL_FACE);
  
      //2.Translations/Rotations/Projections etc..
      glViewport(0, 0, 300, 300);
  
  
  
      //3.Draw Objects        
      paintOnScreen();
      glBindVertexArray(0);
  
  
      //3.Force OpenGL to render
      glFlush();
  
  }
  
  void
  reshape(int width, int height)
  {
      glViewport(0, 0, width, height);
  
      //aspect = GLfloat(width)/height;
  }
  
  
  
  void
  keyboard(unsigned char key, int x, int y)
  {
      switch (key) {
      case 033:   //ESC
          exit(EXIT_SUCCESS);
          break;
      }
  
  }
  
  
  //----------------------------------------------------------------------------
  
  
  int
  main(int argc, char **argv)
  {
  
      // Initialize glut library
      glutInit(&amp;argc, argv);
  
      // Create the window
      glutInitDisplayMode(GLUT_RGBA);
      glutInitWindowSize(300, 300);
      glutInitWindowPosition(300, 200);
      glutCreateWindow("Test");
  
      // Initialize glew library
      glewInit();
  
      // Your own initialization
      init();
  
      // Set callback functions
      glutDisplayFunc(display);
      glutReshapeFunc(reshape);
      glutKeyboardFunc(keyboard);
  
      // Start the main loop
      glutMainLoop();
  
      return 0;
  }
  </code></pre>
  
  <p>and my fragment shader:</p>
  
  <pre><code>#version 150 
  
  in vec2 texCoord;
  
  out vec4  fColor;
  uniform sampler2D texture;
  
  void main() 
  { 
      fColor = texture2D( texture, texCoord );
  } 
  </code></pre>
  
  <p>and my vertex shader:</p>
  
  <pre><code>#version 150 
  
  in  vec4 vPosition;
  in vec2 vTexCoord;
  
  out vec2 texCoord;
  
  
      void main() 
      {
  
          texCoord = vTexCoord;   
          gl_Position =  vPosition;
  
      } 
  </code></pre>