Jump to content

  • Log In with Google      Sign In   
  • Create Account

leagal4ever

Member Since 04 Jun 2012
Offline Last Active Dec 25 2014 03:43 PM

Topics I've Started

drawing 2D very basic shapes

14 January 2013 - 01:08 PM

Hello, im having problem with drawing 2D very basic shapes.

Questions:
1. How draw Quad just with lines, corner should be sharp.
2. Quad with border and filled color, each with different color.
3. Triangle is again not sharp also bottom line seems to be thiner.
4. Position in code is set to 100, 100 (quad) in window position does not match(y only?) its more like on half so on 300px.
Edit: just saw problem there are many width and height to set, forgot one


I have added code since its very small and have many mistakes inside.

Thanks for help.

qqqqqqqqqqqqqqqf.png

#include "sdl.h"
#include "sdl_opengl.h"
#include <iostream>
#include <SDL_image.h>
#include <string>
#include <vector>

using std::vector;
using std::cout;
using std::endl;

vector < vector <int> >  points_vec;

int WIDTH = 800;
int HEIGHT = 600;

int main(int argc, char* argv[])
{
    //initialize SDL
    SDL_Init(SDL_INIT_EVERYTHING);

    //Set OpenGL memory usage
    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 of the window
    SDL_WM_SetCaption("Our first game", NULL);

    //Size of the window
    SDL_SetVideoMode(WIDTH, HEIGHT, 32, SDL_OPENGL);

    //Specific the clear color
    glClearColor(1, 1, 1, 1);// RED, GREEN, BLUE, ALPHA

    //What portion of the screen we will display
    glViewport(0, 0, WIDTH, HEIGHT);

    //Shader model - use this
    glShadeModel(GL_SMOOTH);

    //2D rendering
    glMatrixMode(GL_PROJECTION | GL_MODELVIEW);

    //"Save it"
    glLoadIdentity();

    // Disable depth test
    glDisable(GL_DEPTH_TEST);

    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

    //Handle the main loop
    bool isRunning = true;

    //For handling with event
    SDL_Event event;

    // Main game loop
    while(isRunning)
    {
        // events
        while( SDL_PollEvent(&event) )
        {
            if( event.type == SDL_QUIT )
            {
                isRunning = false;
            }
        }

        //RENDERING to the screen
        glClear(GL_COLOR_BUFFER_BIT);

        glPushMatrix();
            glOrtho(0, WIDTH, HEIGHT, 0, -1, 1);//Set the matrix
            glColor4ub(0, 0, 0, 255);     

            glLineWidth(10);

            // quad with lines
            glBegin(GL_LINES);
                glVertex2d(100, 100);
                glVertex2d(200, 100);

                glVertex2d(200, 100);
                glVertex2d(200, 200);

                glVertex2d(200, 200);
                glVertex2d(100, 200);

                glVertex2d(100, 200);
                glVertex2d(100, 100);           
            glEnd();   

            // triangle with lines
            glBegin(GL_LINES);
                glVertex2d(300, 300);
                glVertex2d(400, 400);

                glVertex2d(400, 400);
                glVertex2d(200, 400);

                glVertex2d(200, 400);
                glVertex2d(300, 300);         
            glEnd();

        glPopMatrix();

        SDL_GL_SwapBuffers();
    }

    SDL_Quit();

    return 0;
}.h>

key press in vector

31 December 2012 - 07:37 AM

Hello, im changing handling how keys are pressed, basicly im having number keys 1-9 and for each key same function is run.

				case SDLK_1:
					KeyPress(1);
					break;

				case SDLK_2:
					KeyPress(2);
					break;

 

it should look like this

std::vector < SDLKey > numberEnum_vec;
numberEnum_vec.push_back( SDLK_1 );
numberEnum_vec.push_back( SDLK_2 );

				for(int i=0; i<numberEnum_vec.size(); i++)
				{
					case numberEnum_vec[i+1]:

						break;
				}

Thanks for answer!


sdl distorted SDL_FillRect and images

26 November 2012 - 01:42 PM

Hello i have problem with distorted rectangle, this problem also happen with images.

Posted Image
Distorted rectangle looks like this.

Its happen only for moment every few seconds, it become obvious while moving ,any idea how to fix it?

c++, sdl - how to make installer? .exe

03 October 2012 - 11:11 AM

Hello i have make part of my game which i want show to other people. I would like to make installer to make game available on every computer with all files included. I am using c++, sdl, sdl_ttf and build game in visual studio 2010 with debug option.

Thanks fo help.

c++, sdl - game editor questions

09 June 2012 - 07:17 AM

Hello im making my first game editor and have some questions.
1 I have some const and functions like message which is simple cout, collision, openimage, xypos.. which should be accesable in every class and main, how?
2 I make twodimensional vector for storing grid, also im making option for increasing grid if needed. Increasing at botom and right was easy, however up is making problems (its changing camera going up). Im not sure if this code is ok, code should add add vector at first place at 0.

    if(map[0][0]){// insert UP                    
                    vector<int> tmpvec;
                    tmpvec.assign(map[0].size(), 0);
                    map.insert(map.begin(), tmpvec);    
                }

3 I have two class menu and map, menu have options like new game, save, load . Map class is saving, loading game. Where is better to put onclick logic?

Thanks for answers

PARTNERS