size()
EnvironmentDescription
Defines the dimension of the display window. Call in setup(). Optionally pass P2D or P3D as renderer.
Syntax
void size(int w, int h)
void size(int w, int h, int renderer)
Parameters
| Name | Type | Description |
|---|---|---|
| w | int | width of the window in pixels |
| h | int | height of the window in pixels |
| renderer | int | P2D or P3D (optional) |
Returns
voidRelated
Under the Hood
From Processing.h:
template<typename T> inline void printArray(const std::vector<T>& a) {
for (size_t i=0; i<a.size();
for (size_t i=0; i<v.size();
int size() const { if(isArray())return (int)arr->size(); if(isObject())return (int)obj->size(); return 0; }
XML* getChild(int i) { return i<(int)children.size()?&children[i]:nullptr;
int getChildCount() const { return (int)children.size();
int getColumnCount() const { return (int)columns.size();
int getRowCount() const { return (int)rows.size();
std::string getColumnTitle(int i) const { return i<(int)columns.size()?columns[i]:"";
for (int i=0;i<(int)columns.size();
std::string getString(int row, int col) const { return row<(int)rows.size()&&col<(int)rows[row].size()?rows[row][col]:"";
for (int i=0;i<(int)rows.size();
int length() const { return (int)size();
for (size_t i = 0; i < size();
return size() >= prefix.size() && compare(0, prefix.size(), prefix) == 0;
return size() >= suffix.size() && compare(size() - suffix.size(), suffix.size(), suffix) == 0;
return (int)size() - (int)other.size();
int size() const { return (int)data.size(); }
int size() const { return (int)data.size();
for (int i = 0; i < (int)data.size();
for (size_t i = 1; i < data.size();
int size() const { return (int)data.size(); }
int size() const { return (int)data.size();
int size() const { return (int)data.size(); }
int size() const { return (int)data.size();
int size() const{ return (int)data.size(); }
int size() const{ return (int)data.size();
int size() const{ return (int)data.size(); }
int size() const{ return (int)data.size();
int size() const { return (int)_data.size(); }
int size() const { return (int)_data.size();
int size() const { return (int)data.size(); }
int size() const { return (int)data.size();
int size() const { return (int)data.size(); }
int size() const { return (int)data.size();
int size() const { return (int)data.size(); }
int size() const { return (int)data.size();
PShape* getChild(int i) { return i<(int)children.size()?&children[i]:nullptr;
int getChildCount() const { return (int)children.size();
int getVertexCount() const { return (int)verts.size();
float size = 12;
PFont(const std::string& n, float s) : name(n), size(s), loaded(true) {}
int size() const { return (int)data.size(); }
int size() const { return (int)data.size();
void size(int w, int h);
void size(int w, int h, int renderer);
template<typename A,typename B,typename=std::enable_if_t<std::is_arithmetic_v<A>&&std::is_arithmetic_v<B>>>
void size(A w,B h){ size((int)w,(int)h);
template<typename A,typename B,typename=std::enable_if_t<std::is_arithmetic_v<A>&&std::is_arithmetic_v<B>>>
void size(A w,B h,int renderer){ size((int)w,(int)h,renderer);
Under the Hood
From Processing.cpp:
void PApplet::size(int w,int h){
winWidth=w;winHeight=h;
logicalW=w;logicalH=h; // remember what the sketch requested
pixelWidth=w;pixelHeight=h;
if(gWindow){
glfwSetWindowSize(gWindow,w,h);
// Poll until the framebuffer is actually the requested size.
// glfwSetWindowSize is async; without this the window stays 100x100
// when setup() calls background() or draws anything.
// Poll until the window is actually resized (or timeout after 500ms)
for(int _wait=0; _wait<500; _wait++){
glfwPollEvents();
int fw=0,fh=0;
glfwGetFramebufferSize(gWindow,&fw,&fh);
// Accept exact match or close match (HiDPI scaling)
if(fw>0 && fh>0){
pixelWidth=fw; pixelHeight=fh;
// Check if the logical window size matches what we requested
int lw=0,lh=0;
glfwGetWindowSize(gWindow,&lw,&lh);
if(lw==w && lh==h) break; // exact match
}
if(_wait>=50){ // after 50ms, accept whatever we have
int fw2=0,fh2=0;
glfwGetFramebufferSize(gWindow,&fw2,&fh2);
if(fw2>0&&fh2>0){ pixelWidth=fw2; pixelHeight=fh2; }
break;
}
#ifdef _WIN32
Sleep(1);
#else
usleep(1000);
#endif
}
// Force coordinate system to requested size regardless of WM.
// logicalW/H are the sketch's coordinate space; viewport uses actual size.
logicalW = w; logicalH = h;
winWidth = w; winHeight = h;
setProjection(w,h);
}
}
void PApplet::size(int w,int h,int renderer){
defaultP3D=(renderer==P3D);
size(w,h);
// For P3D mode: set up depth test and apply default camera/perspective
// immediately so setup() draws with the correct projection.
if(defaultP3D && gWindow){
{int fw=logicalW,fh=logicalH;if(gWindow)glfwGetFramebufferSize(gWindow,&fw,&fh);if(fw>0)fbW=fw;if(fh>0)fbH=fh;}
glViewport(0,0,fbW,fbH);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LESS);
glDisable(GL_CULL_FACE);
glFrontFace(GL_CW);
glEnable(GL_NORMALIZE);
glClearColor(0.8f,0.8f,0.8f,1); // Java Processing default grey (204,204,204)
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
applyDefaultCamera();
}
}
size(w,h);
void PApplet::windowResize(int w,int h){size(w,h);
return s.size() * (BF_GW+1) * scale;
for (int li = 0; li < (int)ls.size();
for(int i=start;i<(int)lines.size();
for(int j=0;j<(int)cells.size()&&j<(int)row.size();
for(auto& row:t.rows){for(size_t i=0;i<row.size();
for(size_t ci2=0;ci2<tag.size();
return path.size()>=e.size()&&path.substr(path.size()-e.size())==e;
currentFont.size = size;
std::string r; for (size_t i=0;i<v.size();