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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T20:58:24+00:00 2026-06-04T20:58:24+00:00

I’m using LWJGL with Clojure and am having difficulty lighting a scene. I am

  • 0

I’m using LWJGL with Clojure and am having difficulty lighting a scene. I am drawing GLU.Sphere objects which are visible when lighting is off but entirely black when lighting is enabled.

What am I doing wrong?

(ns gltest.core
  (:import [org.lwjgl.opengl Display DisplayMode GL11]
           [org.lwjgl.util.glu GLU Sphere]
           [org.lwjgl Sys]
           [org.lwjgl.input Keyboard]
           [java.nio ByteBuffer ByteOrder])
  (:gen-class))

(declare get-time)

(def temp-buf (ByteBuffer/allocateDirect 16))

(def s (Sphere.))

(def display-state (atom {:mode nil
                          :max-fps 60}))
(def render-state (atom {:last-frame nil
                         :last-fps (float 0)
                         :fps (float 0)}))
(def world-state (atom {:x 400
                        :y 300
                        :rotation 0}))

(defn get-time []
  (/ (* (Sys/getTime) 1000)
        (Sys/getTimerResolution)))

(defn update-fps []
  (let [time (get-time)]
    (when (> (- time (@render-state :last-fps))
             1000)
      (Display/setTitle (format "FPS: %s" (@render-state :fps)))
      (swap! render-state
             assoc :fps (float 0) :last-fps time)))
  (swap! render-state assoc :fps (float (+ (@render-state :fps)
                                           1))))

(defn update [delta]
  (swap! world-state assoc :rotation (+ (:rotation @world-state)
                                        (* (float 0.15) delta)))

  (update-fps))

(defn init-gl []
  (GL11/glClearColor 0.1 0.1 0.1 0.0) ; background
  (GL11/glClearDepth 1)
  (GL11/glDepthFunc GL11/GL_LEQUAL)
  (GL11/glHint GL11/GL_PERSPECTIVE_CORRECTION_HINT GL11/GL_NICEST)
  (GL11/glShadeModel GL11/GL_SMOOTH)
  (GL11/glEnable GL11/GL_DEPTH_TEST)

  ;; fovy, aspect ratio, zNear, zFar
  (let [width (.getWidth (:mode @display-state))
        height (.getHeight (:mode @display-state))
        aspect-ratio (float (/ width height))]
    ;; select projection matrix (controls perspective)
    (GL11/glMatrixMode GL11/GL_PROJECTION)
    (GL11/glLoadIdentity)
    (GLU/gluPerspective 45 aspect-ratio 0.1 100)

    (GL11/glMatrixMode GL11/GL_MODELVIEW)
    (GL11/glLoadIdentity)
    (GL11/glViewport 0 0 width height))

  (GL11/glMaterial GL11/GL_FRONT GL11/GL_SPECULAR (-> temp-buf
                                                      .clear
                                                      .asFloatBuffer
                                                      (.put (float-array [1 1 1 1]))
                                                      .flip))
  (GL11/glMaterial GL11/GL_FRONT GL11/GL_AMBIENT (-> temp-buf
                                                     .clear
                                                     .asFloatBuffer
                                                     (.put (float-array [1 1 1 1]))
                                                     .flip))
  (GL11/glMaterial GL11/GL_FRONT GL11/GL_DIFFUSE (-> temp-buf
                                                     .clear
                                                     .asFloatBuffer
                                                     (.put (float-array [1 1 1 1]))
                                                     .flip))

  (GL11/glMaterialf GL11/GL_FRONT_AND_BACK GL11/GL_SHININESS 10)

  ;; setup light
  (let [ambient-light (float-array [0.5 0.5 0.5 0])
        diffuse-light (float-array [0 1.0 0 0])]
    (GL11/glLight GL11/GL_LIGHT0 GL11/GL_AMBIENT (-> temp-buf
                                                     .clear
                                                     .asFloatBuffer
                                                     (.put ambient-light)
                                                     .flip))
    (GL11/glLight GL11/GL_LIGHT0 GL11/GL_DIFFUSE (-> temp-buf .clear
                                                     .asFloatBuffer
                                                     (.put diffuse-light)
                                                     .flip))
    (GL11/glLight GL11/GL_LIGHT0 GL11/GL_POSITION (-> temp-buf
                                                      .clear
                                                      .asFloatBuffer
                                                      (.put (float-array [0 -1 0 0]))
                                                      .flip)))

  (GL11/glEnable GL11/GL_LIGHTING)
  (GL11/glEnable GL11/GL_LIGHT0)

  (swap! render-state assoc :last-frame (get-time)))

(defn render []
  ;; Clear The Screen And The Depth Buffer
  (GL11/glClear (bit-or GL11/GL_COLOR_BUFFER_BIT GL11/GL_DEPTH_BUFFER_BIT))

  ;; setup camera
  (GL11/glLoadIdentity)
  (GL11/glTranslatef (float 0) (float 0) (float -3))
  (GL11/glRotatef 30 1 0 0)

  (GL11/glPushMatrix)
  (GL11/glTranslatef 0 1 0)
  (.draw s 0.1 50 50)
  (GL11/glPopMatrix))

(defn -main []
  (let [display-mode (first (filter #(and
                                      (== (.getWidth %) 800)
                                      (== (.getHeight %) 600)
                                      (== (.getBitsPerPixel %) 32))
                                    (Display/getAvailableDisplayModes)))]
    (swap! display-state assoc :mode display-mode)

    (Display/setDisplayMode display-mode)
    (Display/setTitle "Test")
    (Display/create))

  (init-gl)

  (while (not (Display/isCloseRequested))
    (let [time (get-time)
          last-frame (@render-state :last-frame)]
      (swap! render-state assoc :last-frame time)
      (update (int (- time last-frame))))
    (render)
    (Display/update)
    (Display/sync (@display-state :max-fps)))

  (Display/destroy)
  (System/exit 0))
  • 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-06-04T20:58:27+00:00Added an answer on June 4, 2026 at 8:58 pm

    In this case, setting the order of the ByteBuffer used in the glLight and glMaterial calls fixed the problem.

    // Java
    ByteBuffer buf = ByteBuffer.allocateDirect(16);
    buf.order(ByteOrder.nativeOrder);
    
    ;; Clojure
    (def buf (doto (ByteBuffer/allocateDirect 16)
               (.order (ByteOrder/nativeOrder)))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
We're building an app, our first using Rails 3, and we're having to build
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I am reading a book about Javascript and jQuery and using one of the
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and

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.