3D models blink

Hey so I have a 3D model which I have loaded into my game. However every frame they dissappear and reappear how can I fix this?

CODE:

ofapp.h

#pragma once

#include “ofMain.h”
#include “ofxAssimpModelLoader.h”
#include “meteor.h”

class ofApp : public ofBaseApp{

public:
void setup();
void update();
void draw();

  void keyPressed(int key);
  void keyReleased(int key);
  void mouseMoved(int x, int y );
  void mouseDragged(int x, int y, int button);
  void mousePressed(int x, int y, int button);
  void mouseReleased(int x, int y, int button);
  void mouseEntered(int x, int y);
  void mouseExited(int x, int y);
  void windowResized(int w, int h);
  void dragEvent(ofDragInfo dragInfo);
  void gotMessage(ofMessage msg);
  ofEasyCam cam;
  //ofxAssimpModelLoader Model1;
  std::vector<meteor> Comets;//comets  

};

ofapp.cpp

#include “ofApp.h”

//--------------------------------------------------------------
void ofApp::setup(){
ofSetFrameRate(30);
ofSetVerticalSync(true);
ofEnableDepthTest();

cam.setDistance(120);

//Model1.loadModel(“Models/asteroid.3ds”, 20);

//Model1.setRotation(0, 90, 1, 0, 0);
//Model1.setRotation(1, 270, 0, 0, 1);
//Model1.setScale(0.1, 0.1, 0.1);
// Model1.setPosition(100, 100, 0);

for (int j = 0; j<Comets.size(); j++)
{
Comets[j].setup(0, 0, 0, 0, 0 ,0, 0);
}

for (int i = 0; i < 10; i++) {
meteor tempEnemy;
tempEnemy.setup(ofRandom(0, 1024), ofRandom(0, 1024), 0, 1, 0, 0, 0);
Comets.push_back(meteor(tempEnemy));
}

}

//--------------------------------------------------------------
void ofApp::update(){

}

//--------------------------------------------------------------
void ofApp::draw(){
ofBackground(255, 0, 0);

cam.begin();

cam.end();

for (int j = 0; j < Comets.size(); j++)
{
Comets[j].draw();
}

}

//--------------------------------------------------------------
void ofApp::keyPressed(int key){

}

//--------------------------------------------------------------
void ofApp::keyReleased(int key){

}

//--------------------------------------------------------------
void ofApp::mouseMoved(int x, int y ){

}

//--------------------------------------------------------------
void ofApp::mouseDragged(int x, int y, int button){

}

//--------------------------------------------------------------
void ofApp::mousePressed(int x, int y, int button){

}

//--------------------------------------------------------------
void ofApp::mouseReleased(int x, int y, int button){

}

//--------------------------------------------------------------
void ofApp::mouseEntered(int x, int y){

}

//--------------------------------------------------------------
void ofApp::mouseExited(int x, int y){

}

//--------------------------------------------------------------
void ofApp::windowResized(int w, int h){

}

//--------------------------------------------------------------
void ofApp::gotMessage(ofMessage msg){

}

//--------------------------------------------------------------
void ofApp::dragEvent(ofDragInfo dragInfo){

}

meteor.h

#pragma once
#include “ofxAssimpModelLoader.h”

class meteor
{
public:
meteor();

void setup(int _x, int _y, int _z, int _sx, int _sy, int _sz, int _model);
void draw();
int x;
int y;
int z;
int speedX;
int speedY;
int speedZ;
int model;
ofxAssimpModelLoader Model1;
};

meteor.cpp

#include “meteor.h”

meteor::meteor()
{
}

void meteor::setup(int _x, int _y, int _z, int _sx, int _sy, int _sz, int _model) {
x = _x; // assignes x the value of _x which is assigned in setup
y = _y; // assignes y the value of _y which is assigned in setup
z = _z;
speedX = _sx; // assignes speedX the value of _sx which is assigned in setup
speedY = _sy; // assignes speedY the value of _sy which is assigned in setup
model = _model; //Assignes sprite the value of _sprite which is assigned in setup

  			//Loads in the asteroid model 

Model1.loadModel(“Models/asteroid.3ds”, 0);
Model1.setScale(0.1, 0.1, 0.1);

}

void meteor::draw() {
Model1.setPosition(x, y, z);
Model1.drawFaces();

x = x + speedX;
y = y + speedY;
z = z + speedZ;
}

Hi,
in ofApp::setup()
you have

for (int i = 0; i < 10; i++) {
	meteor tempEnemy;
	tempEnemy.setup(ofRandom(0, 1024), ofRandom(0, 1024), 0, 1, 0, 0, 0);
	Comets.push_back(meteor(tempEnemy));
}

there you are using the default copy constructor, because you don have it defined in the meteor class, which could bring problems with the model loader.
So the correct way should be

for (int i = 0; i < 10; i++) {
	Comets.push_back(meteor());
	Comets.back().setup(ofRandom(0, 1024), ofRandom(0, 1024), 0, 1, 0, 0, 0);
}

besides this I don’t see anything strange.
Hope it helps.
best

Ok I switched it to that code and they still blink. What else could it be?

I commented our the changing of x,y and z and they no longer flicker. How would I be able to move the models without them flickering?

Hi, I think that you need to call update() aftrer setting the position.
like

void meteor::draw() {
Model1.setPosition(x, y, z);
Model1.update();
Model1.drawFaces();

x = x + speedX;
y = y + speedY; 
z = z + speedZ;
}

hope it helps

Hasn’t helped. Is there something I need to do to enable 3D that I havn’t done such as designate GPU to the program.

mm, weird. No you dont need to.
instead of modifying the Model1 object’s position try using ofTranslate, because the

void meteor::draw() {
ofPushMatrix();
ofTranslate(x, y,z);

Model1.drawFaces();
ofPopMatrix();
x = x + speedX;
y = y + speedY; 
z = z + speedZ;
}

if it doesn’t work, can you share the code and assets to test?
are you checking the fps while drawing. Maybe your computer is not capable to make all the math in time for each frame.