• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.

MylesEvans

Members
  • Content count

    51
  • Joined

  • Last visited

Community Reputation

151 Neutral

About MylesEvans

  • Rank
    Member
  1. I'm trying to blend the colors of two rectangles I've drawn in OpenGL without including the background color (clear color). How do I go about doing this? I have blending enabled/glBlendFunc(GL_ONE,GL_ONE); and all that but when I draw my two transparent rectangles they not only blend their colors together but they also blend the background color. I dont want this. I only want the two rectangles to blend.l
  2. I'm having a weird problem, whenever I set Uint32 colorkey = SDL_MapRGB(surface, 255, 255, 255); It turns every geometric object I have draw using Opengl black.   If I set Uint32 colorkey = SDL_MapRGB(surface, 255, 255, 254); and RGB aren't all 255 then its fine, but that a problem since I'm trying to remove a white background. So why would Uint32 colorkey = SDL_MapRGB(surface, 255, 255, 255); be making all of my previously drawn shapes black?
  3. I have an image that I load in SDL. My goal is to load the image in SDL, Color Key, and then send to Opengl to become texture.     I've read some tutorials and the following code is what I have come up with.     int loadImage() { SDL_Surface *surface; if (surface = IMG_Load("AvatarR.jpg")) { nofcolors = surface->format->BytesPerPixel; if(nofcolors == 4) { if (surface->format->Rmask == 0x000000ff) texture_format = GL_RGBA; else texture_format = GL_BGRA; } else if (nofcolors == 3) //no alpha channel { // no alpha channel = no transparency = use color key Uint32 colorkey = SDL_MapRGB(surface, 255, 255, 255); SDL_SetColorKey(surface, SDL_SRCCOLORKEY, colorkey); // now convert image to 32 bits SDL_Surface *temp = SDL_DisplayFormatAlpha(surface); // release previous surface SDL_FreeSurface(surface); // use the new converted one surface = temp; // reassign nofcolors because image format changed nofcolors = surface->format->BytesPerPixel; if(surface->format->Rmask == 0x000000ff) texture_format = GL_RGB; else texture_format = GL_BGR; } glGenTextures(1, &texture); glBindTexture(GL_TEXTURE_2D, texture); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glPixelStorei(GL_UNPACK_ALIGNMENT,4); glTexImage2D(GL_TEXTURE_2D, 0, nofcolors, surface->w, surface->h, 0, texture_format, GL_UNSIGNED_BYTE, surface->pixels); } else { return -1; } if (surface) SDL_FreeSurface(surface); return 1;   It doesn't work. The background color is white and I want it to be gone.       If anyone has any succesful methods in C++ they would like to share I'd greatly appreciate it.
  4. OpenGL

    The image shows on screen for you? How can that be?
  5. I made this thread in For Beginners, but noone there was able to help.     I was having trouble loading the image, but have since fixed that. Now I cant seem to get the image to actually show on the screen. Instead its just the blue rectangle I have drawn with no texture on it.   #include "SDL.h" #include "SDL_image.h" #include "SDL_opengl.h" #include <math.h> #include <stdio.h> int loadImage(); void drawImage(); extern SDL_Event event; GLuint texture = NULL; GLenum texture_format=NULL; GLint nofcolors; bool initGL() { //Initialize Projection Matrix glMatrixMode( GL_PROJECTION ); glLoadIdentity(); //Initialize Modelview Matrix glOrtho(0, 1200, 700, 0, -1, 1); glMatrixMode( GL_MODELVIEW ); glLoadIdentity(); //Initialize clear color glClearColor(1.0,.4,0.0,0.0); glEnable( GL_TEXTURE_2D); //Check for error GLenum error = glGetError(); if( error != GL_NO_ERROR ) { printf( "Error initializing OpenGL! %s\n", gluErrorString( error ) ); return false; } return true; } bool init() { //Initialize SDL if( SDL_Init( SDL_INIT_EVERYTHING ) < 0 ) { return false; } SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER,1); //Create Window if( SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_OPENGL ) == NULL ) { return false; } //Enable unicode SDL_EnableUNICODE( SDL_TRUE ); //Initialize OpenGL if( initGL() == false ) { return false; } //Set caption SDL_WM_SetCaption( "Project Birth Game Window. Guns&Player.", NULL ); return true; } int main( int argc, char *argv[] ) { //Quit flag bool quit = false; //Initialize if( init() == false ) { return 1; } //The frame rate regulator Timer fps; fps.start(); loadImage(); int x = 0, y = 0; //Wait for user exit while( quit == false ) { //Start the frame timer //While there are events to handle while( SDL_PollEvent( &event ) ) { if( event.type == SDL_QUIT ) { quit = true; } else if( event.type == SDL_KEYDOWN ) { //Handle keypress with current mouse position SDL_GetMouseState( &x, &y ); } } drawImage(); update(); SDL_GL_SwapBuffers(); //Cap the frame rate if( fps.get_ticks() < 1000 / FRAMES_PER_SECOND ) { SDL_Delay( ( 1000 / FRAMES_PER_SECOND ) - fps.get_ticks() ); } } //Clean up clean_up(); return 0; } int loadImage() { SDL_Surface* surface; if((surface = IMG_Load("Avatar Basic Character Model.jpg"))) { //get number of channels in the SDL surface nofcolors = surface -> format -> BytesPerPixel; //contains an alpha channel if(nofcolors == 4) { if ( surface -> format -> Rmask == 0x000000ff) texture_format = GL_RGBA; else texture_format = GL_BGRA; } else if ( nofcolors == 3) //no alpha channel { if(surface ->format->Rmask==0x000000ff) texture_format=GL_RGB; else texture_format=GL_BGR; } //Have Opengl generate a texture object handle for us glGenTextures(1, &texture); //Bind the texture object glBindTexture( GL_TEXTURE_2D, texture); //Set the texture's stretching properties glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glPixelStorei(GL_UNPACK_ALIGNMENT,1); glTexImage2D( GL_TEXTURE_2D, 0, nofcolors, surface -> w, surface ->h, 0, texture_format, GL_UNSIGNED_BYTE, surface -> pixels ); } else //could not load image return -1; if (surface) { SDL_FreeSurface(surface); } return 1; } void drawImage() { //Clear the screen before drawing glClear( GL_COLOR_BUFFER_BIT); //Bind the texture to which subsequent calls refer to glBindTexture( GL_TEXTURE_2D, texture); glPushMatrix(); glTranslatef(300,300,0.0f); glBegin(GL_QUADS); //Set color glColor4f(0.0,0.0,1.0,0.0); glTexCoord2i(1,1); glVertex2f(150.0,0);//bottom right glTexCoord2i(0,1); glVertex2f(150.0,-50);//top right glTexCoord2i(0,0); glVertex2f(0.0,-50);//top left glTexCoord2i(1,0); glVertex2f(0.0,0);//bottom left glEnd(); glPopMatrix(); }   At first I was having issues with loading the image, but thats no longer an issue. Any idea on why the image wont show on the quad? Perhaps an issue with binding?  
  6. I was having trouble loading the image, but have since fixed that. Now I cant seem to get the image to actually show on the screen. Instead its just the blue rectangle I have drawn with no texture on it.     #include "SDL.h" #include "SDL_image.h" #include "SDL_opengl.h" #include <math.h> #include <stdio.h> int loadImage(); void drawImage(); extern SDL_Event event; GLuint texture = NULL; GLenum texture_format=NULL; GLint nofcolors; bool initGL() { //Initialize Projection Matrix glMatrixMode( GL_PROJECTION ); glLoadIdentity(); //Initialize Modelview Matrix glOrtho(0, 1200, 700, 0, -1, 1); glMatrixMode( GL_MODELVIEW ); glLoadIdentity(); //Initialize clear color glClearColor(1.0,.4,0.0,0.0); glEnable( GL_TEXTURE_2D); //Check for error GLenum error = glGetError(); if( error != GL_NO_ERROR ) { printf( "Error initializing OpenGL! %s\n", gluErrorString( error ) ); return false; } return true; } bool init() { //Initialize SDL if( SDL_Init( SDL_INIT_EVERYTHING ) < 0 ) { return false; } SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER,1); //Create Window if( SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_OPENGL ) == NULL ) { return false; } //Enable unicode SDL_EnableUNICODE( SDL_TRUE ); //Initialize OpenGL if( initGL() == false ) { return false; } //Set caption SDL_WM_SetCaption( "Project Birth Game Window. Guns&Player.", NULL ); return true; } int main( int argc, char *argv[] ) { //Quit flag bool quit = false; //Initialize if( init() == false ) { return 1; } //The frame rate regulator Timer fps; fps.start(); loadImage(); int x = 0, y = 0; //Wait for user exit while( quit == false ) { //Start the frame timer //While there are events to handle while( SDL_PollEvent( &event ) ) { if( event.type == SDL_QUIT ) { quit = true; } else if( event.type == SDL_KEYDOWN ) { //Handle keypress with current mouse position SDL_GetMouseState( &x, &y ); } } drawImage(); update(); SDL_GL_SwapBuffers(); //Cap the frame rate if( fps.get_ticks() < 1000 / FRAMES_PER_SECOND ) { SDL_Delay( ( 1000 / FRAMES_PER_SECOND ) - fps.get_ticks() ); } } //Clean up clean_up(); return 0; } int loadImage() { SDL_Surface* surface; if((surface = IMG_Load("Avatar Basic Character Model.jpg"))) { //get number of channels in the SDL surface nofcolors = surface -> format -> BytesPerPixel; //contains an alpha channel if(nofcolors == 4) { if ( surface -> format -> Rmask == 0x000000ff) texture_format = GL_RGBA; else texture_format = GL_BGRA; } else if ( nofcolors == 3) //no alpha channel { if(surface ->format->Rmask==0x000000ff) texture_format=GL_RGB; else texture_format=GL_BGR; } //Have Opengl generate a texture object handle for us glGenTextures(1, &texture); //Bind the texture object glBindTexture( GL_TEXTURE_2D, texture); //Set the texture's stretching properties glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glPixelStorei(GL_UNPACK_ALIGNMENT,1); glTexImage2D( GL_TEXTURE_2D, 0, nofcolors, surface -> w, surface ->h, 0, texture_format, GL_UNSIGNED_BYTE, surface -> pixels ); } else //could not load image return -1; if (surface) { SDL_FreeSurface(surface); } return 1; } void drawImage() { //Clear the screen before drawing glClear( GL_COLOR_BUFFER_BIT); //Bind the texture to which subsequent calls refer to glBindTexture( GL_TEXTURE_2D, texture); glPushMatrix(); glTranslatef(300,300,0.0f); glBegin(GL_QUADS); //Set color glColor4f(0.0,0.0,1.0,0.0); glTexCoord2i(1,1); glVertex2f(150.0,0);//bottom right glTexCoord2i(0,1); glVertex2f(150.0,-50);//top right glTexCoord2i(0,0); glVertex2f(0.0,-50);//top left glTexCoord2i(1,0); glVertex2f(0.0,0);//bottom left glEnd(); glPopMatrix(); }  
  7. I have code trying load/display an image and keep getting this Unhandled Exception Error. I think its because the image is not a multiple of 4 or something like that (no idea) here is my code:     #include "SDL.h" #include "SDL_image.h" #include "SDL_opengl.h" #include <math.h> #include <stdio.h> int loadImage(); void drawImage(); extern SDL_Event event; GLuint texture = NULL; GLenum texture_format=NULL; GLint nofcolors; int loadImage() { SDL_Surface* surface; if((surface = IMG_Load("AvatarBasicCharacterModel.jpg"))){ //get number of channels in the SDL surface nofcolors = surface -> format -> BytesPerPixel; //contains an alpha channel if(nofcolors == 4) { if ( surface -> format -> Rmask == 0x000000ff) texture_format = GL_RGBA; else texture_format = GL_BGRA; } else if ( nofcolors == 3) //no alpha channel { if(surface ->format->Rmask==0x000000ff) texture_format=GL_RGB; else texture_format=GL_BGR; } //Have Opengl generate a texture object handle for us glGenTextures(1, &texture); //Bind the texture object glBindTexture( GL_TEXTURE_2D, texture); //Set the texture's stretching properties glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexImage2D( GL_TEXTURE_2D, 0, nofcolors, surface -> w, surface ->h, 0, texture_format, GL_UNSIGNED_BYTE, surface -> pixels ); } else //could not load image SDL_Quit(); return 1; if (surface){ SDL_FreeSurface(surface); } } void drawImage() { //Clear the screen before drawing glClear( GL_COLOR_BUFFER_BIT); //Bind the texture to which subsequent calls refer to glBindTexture( GL_TEXTURE_2D, texture); glPushMatrix(); glTranslatef(60,700,0.0f); glBegin(GL_QUADS); //Set color glColor4f(0.0,0.0,1.0,0.0); glTexCoord2i(1,1); glVertex2f(150.0,0);//bottom right glTexCoord2i(0,1); glVertex2f(150.0,-50);//top right glTexCoord2i(0,0); glVertex2f(0.0,-50);//top left glTexCoord2i(1,0); glVertex2f(0.0,0);//bottom left glEnd(); glPopMatrix(); } I want to A) Understand why the image needs to be a certain width/hieght and B) How to make it work.     The alpha channels and stuff. Not following.
  8. Fixed it. Needed to Swap Buffers.
  9. Trienco that looks like it might be why it doesn't work.   GDsnakes you should make all function inputs const unless you have to modify it. I changed it to this. Still the exact same same issues.   QuadDrawing::QuadDrawing( float Xoff, float Yoff) { QuadoffX = Xoff; QuadoffY = Yoff; }
  10. What could possibly be the problem? I call a function to draw a square and it works fine....but if that EXACT same function is part of a class it doesn't work....Window is up, but screen clear.
  11. Ugh, sorry guys. I copied that from the wrong file I have. That's not the setup (after reading your suggestions I realized my mistake. Sorry for wasting time)....   #include "SDL.h" #include <SDL_opengl.h> //Screen attributes const int SCREEN_WIDTH = 1500; const int SCREEN_HEIGHT = 1500; const int SCREEN_BPP = 32; bool initGL() { //Initialize Projection Matrix glMatrixMode( GL_PROJECTION ); glLoadIdentity(); //Initialize Modelview Matrix glOrtho(0, 1500, 1500, 0, -1, 1); glMatrixMode( GL_MODELVIEW ); glLoadIdentity(); //Initialize clear color glClearColor(1.0,.4,0.0,0.0); //Check for error GLenum error = glGetError(); if( error != GL_NO_ERROR ) { printf( "Error initializing OpenGL! %s\n", gluErrorString( error ) ); return false; } return true; } bool init() { //Initialize SDL if( SDL_Init( SDL_INIT_EVERYTHING ) < 0 ) { return false; } //Create Window if( SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_OPENGL ) == NULL ) { return false; } //Enable unicode SDL_EnableUNICODE( SDL_TRUE ); //Initialize OpenGL if( initGL() == false ) { return false; } //Set caption SDL_WM_SetCaption( "Project Birth Game Window. Guns&Player.", NULL ); return true; }     So this is what my set-up actually looks like. I just want to clarify that I was drawing Quads and whatnot without a problem when I was just calling a "draw" function, but as soon as I made it into a class I've been getting the problems described above in the OP.
  12. The set up:   bool init() { //Initialize SDL if( SDL_Init( SDL_INIT_EVERYTHING ) < 0 ) { return false; } //Create Window if( SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_OPENGL ) == NULL ) { return false; } //Initialize OpenGL if( initGL() == false ) { return false; } //Set caption SDL_WM_SetCaption( "OpenGL Test", NULL ); return true; } bool initGL() { //Initialize Projection Matrix glMatrixMode( GL_PROJECTION ); glLoadIdentity(); //Initialize Modelview Matrix glMatrixMode( GL_MODELVIEW ); glLoadIdentity(); //Initialize clear color glClearColor( 0.f, 0.f, 0.f, 1.f ); //Check for error GLenum error = glGetError(); if( error != GL_NO_ERROR ) { printf( "Error initializing OpenGL! %s\n", gluErrorString( error ) ); return false; } return true; }  
  13. class QuadDrawing { private: float QuadoffX; float QuadoffY; public: QuadDrawing(float, float); void Draw(); }; QuadDrawing::QuadDrawing( float Xoff, float Yoff) { Xoff = QuadoffX; Yoff = QuadoffY; } void QuadDrawing::Draw() { glPushMatrix(); glTranslatef(QuadOffX,QuadoffY,0.0f); glBegin(GL_QUADS); //Set color glColor4f(1.0,0.0,0.0,0.0); glVertex2f(90.0,50); glVertex2f(90.0,-80); glVertex2f(0.0,-80); glVertex2f(0.0,50); glEnd(); glPopMatrix(); } int main( int argc, char *argv[] ) { //Quit flag bool quit = false; //Initialize if( init() == false ) { return 1; } //The frame rate regulator Timer fps; Drawing Square1(300.0, 300.0); int x = 0, y = 0; //Wait for user exit while( quit == false ) { //Start the frame timer fps.start(); //While there are events to handle while( SDL_PollEvent( &event ) ) { if( event.type == SDL_QUIT ) { quit = true; } else if( event.type == SDL_KEYDOWN ) { //Handle keypress with current mouse position SDL_GetMouseState( &x, &y ); handleKeys (event.key.keysym.unicode. x. y); } } MenuState(); Square1.Draw(); update(); //Cap the frame rate if( fps.get_ticks() < 1000 / FRAMES_PER_SECOND ) { SDL_Delay( ( 1000 / FRAMES_PER_SECOND ) - fps.get_ticks() ); } } //Clean up clean_up(); return 0; }   The problem is I want to draw a square to test the class I made which should just take two floating point numbers and draw a square at those points, but the square is never drawn...instead the window comes up but stays completely blank. The window was even clear (no clear color) so I thought that was the problem and added glClear( GL_COLOR_BUFFER_BIT ); to the Draw function in the class making it...   void QuadDrawing::Draw() { glClear( GL_COLOR_BUFFER_BIT); glPushMatrix(); glTranslatef(QuadOffX,QuadoffY,0.0f); glBegin(GL_QUADS); //Set color glColor4f(1.0,0.0,0.0,0.0); glVertex2f(90.0,50); glVertex2f(90.0,-80); glVertex2f(0.0,-80); glVertex2f(0.0,50); glEnd(); glPopMatrix(); }   Still didn't work and the window come up clear/blank (not even the clear color).     But the thing is if I just make it a function and not a class and pass the floating X/Y to draw the square there it works fine. So its a problem with the class.
  14. Just realized its my birthday.