arrrgh

Members
  • Content count

    3
  • Joined

  • Last visited

Community Reputation

107 Neutral

About arrrgh

  • Rank
    Newbie
  1. Wrote First Game[SDL/C++] - Feedback

    IMO, I would replace [source lang="cpp"] buttons[0] = new Button(0, 0, 200, 200, tileClips[Empty]); buttons[1] = new Button(200, 0, 200, 200, tileClips[Empty]); buttons[2] = new Button(400, 0, 200, 200, tileClips[Empty]); buttons[3] = new Button(0, 200, 200, 200, tileClips[Empty]); buttons[4] = new Button(200, 200, 200, 200, tileClips[Empty]); buttons[5] = new Button(400, 200, 200, 200, tileClips[Empty]); buttons[6] = new Button(0, 400, 200, 200, tileClips[Empty]); buttons[7] = new Button(200, 400, 200, 200, tileClips[Empty]); buttons[8] = new Button(400, 400, 200, 200, tileClips[Empty]);[/source] with something along the lines of [source lang="cpp"] const int BOARD_W = 3; // in tiles const int BOARD_H = 3; const int BUTTON_W = 200; // in pixels const int BUTTON_H = 200; int i = 0; int j = 0; for(i = 0 ; i < BOARD_H ; i++) { for(j = 0 ; j < BOARD_W ; j++) { buttons[i*BOARD_H + j] = new Button(i*BUTTON_H, j*BUTTON_W, BUTTON_H, BUTTON_W); } }[/source] because this avoids some repetition and also allows you to change the board size easily, if you wanted to add an option for a 4x4 game, or if you want to change the tile size easily for changing screen resolution, using different graphics etc.
  2. OpenGL Miscoloured textures

    Oh, oops... I thought internalformat and format had to be the same. Works now, thanks!
  3. I am getting started with OpenGL and am making a simple test program which loads a texture and draws a textured quad. The original texture looks like this: But in the program it looks like this: I'm using SDL and here's the code to load the texture: int loadTextures() { SDL_Surface *texture; texture = SDL_LoadBMP("bricks.bmp"); if(texture == NULL) { printf("Failed to load texture because %s\n", SDL_GetError()); return 1; } glGenTextures(1, &texNum[0]); glBindTexture(GL_TEXTURE_2D, texNum[0]); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, texture->w, texture->h, 0, GL_RGB, GL_UNSIGNED_BYTE, texture->pixels); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); SDL_FreeSurface(texture); return 0; } And the code to render: void render() { GLfloat verts[4][3] = {{-1, 1, 0}, {1, 1, 0}, {1, -1, 0}, {-1, -1, 0}}; GLfloat texCoords[4][2] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}}; glBindTexture(GL_TEXTURE_2D, texNum[0]); glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glVertexPointer(3, GL_FLOAT, 0, verts); glTexCoordPointer(2, GL_FLOAT, 0, texCoords); glDrawArrays(GL_QUADS, 0, 4); glDisableClientState(GL_VERTEX_ARRAY); glLoadIdentity(); glTranslatef(0, 0, -2); SDL_GL_SwapBuffers(); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); } I've tried using GL_BGR_EXT but this seems to make the texture fail because the quad is rendered as white like it would if it was untextured, and doing SDL_DisplayFormat on the texture appears to make no difference. Does anyone know what's going wrong here? Any help would be appreciated.