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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T09:46:22+00:00 2026-05-20T09:46:22+00:00

Ok, this is what I have. I have a 1d bitmap (or bitarray, bitset,

  • 0

Ok, this is what I have. I have a 1d bitmap (or bitarray, bitset, bitstring, but I’ll call it a bitmap for now) containing the live or dead states from a conway game of life generation. The cell at (x, y) is represented by the bit at y * map_width + x.

Now I have my game of life “engine” working, it would be nice if I could render some graphical stuff now. I thought OpenGL would be a nice choice for this, but I have no idea how I should start and if there are any specific functions or shaders (I know nothing about shaders) that can efficiently render a bitmap into a 2d plane with black ‘n white pixels.

If you now think “no you idiot opengl is bad go with …”, feel free to say it, I’m open for changes.

EDIT

I forgot to say that I use a compact bitarray storing 8 bits per byte and using masking to retrieve those bytes. This is my hand made library thingy:

#include <stdint.h> // uint32_t
#include <stdlib.h> // malloc()
#include <string.h> // memset()
#include <limits.h> // CHAR_BIT

typedef uint32_t word_t;
enum {
    WORD_SIZE = sizeof(word_t), // size of one word in bytes
    BITS_PER_WORD = sizeof(word_t) * CHAR_BIT, // size of one word in bits
    MAX_WORD_VALUE = UINT32_MAX // max value of one word
};

typedef struct {
    word_t *words;
    int nwords;
    int nbytes;
} bitmap_t;

inline int WORD_OFFSET(int b) { return b / BITS_PER_WORD; }
inline int BIT_OFFSET(int b) { return b % BITS_PER_WORD; }

inline void setbit(bitmap_t bitmap, int n) { bitmap.words[WORD_OFFSET(n)] |= (1 << BIT_OFFSET(n)); }
inline void flipbit(bitmap_t bitmap, int n) { bitmap.words[WORD_OFFSET(n)] ^= (1 << BIT_OFFSET(n)); }
inline void clearbit(bitmap_t bitmap, int n) { bitmap.words[WORD_OFFSET(n)] &= ~(1 << BIT_OFFSET(n)); }
inline int getbit(bitmap_t bitmap, int n) { return (bitmap.words[WORD_OFFSET(n)] & (1 << BIT_OFFSET(n))) != 0; }

inline void clearall(bitmap_t bitmap) {
    int i;
    for (i = bitmap.nwords - 1; i >= 0; i--) {
        bitmap.words[i] = 0;
    }
}

inline void setall(bitmap_t bitmap) {
    int i;
    for (i = bitmap.nwords - 1; i >= 0; i--) {
        bitmap.words[i] = MAX_WORD_VALUE;
    }
}

bitmap_t bitmap_create(int nbits) {
    bitmap_t bitmap;
    bitmap.nwords = nbits / BITS_PER_WORD + 1;
    bitmap.nbytes = bitmap.nwords * WORD_SIZE;
    bitmap.words = malloc(bitmap.nbytes);

    if (bitmap.words == NULL) { // could not allocate memory
        printf("ERROR: Could not allocate (enough) memory.");
        exit(1);
    }

    clearall(bitmap);
    return bitmap;
}

void bitmap_free(bitmap_t bitmap) {
    free(bitmap.words);
}
  • 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-20T09:46:23+00:00Added an answer on May 20, 2026 at 9:46 am

    This is code from my OGL Game of Life implementation.

    This uploads the texture (do this every time you want to update the data):

    glTexImage2D( GL_TEXTURE_2D, 0, 1, game->width, game->height, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, game->culture[game->phase] );
    

    game->culture[phase] is the data array of type char* of size width * height (phase toggles between two alternating arrays that are being written into resp. read from).

    Because GL_LUMINANCE is used, the colors will be only black and white.

    Also, you need to set up the rectagle with this (every frame, but I guess you already know this)

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    
    
        glBegin(GL_QUADS);                                  // Draw A Quad
            glVertex3f(-1.0f, 1.0f, 0.0f);                  // Top Left
            glTexCoord2i( 1, 0 );
            glVertex3f( 1.0f, 1.0f, 0.0f);                  // Top Right
            glTexCoord2i( 1, 1 );
            glVertex3f( 1.0f,-1.0f, 0.0f);                  // Bottom Right
            glTexCoord2i( 0, 1 );
            glVertex3f(-1.0f,-1.0f, 0.0f);                  // Bottom Left
            glTexCoord2i( 0, 0 );
        glEnd();
    

    Of course you could use buffers and keep the “model” in the GPU memory, but that is not really necessary with only one quad.

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

Sidebar

Related Questions

i have this code Bitmap bmp1, bmp2, bmp3,bmp4; Graphics gp2,gp3; if (bmp2 == null)
We have Bitmap and Bitmapdata objects now. And when using the webcam, we can
This question may have been asked before, but I'm starting to get into game
Part 1) I have a bitmap/jpeg image. I need to convert this image into
I have a bitmap that I want to display in my Android app. This
In my project I have an bitmap image. I need to convert this picture
Has anyone done this / have some example code?
Running ipconfig /all shows a Teredo Tunneling Pseudo-Interface. What is that? Does this have
I have this code in jQuery, that I want to reimplement with the prototype
I have this idea for a free backup application. The largest problem I need

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.