Jump to content
  • Advertisement

Absolut88

Member
  • Content Count

    5
  • Joined

  • Last visited

Community Reputation

106 Neutral

About Absolut88

  • Rank
    Newbie
  1. Thank you a ton for taking the time to explain all of that to me. I was at work and couldn't test anything, but now that I am home I am going to see if I can find where the error occurred. ..Neither cout or std::cout prints anything to the console for me? --Nevermind, I'm an idiot, was using an empty project.
  2. the loadTexture() was from a youtube tutorial, it is a function at the top of my program: [source lang="cpp"]GLuint loadTexture(const std::string &fileName) { SDL_Surface *image = IMG_Load(fileName.c_str()); SDL_DisplayFormatAlpha(image); unsigned object(0); glGenTextures(1, &object); glBindTexture(GL_TEXTURE_2D, object); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, image->w, image->h, 0, GL_RGBA, GL_UNSIGNED_BYTE, image->pixels); //Free surface SDL_FreeSurface(image); return object; }[/source] The image must have been to big, I just resized it to 180x180 and it worked.
  3. Thanks a ton man, that worked perfectly. I forgot all about enums and how well they work. I have almost everything working now including the checking for winner logic. I am having one problem though: After a person has been won (3 in a row, duh), i have a bool set up named isGameover that is then set to True. Now after that happens I wanted to load a texture that says "Player One/Two Wins" have a 2000ms Delay, and then exit. However, I am not even able to setup the textures like I did the other ones. I am not sure if there is a certain max size you can have for loading textures onto an unsigned int or not. xTexture, oTexture, and hTexture all load and work fine. They are 180x180, .png playerOneTexture and playerTwoTexture are 600x600, .png, and saved the exact same way as the other three. I am guessing that there is a max image size that can be loaded this way. [source lang="cpp"] // TEXTURES // X Texture unsigned int xTexture = 0; xTexture = loadTexture("X.png"); // O Texture unsigned int oTexture = 0; oTexture = loadTexture("O.png"); // Holder Texture unsigned int hTexture = 0; hTexture = loadTexture ("Holder.png"); // PlayerOne texture unsigned int playerOneTexture = 0; playerOneTexture = loadTexture ("playerOneWins.png"); // PlayerTwo texture unsigned int playerTwoTexture = 0; playerTwoTexture = loadTexture ("playerTwoWins.png");[/source]
  4. I also tried to do the 'turns' based on a counter and % 0 == this color, else another color. Couldn't figure that out either.
  5. So I am finally transitioning from console based programming into event-driven / 2d gfx programming. I have been looking through lazyfoos tutorials and they have helped a ton. I started to make a Tic-Tac-Toe game yesterday and it started off pretty good, I think. The problem I am running into right now is how to define if it is playerOne's turn or not. I am using a bool for playerOne, true means it is playerOnes turn, false means it isn't. For now there are not actually 2 players, but I am trying to make it so when it playerOne == true, the box turns blue when clicked, and when playerOne == false, turn red. Later on I will switch it to images, but I want the logic down. I suppose it will be easier if I post the code so here it is. Any help will be greatly appreciated: [source lang="cpp"]#include "SDL.h" #include "SDL_opengl.h" #include "SDL_image.h" #include <iostream> #include <string> const int HOLDERS = 9; // Number of holders for images void setupWindow() { // Initialize SDL SDL_Init(SDL_INIT_EVERYTHING); // Allocate memory for GL SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, 32); SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16); SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); // Caption on the window pane SDL_WM_SetCaption ("Tic-Tac-Toe", NULL); // Setup the window SDL_SetVideoMode(600, 600, 32, SDL_OPENGL); // Clears the screen to this color glClearColor(1,1,1,1); // What is displayed of the screen glViewport(0,0,600,600); // Smooth color transition glShadeModel(GL_SMOOTH); // Sets to 2D glMatrixMode(GL_PROJECTION); glLoadIdentity(); // Disable depth test since not 3D glDisable(GL_DEPTH_TEST); } struct Holder { float xPos; float yPos; float width; float height; bool isVacant; }; int main (int argc, char* args[]) { // Function for window setup setupWindow(); /*---------------------------------------------------------------------------------------------------*/ /*--------------------------- VARIABLE SETUP -----------------------------------------------------*/ /*---------------------------------------------------------------------------------------------------*/ // Handles game loop bool isRunning = true; bool playerOne = true; // Handles SDL events SDL_Event event; // Array of Holders type Holder holders[HOLDERS]; // Setup the holders for (int a = 0, x = 20, y = 20; a < HOLDERS; a++, x+= 190) { if ( x > 400) { x = 20; y += 190; } holders[a].xPos = x; holders[a].yPos = y; holders[a].width = 180; holders[a].height = 180; holders[a].isVacant = true; } /*---------------------------------------------------------------------------------------------------*/ /*--------------------------- MAIN LOOP -----------------------------------------------------*/ /*---------------------------------------------------------------------------------------------------*/ // Game loop while (isRunning) { /*---------------------------------------------------------------------------------------------------*/ /*--------------------------- 1. EVENTS --------------------------------------------------*/ /*---------------------------------------------------------------------------------------------------*/ while (SDL_PollEvent(&event)) { // If window is closed if (event.type == SDL_QUIT) { isRunning = false; } // If escape key is pressed if (event.type == SDL_KEYUP && event.key.keysym.sym == SDLK_ESCAPE) { isRunning = false; } // Mouse click if (event.type == SDL_MOUSEBUTTONDOWN) { if (event.button.button == SDL_BUTTON_LEFT) { // Mouse offsets int x = 0, y = 0; x = event.button.x; y = event.button.y; for (int a = 0; a < HOLDERS; a++) { if ((x > holders[a].xPos) && (x < holders[a].xPos + holders[a].width) && (y > holders[a].yPos) && (y < holders[a].yPos + holders[a].height) && holders[a].isVacant == true) { OutputDebugString("Spot no longer vacant\n"); holders[a].isVacant = false; } } } } } /*---------------------------------------------------------------------------------------------------*/ /*--------------------------- 2. LOGIC -----------------------------------------------------*/ /*---------------------------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------------------------*/ /*--------------------------- 3. RENDER -----------------------------------------------------*/ /*---------------------------------------------------------------------------------------------------*/ // Clears screen before rendering glClear(GL_COLOR_BUFFER_BIT); glPushMatrix(); // Start phase glOrtho(0,600,600,0,-1,1); // Set the matrix // THE HOLDERS glBegin(GL_QUADS); // Used to display vacant spaces black for (int n = 0; n < HOLDERS; n++) { if (holders[n].isVacant == true) { glColor4ub(0,0,0,255); glVertex2f(holders[n].xPos, holders[n].yPos); glVertex2f(holders[n].xPos + holders[n].width, holders[n].yPos); glVertex2f(holders[n].xPos + holders[n].width, holders[n].yPos + holders[n].height); glVertex2f(holders[n].xPos, holders[n].yPos + holders[n].height); } else if (holders[n].isVacant == false && playerOne == true) { glColor4ub(0,0,255,255); glVertex2f(holders[n].xPos, holders[n].yPos); glVertex2f(holders[n].xPos + holders[n].width, holders[n].yPos); glVertex2f(holders[n].xPos + holders[n].width, holders[n].yPos + holders[n].height); glVertex2f(holders[n].xPos, holders[n].yPos + holders[n].height); } else if (holders[n].isVacant == false && playerOne == false) { glColor4ub(255,0,0,255); glVertex2f(holders[n].xPos, holders[n].yPos); glVertex2f(holders[n].xPos + holders[n].width, holders[n].yPos); glVertex2f(holders[n].xPos + holders[n].width, holders[n].yPos + holders[n].height); glVertex2f(holders[n].xPos, holders[n].yPos + holders[n].height); } } glEnd(); glPopMatrix(); // End phase // Draws everything above it to the screen SDL_GL_SwapBuffers(); } SDL_Quit; return 0; }[/source]
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!