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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T19:28:37+00:00 2026-06-06T19:28:37+00:00

I made some code to produce boxes every time my code encounters a white

  • 0

I made some code to produce boxes every time my code encounters a white pixel in my level image. However, it doesn’t seem to work. It only works if I comment out the actual loading from image parts.

        GL11.glMatrixMode(GL11.GL_PROJECTION);
    GL11.glLoadIdentity();
    GL11.glOrtho(-5, 5, -5, 5, -20, 20);
    GL11.glMatrixMode(GL11.GL_MODELVIEW);
    float camPosX=0, camPosY=0;
    for(int i=0;i<level.getWidth();i++){
        for(int j=0;j<level.getHeight();j++){
            if(level.getRGB(i, j)==Color.red.getRGB()){camPosX=i;camPosY=j;}
        }
    }
    System.out.println("Camera position is "+camPosX+", "+camPosY);
    int x=0;
    while (!Display.isCloseRequested()) {
        Display.sync(60);
        //poll for keypresses first, default key is 'forward'
        if(Keyboard.isKeyDown(Keyboard.KEY_NUMPAD8));



        GL11.glClear(GL11.GL_DEPTH_BUFFER_BIT|GL11.GL_COLOR_BUFFER_BIT);
        //GL11.glEnable(GL11.GL_CULL_FACE);
        GL11.glEnable(GL11.GL_DEPTH_TEST);
        GL11.glColor3f(0, 0, 0);
        for(int i=0;i<level.getWidth();i++){
            for(int j=0;j<level.getHeight();j++){
                if(level.getRGB(i, j)==Color.WHITE.getRGB()){
                    GL11.glTranslatef(-i, 0, -j);
                    GL11.glRotatef(45, 1, 1, 1);
                    GL11.glBegin(GL11.GL_QUADS);
                    GL11.glColor3f(1.0f,0.0f,0.0f);          // Set The Color To Red
                    GL11.glVertex3f( 0.5f, 0.5f, 0.5f);          // Top Right Of The Quad (Front)
                    GL11.glVertex3f(-0.5f, 0.5f, 0.5f);          // Top Left Of The Quad (Front)
                    GL11.glVertex3f(-0.5f,-0.5f, 0.5f);          // Bottom Left Of The Quad (Front)
                    GL11.glVertex3f( 0.5f,-0.5f, 0.5f);          // Bottom Right Of The Quad (Front)
                    GL11.glVertex3f( 0.5f,-0.5f,-0.5f);          // Bottom Left Of The Quad (Back)
                    GL11.glVertex3f(-0.5f,-0.5f,-0.5f);          // Bottom Right Of The Quad (Back)
                    GL11.glVertex3f(-0.5f, 0.5f,-0.5f);          // Top Right Of The Quad (Back)
                    GL11.glVertex3f( 0.5f, 0.5f,-0.5f);          // Top Left Of The Quad (Back)
                    GL11.glVertex3f(-0.5f, 0.5f, 0.5f);          // Top Right Of The Quad (Left)
                    GL11.glVertex3f(-0.5f, 0.5f,-0.5f);          // Top Left Of The Quad (Left)
                    GL11.glVertex3f(-0.5f,-0.5f,-0.5f);          // Bottom Left Of The Quad (Left)
                    GL11.glVertex3f(-0.5f,-0.5f, 0.5f);          // Bottom Right Of The Quad (Left)
                    GL11.glVertex3f( 0.5f, 0.5f,-0.5f);          // Top Right Of The Quad (Right)
                    GL11.glVertex3f( 0.5f, 0.5f, 0.5f);          // Top Left Of The Quad (Right)
                    GL11.glVertex3f( 0.5f,-0.5f, 0.5f);          // Bottom Left Of The Quad (Right)
                    GL11.glVertex3f( 0.5f,-0.5f,-0.5f);          // Bottom Right Of The Quad (Right)
                    GL11.glEnd();
                    GL11.glLoadIdentity();
                }
            }
        }
        GL11.glTranslatef(-camPosX, 0, -camPosY);
        Display.update();
    }
  • 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-06T19:28:38+00:00Added an answer on June 6, 2026 at 7:28 pm

    In the main loop where you generate the boxes, you probably want to do

    ...
    if(level.GetRGB(i, j)==Color.WHITE.getRGB()) {
        GL11.glPushMatrix(); // store current matrix
        GL11.glTranslatef(-i, 0, -j);
        ...
        GL11.glPopMatrix(); // instead of GL11.glLoadIdentity()
    }
    

    The line

    GL11.glTranslatef(-camPosX, 0, -camPosY);
    

    probably does not what you think it does. It does not have any effect on the following call Display.update(). However, it will affect the next run of your main loop, because you do not call GL11.glLoadIdentity() at the beginning of the main loop. I suggest moving it to the beginning of the main loop and calling glLoadIdentity() before.

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

Sidebar

Related Questions

I've made some image validation. The user has to enter the code from the
I made some code, for understanding the concept/basic of pointer: int a=1; int *b=&a;
I've made some experimental code that I would like to save in the repository,
I have recently made changes in some code that makes a char name field
I've got some code which takes a drawing made on in SVG with Raphael
I've made some function that generates an email template. Code it generates is pure
Greetings, SO. I have some code which I've made attempts at compiling using gcc,
I am converting some code to LINQ, at the same time exploring to what
I made some little programs with Swing-components in JRuby. Now I want to convert
I made some modifications to SVG Edit which contains a make file. When I

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.