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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T00:34:11+00:00 2026-06-06T00:34:11+00:00

I’ve came upon a problem regarding 2D textures placed on 2D quads. I have

  • 0

I’ve came upon a problem regarding 2D textures placed on 2D quads. I have a space arcade game and it has asteroids,planets and a ship (with textures) that load perfectly fine.

I’m now working on power ups but for some weird reason it only shows one of the 3 different textures I designated on each power up and shows up a big version of the texture at the upper left cornor from time to time which doesn ‘t do anything (no collision function).

I’m loading the texture into the variables before entering the game loop and checked if it is actually loaded and the int values held values so that is fine. When an asteroid is destroyed a PowerUp Object is instantiated and the GLuint texture property is filled with the int value from the texture previously loaded.

I’ll post some code fragments to display some error I might be making:

//Initialisation of Vectors that hold all PowerUps dropped in game
vector<PowerUp_Speed> powerUps;
vector<PowerUp_Gun> powerUps_Gun;
vector<PowerUp_FireRate> powerUps_FireRate;

//PowerUps Texture Loading  (Before the main loop and after SDL init)
int speedTexture = loadTexture("sprites/Speed.png");
int rateTexture = loadTexture("sprites/Rate.png");
int gunTexture = loadTexture("sprites/Gun.png");

Following section is IN the main loop (when bullet vs asteroid collision occurs)

//PowerUps
PowerUp_Speed boost;
boost.texture = speedTexture;
bool push = boost.Drop(powerUps, destr[d]);
if(push)    powerUps.push_back(boost);

PowerUp_Gun gunBoost;
gunBoost.texture = rateTexture;
push = gunBoost.Drop(powerUps_Gun, destr[d]);
if(push)    powerUps_Gun.push_back(gunBoost);

PowerUp_FireRate fireBoost;
fireBoost.texture = gunTexture;
push = fireBoost.Drop(powerUps_FireRate, destr[d]);
if(push)    powerUps_FireRate.push_back(fireBoost);

And one of the PowerUp Objects to display how these function:

#include "SpaceGame.h"

PowerUp_Speed::PowerUp_Speed()
{
    isAlive = true;
    width = 40;
    height = width;
    chance = 5;
}

void PowerUp_Speed::boostPlayer(Ship &ship)
{
    ship.vel += 0.1f;
}

void PowerUp_Speed::Draw()
{
    if(isAlive)
    {
        glPushMatrix();
        glColor4ub(255, 255, 255, 255);
        glEnable(GL_TEXTURE_2D);
        glBindTexture(GL_TEXTURE_2D, texture);
        glBegin(GL_QUADS);
            glTexCoord2d(0,0); glVertex2f(x, y);
            glTexCoord2d(1,0); glVertex2f(x + width, y);
            glTexCoord2d(1,1); glVertex2f(x + width, y + height);
            glTexCoord2d(0,1); glVertex2f(x, y + height);
        glDisable(GL_TEXTURE_2D);
        glPopMatrix();
    }
}

bool PowerUp_Speed::Drop(vector<PowerUp_Speed> &powerUps, Destructable d)
{
    if(rand() % chance == 1)
    {
        if(powerUps.size() == 0)
        {
            x = d.x;
            y = d.y;
            return true;
        }
        else
        {
            bool succes = false;

            for(unsigned int i = 0; i < powerUps.size(); i++)
            {
                if(!powerUps[i].isAlive)
                {
                    powerUps[i].isAlive = true;
                    powerUps[i].x = d.x;
                    powerUps[i].x = d.y;
                    powerUps[i].texture = texture;
                    succes = true;
                    return false;
                }
            }

            if(!succes)
            {
                x = d.x;
                y = d.y;
                return true;
            }
        }
    }
    return false;
}

and its decleration in a header file:

class PowerUp_Speed
{
    public:
        float x, y;
        int width, height;
        int chance;
        bool isAlive;
        GLuint texture;
        PowerUp_Speed();
        void Draw();
        void boostPlayer(Ship &ship);
        bool Drop(vector<PowerUp_Speed> &powerUps, Destructable d);
};
  • 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-06T00:34:13+00:00Added an answer on June 6, 2026 at 12:34 am

    Add a glEnd() to PowerUp_Speed::Draw():

    glBegin(GL_QUADS);
        glTexCoord2d(0,0); glVertex2f(x, y);
        glTexCoord2d(1,0); glVertex2f(x + width, y);
        glTexCoord2d(1,1); glVertex2f(x + width, y + height);
        glTexCoord2d(0,1); glVertex2f(x, y + height);
    glEnd();
    

    Every glBegin() needs a corresponding glEnd().

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I have a jquery bug and I've been looking for hours now, I can't
Basically, what I'm trying to create is a page of div tags, each has
this is what i have right now Drawing an RSS feed into the php,

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.