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 208811
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T17:51:33+00:00 2026-05-11T17:51:33+00:00

I’ve been trying to get input with IUP to make a small pong game.

  • 0

I’ve been trying to get input with IUP to make a small pong game. I wanted to try some input, and tried some of the code that comes with the IUPGL examples, but the input doesn’t seem to be working at all. Here’s the code as it stands so far:

require "iuplua"
require "iupluagl"
require "luagl"

paddle = {x = -0.9, y = 0.2}

function drawPaddle(x, y)
    gl.Begin(gl.QUADS)
    gl.Color(0.0, 0.5, 0.0)

    gl.Vertex(x, y)
    gl.Vertex(x + 0.1, y)
    gl.Vertex(x + 0.1, y - 0.4)
    gl.Vertex(x, y - 0.4)
end

canvas = iup.glcanvas{buffer = "DOUBLE", rastersize = "300x300"}

function canvas:action(x, y)
    iup.GLMakeCurrent(self)
    gl.ClearColor(0.0, 0.0, 0.0, 0.0)
    gl.Clear(gl.COLOR_BUFFER_BIT)
    gl.Clear(gl.DEPTH_BUFFER_BIT)

    gl.MatrixMode(gl.PROJECTION)
    gl.Viewport(0, 0, 300, 300)
    gl.LoadIdentity()

    drawPaddle(paddle.x, paddle.y)

    gl.End()
    iup.GLSwapBuffers(self)
end

window = iup.dialog{canvas, title = "Soon to be Pong"}

function canvas:k_any(c)
    if c == iup.K_q then
        return iup.CLOSE
    elseif c == iup.K_w then
        paddle.y = paddle.y + 0.02
        return iup.CONTINUE
    else
        return iup.DEFAULT
    end
end

window:show()

iup.MainLoop()

It’s my understanding that canvas:k_any() gets called when a key is pressed, but it’s not responding, even to the quit command. Any ideas?

  • 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-11T17:51:33+00:00Added an answer on May 11, 2026 at 5:51 pm

    Here is at least part of the problem for the sample you’ve quoted. Before the IUP keyname constants are actually defined in your iup table, you need to call a function. The idea is that the memory footprint is lower if you don’t need all of the key names, which many applications can do entirely without.

    Try adding the following lines sometime shortly after require "iuplua" and before you use the names in any code:

    iup.key_open()      -- load key names
    

    This is documented near the top of the topic Keyboard Codes as well as in a variety of places related to the keyboard.

    Without the call to iup.key_open(), iup.K_q evaluates to nil (as does any other key name) and thus silently never matches any keycode passed to canvas:k_any().

    Edit: I just ran your sample, and indeed calling iup.key_open() causes the q and w keys to be recognized. You have a further glitch you will notice next that just updating the paddle’s position doesn’t ask for the canvas to redraw. I’ll leave that as an exercise as you go forward.

    Edit2: Adding the line iup.Update(self) to the function canvas:k_any() just after you modify the state of the paddle appears to do what you want. Doing it that way rather than manually calling the action() method has the advantage of interacting with IUP’s message loop handling in the expected way. In the general case, calling iup.UpdateChildren(window) instead might be preferred. That would keep any other IUP controls that are displayed in the dialog updated as well as the canvas, which can be useful if you have controls that don’t do all their own updating internally.

    Alternatively, you could move the drawing routines into their own function called from both the k_any() and action() methods of the canvas. I’m not sure I’d recommend that in general as it doesn’t scale as well when you want to support multiple viewports or related controls.

    You might want to rearrange the logic in your k_any() handler so that you are less likely to accidentally forget the call to iup.Update() as you add cases for new keys.

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

Sidebar

Ask A Question

Stats

  • Questions 258k
  • Answers 258k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I just tried enabling the Client-only Framework subset option in… May 13, 2026 at 10:56 am
  • Editorial Team
    Editorial Team added an answer This would be my approach: Each DB would have a… May 13, 2026 at 10:56 am
  • Editorial Team
    Editorial Team added an answer I'm pretty sure I've heard that this is a compiler… May 13, 2026 at 10:56 am

Related Questions

I've got a string that has curly quotes in it. I'd like to replace
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I have a French site that I want to parse, but am running into
I have text I am displaying in SIlverlight that is coming from a CMS

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.