Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6650497
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:54:00+00:00 2026-05-26T00:54:00+00:00

I seem to be having the same trouble over and over again and cannot

  • 0

I seem to be having the same trouble over and over again and cannot get my thick head around it. This program will not display a paddle as I want (and expected it) to do on screen 🙁 –

#include <SDL/SDL.h>
#include <SDL/SDL_opengl.h>

SDL_Event event;

const int paddle_width = 20;
const int paddle_height = 80;

class PlayerPaddle

{

private:

int xloc;
int yloc;
int yvel;

public:

PlayerPaddle()

{

    int xloc = 20;
    int yloc = 200;
    int yvel = 0;

}

void ShowPaddle()

{

    glTranslatef(xloc,yloc,0);

    glBegin(GL_QUADS);

        glColor4f(1.0,1.0,1.0,1.0);

        glVertex3f(0,0,0);
        glVertex3f(20,0,0);
        glVertex3f(20,80,0);
        glVertex3f(0,80,0);

    glEnd();

    glLoadIdentity();

}

void MovePaddle()

{

    yloc += yvel;

}

void Handle_Input()

{

    if( event.type == SDL_KEYDOWN )

        {

            switch( event.key.keysym.sym )

                {
                    case SDLK_UP: yvel -= paddle_height / 2; break;
                    case SDLK_DOWN: yvel += paddle_height / 2; break;
                }

        }

    else if( event.type == SDL_KEYUP )

        {

            switch( event.key.keysym.sym )

                {
                    case SDLK_UP: yvel += paddle_height / 2; break;
                    case SDLK_DOWN: yvel -= paddle_height / 2; break;
                }

        }

}

};

void init ()

{

SDL_Init(SDL_INIT_EVERYTHING);
SDL_SetVideoMode(640,480,32,SDL_OPENGL);
SDL_WM_SetCaption( "Pong", NULL );

glClearColor( 0, 0, 0, 0 );
glViewport(0, 0, 640, 480);
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
glOrtho( 0, 640 , 480 , 0, 0, 1 );
glMatrixMode( GL_MODELVIEW );
glClear(GL_COLOR_BUFFER_BIT);
glLoadIdentity();

}

int main (int argc, char **argv)

{

init();

PlayerPaddle ppaddle;

bool quit = false;

while (quit == false)

{

    while (SDL_PollEvent (&event))

    {

        ppaddle.Handle_Input();

        if (event.type == SDL_QUIT)
        quit = true;

    }

    ppaddle.MovePaddle();

    glClear(GL_COLOR_BUFFER_BIT);

    ppaddle.ShowPaddle();

    SDL_GL_SwapBuffers();

}

SDL_Quit();
return 0;

}

I just get a clear black screen until I quit the program which returns 0 as expected. I know the code:

    ppaddle.MovePaddle();

    glClear(GL_COLOR_BUFFER_BIT);

    ppaddle.ShowPaddle();

    SDL_GL_SwapBuffers();

iterates at least once as if I inserted a return 1; statement in there the program would start up and return 1 immediately.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T00:54:00+00:00Added an answer on May 26, 2026 at 12:54 am

    At a minimum you screwed up your constructor. Again.

    It should probably be this:

    PlayerPaddle()
    {
        xloc = 20;
        yloc = 200;
        yvel = 0;
    }
    

    You may also want to toss in a SDL_Delay(100) at the end of your main loop to slow things down until you get some more sophisticated physics handling going.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This may be something common and trivial, but I seem to be having trouble
I am having trouble with my code. I cannot seem to understand how to
I'm having trouble with MySQL or Python and can't seem to isolate the problem.
I've been having trouble trying to get PIL to nicely downsample images. The goal,
I'm having a bit of trouble trying to get class variables to work in
My program generates relatively simple PDF documents on request, but I'm having trouble with
I am having trouble getting my class to from program.cs to run in form.cs
I am having trouble clicking or interacting with some page elements. They seem like
I am having a bit of trouble getting this c# code to work I
I seem to be having trouble with setting the correct height and width of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.