• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to turn on a light through an actionPerformed with opengl Java

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm writing a java program with opengl and I'm trying to get it where the user would select something like lighting on in a JMenu and then it would turn the lighting on in the house/barn... I have a method called LightOn that I put gl.glEnable(gl.GL_LIGHT0); but it just doesn't seem to turn on when I call it from the action performed... Is there something I'm missing from my code that I'm supposed to use instead since I have tried it with a boolean.. So the boolean starts off as false and when the JMenuItem is clicked the actionPerformed will turn the boolean to true and call the method LightOn. In the display method I have what the light is supposed to be

Snippet of code in display method for lighting:



 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You have two separate variables both named light.
 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Remove the word "boolean" on line 6 of your second code block. You're redefining "light" rather than referencing the value you defined earlier. Also, just a friendly suggestion, if the intent is to not leave the light on indefinitely once it's been turned on, modify your logic so that if your action command is not "light on", set light=false.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic