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

The Archive Base Latest Questions

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

So a subset of my code (within a rendering loop of course) is: for(int

  • 0

So a subset of my code (within a rendering loop of course) is:

    for(int x=0;x<data.length;x++) 
        for(int y=0;y<data[0].length;y++) {

            float r = colorData[x][y][0], g = colorData[x][y][1], b = colorData[x][y][2];
            glGetError();
            glColor3f(r,g,b);
            int xCoord = x*100;
            int yCoord = y*100;
            int height = (int) Math.round(data[y][x]*25);

            glBegin(GL_QUADS);


                //Top
                glVertex3f(xCoord,yCoord,height);
                glVertex3f(xCoord+100,yCoord,height);
                glVertex3f(xCoord+100,yCoord+100,height);
                glVertex3f(xCoord,yCoord+100,height);
                //*/

                //Sides
                glColor3f(r/2,g/2,b/2);          
                glVertex3f(xCoord,yCoord,height);
                glVertex3f(xCoord,yCoord,0);
                glVertex3f(xCoord+100,yCoord,0);
                glVertex3f(xCoord+100,yCoord,height);

                glVertex3f(xCoord,yCoord+100,height);
                glVertex3f(xCoord+100,yCoord+100,height);
                glVertex3f(xCoord+100,yCoord+100,0);
                glVertex3f(xCoord,yCoord+100,0);

                glVertex3f(xCoord,yCoord+100,height);
                glVertex3f(xCoord,yCoord+100,0);
                glVertex3f(xCoord,yCoord,0);
                glVertex3f(xCoord,yCoord,height);

                glVertex3f(xCoord+100,yCoord+100,height);
                glVertex3f(xCoord+100,yCoord,height);
                glVertex3f(xCoord+100,yCoord,0);
                glVertex3f(xCoord+100,yCoord+100,0);

                //Bottom
                glColor3f(r/4,g/4,b/4);
                glVertex3f(xCoord,yCoord,0);
                glVertex3f(xCoord,yCoord+100,0);
                glVertex3f(xCoord+100,yCoord+100,0);
                glVertex3f(xCoord+100,yCoord,0);



            glEnd();
            int err =  glGetError();
            if(err != GL_NO_ERROR)
                 System.out.println("An error has occured: #"+err);
            glColor3f(1,0,0);
            glBegin(GL_LINES);
                //Top
                glVertex3f(xCoord,yCoord,height);
                glVertex3f(xCoord+100,yCoord,height);
                glVertex3f(xCoord+100,yCoord+100,height);
                glVertex3f(xCoord,yCoord+100,height);
            glEnd();                
        }

The code works correctly, drawing a two dimensional grid of boxes, with the sides of the box being slightly darker than the top. (Poor man’s lighting)

Just for curiosity I took out the first call to glColor3f, expecting the top of the box to become colorless, and the sides to remain the same; however the entire grid of boxes goes white. Why is this? Is it something in this code here? Or is some other part of my render loop causing this?

(If it makes a difference, I’m using LWJGL’s Java implementation of OpenGL1.1)

  • 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:30:37+00:00Added an answer on June 4, 2026 at 8:30 pm

    OpenGL immediate mode works a bit like this (pseudocode)

    glColor3f(r,g,b){
    state.color.{r,g,b} = r,g,b;
    }
    
    glNormal(x,y,z){
    state.normal.{x,y,z} = x,y,z;
    }
    
    /* and so on */
    
    glVertex3f(x,y,z){
        send_vertex_to_rasterizer(state.color, state.normal, ..., {x,y,z})
    }
    

    I.e. OpenGL remembers the last color you’ve set and will it apply to all following vertices until you change it to another color, which then will apply.

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

Sidebar

Related Questions

I'm interested in T-SQL source code for synchronizing a table (or perhaps a subset
In the source code below, I am selecting a subset of properties from the
I'm copying a subset of some data, so that the copy will be independently
I am trying to work out how to parallelize some code from data mining
For testing code I'm copying data from a live database to a test database
I have the following code snippet, which loads data from a CSV file into
Possible Duplicates: Is this a legitimate C++ code? “C subset of C++” -> Where
The regular code snippet of syncing data with sync framework is this: LocalDBSyncAgent syncAgent
The code: #include stdafx.h #include stdio.h #include math.h #include stdlib.h #include time.h int main()
I am trying to extract a subset from a huge dataset. The following code

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.